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

utils/pypi: specify dependencies needed to update resources #16772

Merged
merged 2 commits into from
Mar 4, 2024
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
3 changes: 3 additions & 0 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Expand Up @@ -72,6 +72,8 @@ def bump_formula_pr_args
"or specified <version>."
switch "-f", "--force",
description: "Remove all mirrors if `--mirror` was not specified."
switch "--install-dependencies",
description: "Install missing dependencies required to update resources."
flag "--python-package-name=",
description: "Use the specified <package-name> when finding Python resources for <formula>. " \
"If no package name is specified, it will be inferred from the formula's stable URL."
Expand Down Expand Up @@ -329,6 +331,7 @@ def bump_formula_pr
package_name: args.python_package_name,
extra_packages: args.python_extra_packages,
exclude_packages: args.python_exclude_packages,
install_dependencies: args.install_dependencies?,
silent: args.quiet?,
ignore_non_pypi_packages: true
end
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/dev-cmd/update-python-resources.rb
Expand Up @@ -19,6 +19,8 @@ def update_python_resources_args
description: "Suppress any output."
switch "--ignore-non-pypi-packages",
description: "Don't fail if <formula> is not a PyPI package."
switch "--install-dependencies",
description: "Install missing dependencies required to update resources."
flag "--version=",
description: "Use the specified <version> when finding resources for <formula>. " \
"If no version is specified, the current version for <formula> will be used."
Expand All @@ -43,6 +45,7 @@ def update_python_resources
package_name: args.package_name,
extra_packages: args.extra_packages,
exclude_packages: args.exclude_packages,
install_dependencies: args.install_dependencies?,
print_only: args.print_only?,
silent: args.silent?,
verbose: args.verbose?,
Expand Down
18 changes: 17 additions & 1 deletion Library/Homebrew/utils/pypi.rb
Expand Up @@ -198,14 +198,17 @@
package_name: T.nilable(String),
extra_packages: T.nilable(T::Array[String]),
exclude_packages: T.nilable(T::Array[String]),
dependencies: T.nilable(T::Array[String]),
install_dependencies: T.nilable(T::Boolean),
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, verbose: false,
exclude_packages: nil, dependencies: nil, install_dependencies: false,
print_only: false, silent: false, verbose: false,
ignore_non_pypi_packages: false)

auto_update_list = formula.tap&.pypi_formula_mappings
Expand All @@ -224,9 +227,22 @@
package_name = list_entry["package_name"]
extra_packages = list_entry["extra_packages"]
exclude_packages = list_entry["exclude_packages"]
dependencies = list_entry["dependencies"]

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L230

Added line #L230 was not covered by tests
end
end

missing_dependencies = Array(dependencies).reject do |dependency|
Formula[dependency].any_version_installed?

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L234-L235

Added lines #L234 - L235 were not covered by tests
rescue FormulaUnavailableError
odie "Formula \"#{dependency}\" not found but it is a dependency to update \"#{formula.name}\" resources."

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L237

Added line #L237 was not covered by tests
end
if missing_dependencies.present?
missing_msg = "formulae required to update \"#{formula.name}\" resources: #{missing_dependencies.join(", ")}"
odie "Missing #{missing_msg}" unless install_dependencies
ohai "Installing #{missing_msg}"
missing_dependencies.each(&method(:ensure_formula_installed!))

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L242-L243

Added lines #L242 - L243 were not covered by tests
end

