update-python-resources: skip dependencies of excluded packages

This commit is contained in:
fn ⌃ ⌥ 2021-11-14 03:26:40 -08:00
parent 1f0ab4a1ee
commit e6e730f49d

View File

@ -94,11 +94,17 @@ module PyPI
@name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero? @name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero?
end end
# Compare only names so we can use .include? on a Package array # Compare only names so we can use .include? and .uniq on a Package array
sig { params(other: Package).returns(T::Boolean) } sig { params(other: Package).returns(T::Boolean) }
def ==(other) def ==(other)
same_package?(other) same_package?(other)
end end
alias eql? ==
sig { returns(Integer) }
def hash
@name.tr("_", "-").downcase.hash
end
sig { params(other: Package).returns(T.nilable(Integer)) } sig { params(other: Package).returns(T.nilable(Integer)) }
def <=>(other) def <=>(other)
@ -212,7 +218,8 @@ module PyPI
odie '"pipgrip" must be installed (`brew install pipgrip`)' unless @pipgrip_installed odie '"pipgrip" must be installed (`brew install pipgrip`)' unless @pipgrip_installed
ohai "Retrieving PyPI dependencies for \"#{input_packages.join(" ")}\"..." if !print_only && !silent ohai "Retrieving PyPI dependencies for \"#{input_packages.join(" ")}\"..." if !print_only && !silent
command = [Formula["pipgrip"].opt_bin/"pipgrip", "--json", "--no-cache-dir", *input_packages.map(&:to_s)] command =
[Formula["pipgrip"].opt_bin/"pipgrip", "--json", "--tree", "--no-cache-dir", *input_packages.map(&:to_s)]
pipgrip_output = Utils.popen_read(*command) pipgrip_output = Utils.popen_read(*command)
unless $CHILD_STATUS.success? unless $CHILD_STATUS.success?
odie <<~EOS odie <<~EOS
@ -222,9 +229,7 @@ module PyPI
EOS EOS
end end
found_packages = JSON.parse(pipgrip_output).to_h.map do |new_name, new_version| found_packages = json_to_packages(JSON.parse(pipgrip_output), main_package, exclude_packages).uniq
Package.new("#{new_name}==#{new_version}")
end
new_resource_blocks = "" new_resource_blocks = ""
found_packages.sort.each do |package| found_packages.sort.each do |package|
@ -281,4 +286,17 @@ module PyPI
true true
end end
def json_to_packages(json_tree, main_package, exclude_packages)
return [] if json_tree.nil?
json_tree.flat_map do |package_json|
package = Package.new("#{package_json["name"]}==#{package_json["version"]}")
[package] + if package == main_package || exclude_packages.exclude?(package)
json_to_packages(package_json["dependencies"], main_package, exclude_packages)
else
[]
end
end
end
end end