mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
utils/pypi: use python from formula for non-pypi url metadata
This fixes the resource detection when formula has Python packages that are not compatible with current aliased python formula, e.g. `awscli` Also switch to `opt_libexec` path to ignore Python formula patch version and revision bump differences.
This commit is contained in:
parent
678bfecc5a
commit
53bb72548a
@ -13,12 +13,13 @@ module PyPI
|
|||||||
# or it can be a non-PyPI URL.
|
# or it can be a non-PyPI URL.
|
||||||
# @api private
|
# @api private
|
||||||
class Package
|
class Package
|
||||||
sig { params(package_string: String, is_url: T::Boolean).void }
|
sig { params(package_string: String, is_url: T::Boolean, python_name: String).void }
|
||||||
def initialize(package_string, is_url: false)
|
def initialize(package_string, is_url: false, python_name: "python")
|
||||||
@pypi_info = nil
|
@pypi_info = nil
|
||||||
@package_string = package_string
|
@package_string = package_string
|
||||||
@is_url = is_url
|
@is_url = is_url
|
||||||
@is_pypi_url = package_string.start_with? PYTHONHOSTED_URL_PREFIX
|
@is_pypi_url = package_string.start_with? PYTHONHOSTED_URL_PREFIX
|
||||||
|
@python_name = python_name
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
@ -131,7 +132,7 @@ module PyPI
|
|||||||
@extras ||= []
|
@extras ||= []
|
||||||
@version ||= match[2]
|
@version ||= match[2]
|
||||||
elsif @is_url
|
elsif @is_url
|
||||||
ensure_formula_installed!("python")
|
ensure_formula_installed!(@python_name)
|
||||||
|
|
||||||
# The URL might be a source distribution hosted somewhere;
|
# The URL might be a source distribution hosted somewhere;
|
||||||
# try and use `pip install -q --no-deps --dry-run --report ...` to get its
|
# try and use `pip install -q --no-deps --dry-run --report ...` to get its
|
||||||
@ -140,7 +141,7 @@ module PyPI
|
|||||||
# do below, in that it uses `--no-deps` because we only care about resolving
|
# do below, in that it uses `--no-deps` because we only care about resolving
|
||||||
# this specific URL's project metadata.
|
# this specific URL's project metadata.
|
||||||
command =
|
command =
|
||||||
[Formula["python"].bin/"python3", "-m", "pip", "install", "-q", "--no-deps",
|
[Formula[@python_name].opt_libexec/"bin/python", "-m", "pip", "install", "-q", "--no-deps",
|
||||||
"--dry-run", "--ignore-installed", "--report", "/dev/stdout", @package_string]
|
"--dry-run", "--ignore-installed", "--report", "/dev/stdout", @package_string]
|
||||||
pip_output = Utils.popen_read({ "PIP_REQUIRE_VIRTUALENV" => "false" }, *command)
|
pip_output = Utils.popen_read({ "PIP_REQUIRE_VIRTUALENV" => "false" }, *command)
|
||||||
unless $CHILD_STATUS.success?
|
unless $CHILD_STATUS.success?
|
||||||
@ -226,8 +227,19 @@ module PyPI
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
python_deps = formula.deps
|
||||||
|
.select { |d| d.name.match?(/^python(@.+)?$/) }
|
||||||
|
.map(&:to_formula)
|
||||||
|
.sort_by(&:version)
|
||||||
|
.reverse
|
||||||
|
python_name = if python_deps.empty?
|
||||||
|
"python"
|
||||||
|
else
|
||||||
|
(python_deps.find(&:any_version_installed?) || python_deps.first).name
|
||||||
|
end
|
||||||
|
|
||||||
main_package = if package_name.present?
|
main_package = if package_name.present?
|
||||||
Package.new(package_name)
|
Package.new(package_name, python_name: python_name)
|
||||||
else
|
else
|
||||||
stable = T.must(formula.stable)
|
stable = T.must(formula.stable)
|
||||||
url = if stable.specs[:tag].present?
|
url = if stable.specs[:tag].present?
|
||||||
@ -235,7 +247,7 @@ module PyPI
|
|||||||
else
|
else
|
||||||
stable.url
|
stable.url
|
||||||
end
|
end
|
||||||
Package.new(url, is_url: true)
|
Package.new(url, is_url: true, python_name: python_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if version.present?
|
if version.present?
|
||||||
@ -249,12 +261,6 @@ module PyPI
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
python_deps = formula.deps
|
|
||||||
.select { |d| d.name.match?(/^python(@.+)?$/) }
|
|
||||||
.map(&:to_formula)
|
|
||||||
.sort_by(&:version)
|
|
||||||
.reverse
|
|
||||||
|
|
||||||
extra_packages = (extra_packages || []).map { |p| Package.new p }
|
extra_packages = (extra_packages || []).map { |p| Package.new p }
|
||||||
exclude_packages = (exclude_packages || []).map { |p| Package.new p }
|
exclude_packages = (exclude_packages || []).map { |p| Package.new p }
|
||||||
exclude_packages += %w[argparse pip wsgiref].map { |p| Package.new p }
|
exclude_packages += %w[argparse pip wsgiref].map { |p| Package.new p }
|
||||||
@ -286,11 +292,6 @@ module PyPI
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
python_name = if python_deps.empty?
|
|
||||||
"python"
|
|
||||||
else
|
|
||||||
(python_deps.find(&:any_version_installed?) || python_deps.first).name
|
|
||||||
end
|
|
||||||
ensure_formula_installed!(python_name)
|
ensure_formula_installed!(python_name)
|
||||||
|
|
||||||
# Resolve the dependency tree of all input packages
|
# Resolve the dependency tree of all input packages
|
||||||
@ -372,7 +373,7 @@ module PyPI
|
|||||||
return [] if packages.blank?
|
return [] if packages.blank?
|
||||||
|
|
||||||
command = [
|
command = [
|
||||||
Formula[python_name].libexec/"bin/python", "-m", "pip", "install", "-q", "--disable-pip-version-check",
|
Formula[python_name].opt_libexec/"bin/python", "-m", "pip", "install", "-q", "--disable-pip-version-check",
|
||||||
"--dry-run", "--ignore-installed", "--report=/dev/stdout", *packages.map(&:to_s)
|
"--dry-run", "--ignore-installed", "--report=/dev/stdout", *packages.map(&:to_s)
|
||||||
]
|
]
|
||||||
options = {}
|
options = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user