migrate automatic python resource list to Homebrew/core
This commit is contained in:
parent
63dead36cc
commit
8e670995f8
@ -26,6 +26,14 @@ module Homebrew
|
|||||||
flag "--version=",
|
flag "--version=",
|
||||||
description: "Use the specified <version> when finding resources for <formula>. "\
|
description: "Use the specified <version> when finding resources for <formula>. "\
|
||||||
"If no version is specified, the current version for <formula> will be used."
|
"If no version is specified, the current version for <formula> will be used."
|
||||||
|
flag "--package-name=",
|
||||||
|
depends_on: "--version",
|
||||||
|
description: "Use the specified <package-name> when finding resources for <formula>. "\
|
||||||
|
"If no package name is specified, it will be inferred from the formula's stable URL."
|
||||||
|
comma_array "--extra-packages=",
|
||||||
|
description: "Include these additional packages when finding resources."
|
||||||
|
comma_array "--exclude-packages=",
|
||||||
|
description: "Exclude these packages when finding resources."
|
||||||
|
|
||||||
min_named :formula
|
min_named :formula
|
||||||
end
|
end
|
||||||
@ -35,7 +43,13 @@ module Homebrew
|
|||||||
args = update_python_resources_args.parse
|
args = update_python_resources_args.parse
|
||||||
|
|
||||||
args.named.to_formulae.each do |formula|
|
args.named.to_formulae.each do |formula|
|
||||||
PyPI.update_python_resources! formula, args.version, print_only: args.print_only?, silent: args.silent?,
|
PyPI.update_python_resources! formula,
|
||||||
|
version: args.version,
|
||||||
|
package_name: args.package_name,
|
||||||
|
extra_packages: args.extra_packages,
|
||||||
|
exclude_packages: args.exclude_packages,
|
||||||
|
print_only: args.print_only?,
|
||||||
|
silent: args.silent?,
|
||||||
ignore_non_pypi_packages: args.ignore_non_pypi_packages?
|
ignore_non_pypi_packages: args.ignore_non_pypi_packages?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,18 +10,6 @@ module PyPI
|
|||||||
PYTHONHOSTED_URL_PREFIX = "https://files.pythonhosted.org/packages/"
|
PYTHONHOSTED_URL_PREFIX = "https://files.pythonhosted.org/packages/"
|
||||||
private_constant :PYTHONHOSTED_URL_PREFIX
|
private_constant :PYTHONHOSTED_URL_PREFIX
|
||||||
|
|
||||||
AUTOMATIC_RESOURCE_UPDATE_BLOCKLIST = %w[
|
|
||||||
ansible
|
|
||||||
ansible@2.8
|
|
||||||
cloudformation-cli
|
|
||||||
diffoscope
|
|
||||||
dxpy
|
|
||||||
ipython
|
|
||||||
molecule
|
|
||||||
salt
|
|
||||||
].freeze
|
|
||||||
private_constant :AUTOMATIC_RESOURCE_UPDATE_BLOCKLIST
|
|
||||||
|
|
||||||
@pipgrip_installed = nil
|
@pipgrip_installed = nil
|
||||||
|
|
||||||
def url_to_pypi_package_name(url)
|
def url_to_pypi_package_name(url)
|
||||||
@ -40,7 +28,11 @@ module PyPI
|
|||||||
|
|
||||||
# Get name, URL and SHA-256 checksum for a given PyPI package.
|
# Get name, URL and SHA-256 checksum for a given PyPI package.
|
||||||
def get_pypi_info(package, version)
|
def get_pypi_info(package, version)
|
||||||
metadata_url = "https://pypi.org/pypi/#{package}/#{version}/json"
|
metadata_url = if version.present?
|
||||||
|
"https://pypi.org/pypi/#{package}/#{version}/json"
|
||||||
|
else
|
||||||
|
"https://pypi.org/pypi/#{package}/json"
|
||||||
|
end
|
||||||
out, _, status = curl_output metadata_url, "--location"
|
out, _, status = curl_output metadata_url, "--location"
|
||||||
|
|
||||||
return unless status.success?
|
return unless status.success?
|
||||||
@ -58,17 +50,38 @@ module PyPI
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Return true if resources were checked (even if no change).
|
# Return true if resources were checked (even if no change).
|
||||||
def update_python_resources!(formula, version = nil, print_only: false, silent: false,
|
def update_python_resources!(formula, version: nil, package_name: nil, extra_packages: nil, exclude_packages: nil,
|
||||||
ignore_non_pypi_packages: false)
|
print_only: false, silent: false, ignore_non_pypi_packages: false)
|
||||||
|
|
||||||
if !print_only && AUTOMATIC_RESOURCE_UPDATE_BLOCKLIST.include?(formula.full_name)
|
auto_update_list = formula.tap.audit_exceptions[:automatic_resource_update_list]
|
||||||
|
if package_name.blank? && extra_packages.blank? && !print_only &&
|
||||||
|
auto_update_list.present? && auto_update_list.key?(formula.full_name)
|
||||||
|
|
||||||
|
list_entry = auto_update_list[formula.full_name]
|
||||||
|
case list_entry
|
||||||
|
when false
|
||||||
odie "The resources for \"#{formula.name}\" need special attention. Please update them manually."
|
odie "The resources for \"#{formula.name}\" need special attention. Please update them manually."
|
||||||
return
|
when String
|
||||||
|
package_name = list_entry
|
||||||
|
when Hash
|
||||||
|
package_name = list_entry["package_name"]
|
||||||
|
extra_packages = list_entry["extra_packages"]
|
||||||
|
exclude_packages = list_entry["exclude_packages"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pypi_name = url_to_pypi_package_name formula.stable.url
|
package_name ||= url_to_pypi_package_name formula.stable.url
|
||||||
|
version ||= formula.version
|
||||||
|
extra_packages ||= []
|
||||||
|
exclude_packages ||= []
|
||||||
|
|
||||||
if pypi_name.nil?
|
# opoo "package_name: #{package_name}"
|
||||||
|
# opoo "version: #{version}"
|
||||||
|
# opoo "extra_packages: #{extra_packages}"
|
||||||
|
# opoo "exclude_packages: #{exclude_packages}"
|
||||||
|
# odie ""
|
||||||
|
|
||||||
|
if package_name.nil?
|
||||||
return if ignore_non_pypi_packages
|
return if ignore_non_pypi_packages
|
||||||
|
|
||||||
odie <<~EOS
|
odie <<~EOS
|
||||||
@ -77,11 +90,24 @@ module PyPI
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
version ||= formula.version
|
input_package_names = { package_name => version }
|
||||||
|
extra_packages.each do |extra|
|
||||||
|
extra_name, extra_version = extra.split "=="
|
||||||
|
|
||||||
if get_pypi_info(pypi_name, version).blank?
|
if input_package_names.key?(extra_name) && input_package_names[extra_name] != extra_version
|
||||||
odie "\"#{pypi_name}\" at version #{version} is not available on PyPI." unless ignore_non_pypi_packages
|
odie "Conflicting versions specified for the `#{extra_name}` package: "\
|
||||||
return
|
"#{input_package_names[extra_name]}, #{extra_version}"
|
||||||
|
end
|
||||||
|
|
||||||
|
input_package_names[extra_name] = extra_version
|
||||||
|
end
|
||||||
|
|
||||||
|
input_package_names.each do |name, package_version|
|
||||||
|
name = name.split("[").first
|
||||||
|
next if get_pypi_info(name, package_version).present?
|
||||||
|
|
||||||
|
version_string = " at version #{package_version}" if package_version.present?
|
||||||
|
odie "\"#{name}\"#{version_string} is not available on PyPI." unless ignore_non_pypi_packages
|
||||||
end
|
end
|
||||||
|
|
||||||
non_pypi_resources = formula.resources.reject do |resource|
|
non_pypi_resources = formula.resources.reject do |resource|
|
||||||
@ -95,27 +121,43 @@ module PyPI
|
|||||||
@pipgrip_installed ||= Formula["pipgrip"].any_version_installed?
|
@pipgrip_installed ||= Formula["pipgrip"].any_version_installed?
|
||||||
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 \"#{pypi_name}==#{version}\"..." if !print_only && !silent
|
found_packages = {}
|
||||||
|
input_package_names.each do |name, package_version|
|
||||||
|
pypi_package_string = if package_version.present?
|
||||||
|
"#{name}==#{package_version}"
|
||||||
|
else
|
||||||
|
name
|
||||||
|
end
|
||||||
|
|
||||||
|
ohai "Retrieving PyPI dependencies for \"#{pypi_package_string}\"..." if !print_only && !silent
|
||||||
pipgrip_output = Utils.popen_read Formula["pipgrip"].bin/"pipgrip", "--json", "--no-cache-dir",
|
pipgrip_output = Utils.popen_read Formula["pipgrip"].bin/"pipgrip", "--json", "--no-cache-dir",
|
||||||
"#{pypi_name}==#{version}"
|
pypi_package_string
|
||||||
unless $CHILD_STATUS.success?
|
unless $CHILD_STATUS.success?
|
||||||
odie <<~EOS
|
odie <<~EOS
|
||||||
Unable to determine dependencies for \"#{pypi_name}\" because of a failure when running
|
Unable to determine dependencies for \"#{name}\" because of a failure when running
|
||||||
`pipgrip --json --no-cache-dir #{pypi_name}==#{version}`.
|
`pipgrip --json --no-cache-dir #{pypi_package_string}`.
|
||||||
Please update the resources for \"#{formula.name}\" manually.
|
Please update the resources for \"#{formula.name}\" manually.
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
packages = JSON.parse(pipgrip_output).sort.to_h
|
found_packages.merge!(JSON.parse(pipgrip_output).sort.to_h) do |conflicting_package, old_version, new_version|
|
||||||
|
next old_version if old_version == new_version
|
||||||
|
|
||||||
# Remove extra packages that may be included in pipgrip output
|
odie "Conflicting versions found for the `#{conflicting_package}` resource: #{old_version}, #{new_version}"
|
||||||
exclude_list = %W[#{pypi_name.downcase} argparse pip setuptools wheel wsgiref]
|
end
|
||||||
packages.delete_if do |package|
|
|
||||||
exclude_list.include? package
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Remove extra packages that may be included in pipgrip output
|
||||||
|
exclude_list = %W[#{package_name.downcase} argparse pip setuptools wheel wsgiref]
|
||||||
|
found_packages.delete_if { |package| exclude_list.include? package }
|
||||||
|
|
||||||
new_resource_blocks = ""
|
new_resource_blocks = ""
|
||||||
packages.each do |package, package_version|
|
found_packages.each do |package, package_version|
|
||||||
|
if exclude_packages.include? package
|
||||||
|
ohai "Excluding \"#{package}==#{package_version}\"" if !print_only && !silent
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
ohai "Getting PyPI info for \"#{package}==#{package_version}\"" if !print_only && !silent
|
ohai "Getting PyPI info for \"#{package}==#{package_version}\"" if !print_only && !silent
|
||||||
name, url, checksum = get_pypi_info package, package_version
|
name, url, checksum = get_pypi_info package, package_version
|
||||||
# Fail if unable to find name, url or checksum for any resource
|
# Fail if unable to find name, url or checksum for any resource
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user