python_deps = formula.deps
.select { |d| d.name.match?(/^python(@.+)?$/) }
.map(&:to_formula)
Expand Down
2 changes: 2 additions & 0 deletions completions/bash/brew
Expand Up @@ -500,6 +500,7 @@ _brew_bump_formula_pr() {
--force
--fork-org
--help
--install-dependencies
--message
--mirror
--no-audit
Expand Down Expand Up @@ -2471,6 +2472,7 @@ _brew_update_python_resources() {
--extra-packages
--help
--ignore-non-pypi-packages
--install-dependencies
--package-name
--print-only
--quiet
Expand Down
2 changes: 2 additions & 0 deletions completions/fish/brew.fish
Expand Up @@ -422,6 +422,7 @@ __fish_brew_complete_arg 'bump-formula-pr' -l dry-run -d 'Print what would be do
__fish_brew_complete_arg 'bump-formula-pr' -l force -d 'Remove all mirrors if `--mirror` was not specified'
__fish_brew_complete_arg 'bump-formula-pr' -l fork-org -d 'Use the specified GitHub organization for forking'
__fish_brew_complete_arg 'bump-formula-pr' -l help -d 'Show this message'
__fish_brew_complete_arg 'bump-formula-pr' -l install-dependencies -d 'Install missing dependencies required to update resources'
__fish_brew_complete_arg 'bump-formula-pr' -l message -d 'Prepend message to the default pull request message'
__fish_brew_complete_arg 'bump-formula-pr' -l mirror -d 'Use the specified URL as a mirror URL. If URL is a comma-separated list of URLs, multiple mirrors will be added'
__fish_brew_complete_arg 'bump-formula-pr' -l no-audit -d 'Don\'t run `brew audit` before opening the PR'
Expand Down Expand Up @@ -1611,6 +1612,7 @@ __fish_brew_complete_arg 'update-python-resources' -l exclude-packages -d 'Exclu
__fish_brew_complete_arg 'update-python-resources' -l extra-packages -d 'Include these additional packages when finding resources'
__fish_brew_complete_arg 'update-python-resources' -l help -d 'Show this message'
__fish_brew_complete_arg 'update-python-resources' -l ignore-non-pypi-packages -d 'Don\'t fail if formula is not a PyPI package'
__fish_brew_complete_arg 'update-python-resources' -l install-dependencies -d 'Install missing dependencies required to update resources'
__fish_brew_complete_arg 'update-python-resources' -l package-name -d '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'
__fish_brew_complete_arg 'update-python-resources' -l print-only -d 'Print the updated resource blocks instead of changing formula'
__fish_brew_complete_arg 'update-python-resources' -l quiet -d 'Make some output more quiet'
Expand Down
2 changes: 2 additions & 0 deletions completions/zsh/_brew
Expand Up @@ -546,6 +546,7 @@ _brew_bump_formula_pr() {
'--force[Remove all mirrors if `--mirror` was not specified]' \
'--fork-org[Use the specified GitHub organization for forking]' \
'--help[Show this message]' \
'--install-dependencies[Install missing dependencies required to update resources]' \
'--message[Prepend message to the default pull request message]' \
'--mirror[Use the specified URL as a mirror URL. If URL is a comma-separated list of URLs, multiple mirrors will be added]' \
'(--strict --online)--no-audit[Don'\''t run `brew audit` before opening the PR]' \
Expand Down Expand Up @@ -1995,6 +1996,7 @@ _brew_update_python_resources() {
'--extra-packages[Include these additional packages when finding resources]' \
'--help[Show this message]' \
'--ignore-non-pypi-packages[Don'\''t fail if formula is not a PyPI package]' \
'--install-dependencies[Install missing dependencies required to update resources]' \
'--package-name[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]' \
'--print-only[Print the updated resource blocks instead of changing formula]' \
'--quiet[Make some output more quiet]' \
Expand Down
4 changes: 4 additions & 0 deletions docs/Manpage.md
Expand Up @@ -1129,6 +1129,8 @@ nor vice versa. It must use whichever style specification the formula already us
Specify the new commit *`revision`* corresponding to the specified git *`tag`* or specified *`version`*.
* `-f`, `--force`:
Remove all mirrors if `--mirror` was not specified.
* `--install-dependencies`:
Install missing dependencies required to update resources.
* `--python-package-name`:
Use the specified *`package-name`* when finding Python resources for *`formula`*. If no package name is specified, it will be inferred from the formula's stable URL.
* `--python-extra-packages`:
Expand Down Expand Up @@ -1666,6 +1668,8 @@ Update versions for PyPI resource blocks in *`formula`*.
Suppress any output.
* `--ignore-non-pypi-packages`:
Don't fail if *`formula`* is not a PyPI package.
* `--install-dependencies`:
Install missing dependencies required to update resources.
* `--version`:
Use the specified *`version`* when finding resources for *`formula`*. If no version is specified, the current version for *`formula`* will be used.
* `--package-name`:
Expand Down
8 changes: 8 additions & 0 deletions manpages/brew.1
Expand Up @@ -1622,6 +1622,10 @@ Specify the new commit \fIrevision\fR corresponding to the specified git \fItag\
Remove all mirrors if \fB\-\-mirror\fR was not specified\.
.
.TP
\fB\-\-install\-dependencies\fR
Install missing dependencies required to update resources\.
.
.TP
\fB\-\-python\-package\-name\fR
Use the specified \fIpackage\-name\fR when finding Python resources for \fIformula\fR\. If no package name is specified, it will be inferred from the formula\'s stable URL\.
.
Expand Down Expand Up @@ -2385,6 +2389,10 @@ Suppress any output\.
Don\'t fail if \fIformula\fR is not a PyPI package\.
.
.TP
\fB\-\-install\-dependencies\fR
Install missing dependencies required to update resources\.
.
.TP
\fB\-\-version\fR
Use the specified \fIversion\fR when finding resources for \fIformula\fR\. If no version is specified, the current version for \fIformula\fR will be used\.
.
Expand Down