Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update-python-resources: show pip install failure when --verbose #16412

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/dev-cmd/update-python-resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def update_python_resources
exclude_packages: args.exclude_packages,
print_only: args.print_only?,
silent: args.silent?,
verbose: args.verbose?,
ignore_non_pypi_packages: args.ignore_non_pypi_packages?
end
end
Expand Down
29 changes: 18 additions & 11 deletions Library/Homebrew/utils/pypi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,12 @@
exclude_packages: T.nilable(T::Array[String]),
print_only: T.nilable(T::Boolean),
silent: T.nilable(T::Boolean),
verbose: T.nilable(T::Boolean),
ignore_non_pypi_packages: T.nilable(T::Boolean),
).returns(T.nilable(T::Boolean))
}
def self.update_python_resources!(formula, version: nil, package_name: nil, extra_packages: nil,
exclude_packages: nil, print_only: false, silent: false,
exclude_packages: nil, print_only: false, silent: false, verbose: false,
ignore_non_pypi_packages: false)

auto_update_list = formula.tap&.pypi_formula_mappings
Expand Down Expand Up @@ -289,21 +290,23 @@
ensure_formula_installed!(python_name)

# Resolve the dependency tree of all input packages
ohai "Retrieving PyPI dependencies for \"#{input_packages.join(" ")}\"..." if !print_only && !silent
found_packages = pip_report(input_packages, python_name: python_name)
show_info = !print_only && !silent

Check warning on line 293 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L293

Added line #L293 was not covered by tests
ohai "Retrieving PyPI dependencies for \"#{input_packages.join(" ")}\"..." if show_info
found_packages = pip_report(input_packages, python_name: python_name, print_stderr: verbose && show_info)

Check warning on line 295 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L295

Added line #L295 was not covered by tests
# Resolve the dependency tree of excluded packages to prune the above
exclude_packages.delete_if { |package| found_packages.exclude? package }
ohai "Retrieving PyPI dependencies for excluded \"#{exclude_packages.join(" ")}\"..." if !print_only && !silent
exclude_packages = pip_report(exclude_packages, python_name: python_name) + [Package.new(main_package.name)]
ohai "Retrieving PyPI dependencies for excluded \"#{exclude_packages.join(" ")}\"..." if show_info
exclude_packages = pip_report(exclude_packages, python_name: python_name, print_stderr: verbose && show_info)
exclude_packages += [Package.new(main_package.name)]

Check warning on line 300 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L299-L300

Added lines #L299 - L300 were not covered by tests

new_resource_blocks = ""
found_packages.sort.each do |package|
if exclude_packages.include? package
ohai "Excluding \"#{package}\"" if !print_only && !silent
ohai "Excluding \"#{package}\"" if show_info
next
end

ohai "Getting PyPI info for \"#{package}\"" if !print_only && !silent
ohai "Getting PyPI info for \"#{package}\"" if show_info
name, url, checksum = package.pypi_info
# Fail if unable to find name, url or checksum for any resource
if name.blank?
Expand Down Expand Up @@ -358,12 +361,16 @@
name.gsub(/[-_.]+/, "-").downcase
end

def self.pip_report(packages, python_name: "python")
def self.pip_report(packages, python_name: "python", print_stderr: false)
return [] if packages.blank?

command = [Formula[python_name].libexec/"bin/python", "-m", "pip", "install", "-q", "--dry-run",
"--ignore-installed", "--report=/dev/stdout", *packages.map(&:to_s)]
pip_output = Utils.popen_read({ "PIP_REQUIRE_VIRTUALENV" => "false" }, *command)
command = [
Formula[python_name].libexec/"bin/python", "-m", "pip", "install", "-q", "--disable-pip-version-check",

Check warning on line 368 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L368

Added line #L368 was not covered by tests
"--dry-run", "--ignore-installed", "--report=/dev/stdout", *packages.map(&:to_s)
]
options = {}

Check warning on line 371 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L371

Added line #L371 was not covered by tests
options[:err] = :err if print_stderr
pip_output = Utils.popen_read({ "PIP_REQUIRE_VIRTUALENV" => "false" }, *command, **options)

Check warning on line 373 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L373

Added line #L373 was not covered by tests
unless $CHILD_STATUS.success?
odie <<~EOS
Unable to determine dependencies for "#{packages.join(" ")}" because of a failure when running
Expand Down