Merge pull request #15582 from Bo98/no-api-migrate

Migrate remaining no-api commands to new scoped system
This commit is contained in:
Mike McQuaid 2023-06-22 19:52:56 +01:00 committed by GitHub
commit 66c6e5b5f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 104 additions and 120 deletions

View File

@ -862,6 +862,7 @@ fi
AUTO_UPDATE_CASK_TAP_COMMANDS=( AUTO_UPDATE_CASK_TAP_COMMANDS=(
bump bump
bump-cask-pr bump-cask-pr
bump-unversioned-casks
) )
if check-array-membership "${HOMEBREW_COMMAND}" "${AUTO_UPDATE_CASK_TAP_COMMANDS[@]}" if check-array-membership "${HOMEBREW_COMMAND}" "${AUTO_UPDATE_CASK_TAP_COMMANDS[@]}"
then then
@ -896,37 +897,6 @@ if [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${HOMEBREW_COMMAND}.sh" ]] ||
[[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${HOMEBREW_COMMAND}.rb" ]] [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${HOMEBREW_COMMAND}.rb" ]]
then then
export HOMEBREW_DEVELOPER_COMMAND="1" export HOMEBREW_DEVELOPER_COMMAND="1"
if [[ -z "${HOMEBREW_NO_INSTALL_FROM_API}" ]]
then
NO_INSTALL_FROM_API_COMMANDS=(
bottle
bump-cask-pr
bump-formula-pr
bump-revision
bump-unversioned-casks
bump
cat
create
edit
extract
formula
generate-cask-api
generate-formula-api
livecheck
pr-pull
pr-upload
update-python-resources
)
if check-array-membership "${HOMEBREW_COMMAND}" "${NO_INSTALL_FROM_API_COMMANDS[@]}"
then
export HOMEBREW_NO_INSTALL_FROM_API=1
export HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API=1
fi
unset NO_INSTALL_FROM_API_COMMANDS
fi
fi fi
if [[ -n "${HOMEBREW_DEVELOPER_COMMAND}" && -z "${HOMEBREW_DEVELOPER}" ]] if [[ -n "${HOMEBREW_DEVELOPER_COMMAND}" && -z "${HOMEBREW_DEVELOPER}" ]]

View File

@ -98,7 +98,7 @@ module Homebrew
conflicts "--formula", "--cask" conflicts "--formula", "--cask"
conflicts "--installed", "--all" conflicts "--installed", "--all"
named_args [:formula, :cask] named_args [:formula, :cask], without_api: true
end end
end end
@ -123,7 +123,7 @@ module Homebrew
ENV.activate_extensions! ENV.activate_extensions!
ENV.setup_build_environment ENV.setup_build_environment
audit_formulae, audit_casks = with_no_api_env do # audit requires full Ruby source audit_formulae, audit_casks = Homebrew.with_no_api_env do # audit requires full Ruby source
if args.tap if args.tap
Tap.fetch(args.tap).then do |tap| Tap.fetch(args.tap).then do |tap|
[ [
@ -217,7 +217,7 @@ module Homebrew
# Audit requires full Ruby source so disable API. # Audit requires full Ruby source so disable API.
# We shouldn't do this for taps however so that we don't unnecessarily require a full Homebrew/core clone. # We shouldn't do this for taps however so that we don't unnecessarily require a full Homebrew/core clone.
fa = if f.core_formula? fa = if f.core_formula?
with_no_api_env(&audit_proc) Homebrew.with_no_api_env(&audit_proc)
else else
audit_proc.call audit_proc.call
end end

View File

@ -86,7 +86,7 @@ module Homebrew
conflicts "--no-rebuild", "--keep-old" conflicts "--no-rebuild", "--keep-old"
named_args [:installed_formula, :file], min: 1 named_args [:installed_formula, :file], min: 1, without_api: true
end end
end end
@ -311,6 +311,7 @@ module Homebrew
tap = CoreTap.instance tap = CoreTap.instance
end end
raise TapUnavailableError, tap.name unless tap.installed?
return ofail "Formula has no stable version: #{formula.full_name}" unless formula.stable return ofail "Formula has no stable version: #{formula.full_name}" unless formula.stable

View File

@ -52,7 +52,7 @@ module Homebrew
conflicts "--dry-run", "--write" conflicts "--dry-run", "--write"
conflicts "--no-audit", "--online" conflicts "--no-audit", "--online"
named_args :cask, number: 1 named_args :cask, number: 1, without_api: true
end end
end end

View File

@ -85,7 +85,7 @@ module Homebrew
conflicts "--no-audit", "--online" conflicts "--no-audit", "--online"
conflicts "--url", "--tag" conflicts "--url", "--tag"
named_args :formula, max: 1 named_args :formula, max: 1, without_api: true
end end
end end

View File

@ -25,7 +25,7 @@ module Homebrew
conflicts "--dry-run", "--write-only" conflicts "--dry-run", "--write-only"
named_args :formula, min: 1 named_args :formula, min: 1, without_api: true
end end
end end

View File

@ -25,7 +25,7 @@ module Homebrew
flag "--state-file=", flag "--state-file=",
description: "File for caching state." description: "File for caching state."
named_args [:cask, :tap], min: 1 named_args [:cask, :tap], min: 1, without_api: true
end end
end end

View File

@ -33,7 +33,7 @@ module Homebrew
conflicts "--cask", "--formula" conflicts "--cask", "--formula"
conflicts "--no-pull-requests", "--open-pr" conflicts "--no-pull-requests", "--open-pr"
named_args [:formula, :cask] named_args [:formula, :cask], without_api: true
end end
end end

View File

@ -18,7 +18,7 @@ module Homebrew
conflicts "--formula", "--cask" conflicts "--formula", "--cask"
named_args [:formula, :cask], min: 1 named_args [:formula, :cask], min: 1, without_api: true
end end
end end

View File

@ -188,19 +188,24 @@ module Homebrew
EOS EOS
end end
if Formula.aliases.include? fc.name Homebrew.with_no_api_env do
realname = Formulary.canonical_name(fc.name) if Formula.aliases.include? fc.name
odie <<~EOS realname = Formulary.canonical_name(fc.name)
The formula '#{realname}' is already aliased to '#{fc.name}'. odie <<~EOS
Please check that you are not creating a duplicate. The formula '#{realname}' is already aliased to '#{fc.name}'.
To force creation use `--force`. Please check that you are not creating a duplicate.
EOS To force creation use `--force`.
EOS
end
end end
end end
fc.generate! fc.generate!
PyPI.update_python_resources! Formula[fc.name], ignore_non_pypi_packages: true if args.python? formula = Homebrew.with_no_api_env do
Formula[fc.name]
end
PyPI.update_python_resources! formula, ignore_non_pypi_packages: true if args.python?
puts "Please run `brew audit --new #{fc.name}` before submitting, thanks." puts "Please run `brew audit --new #{fc.name}` before submitting, thanks."
fc.path fc.path

View File

@ -24,7 +24,7 @@ module Homebrew
conflicts "--formula", "--cask" conflicts "--formula", "--cask"
named_args [:formula, :cask] named_args [:formula, :cask], without_api: true
end end
end end
@ -76,10 +76,9 @@ module Homebrew
end.presence end.presence
end end
if Homebrew::EnvConfig.automatically_set_no_install_from_api? && if !Homebrew::EnvConfig.no_install_from_api? && !Homebrew::EnvConfig.no_env_hints?
!Homebrew::EnvConfig.no_env_hints?
paths.each do |path| paths.each do |path|
next if !path.fnmatch?("**/homebrew-core/Formula/**/*.rb") && !path.fnmatch?("**/homebrew-cask/Casks/**/*.rb") next if !path.fnmatch?("**/homebrew-core/Formula/*.rb") && !path.fnmatch?("**/homebrew-cask/Casks/*.rb")
opoo <<~EOS opoo <<~EOS
Unless `HOMEBREW_NO_INSTALL_FROM_API` is set when running Unless `HOMEBREW_NO_INSTALL_FROM_API` is set when running

View File

@ -88,7 +88,7 @@ module Homebrew
switch "-f", "--force", switch "-f", "--force",
description: "Overwrite the destination formula if it already exists." description: "Overwrite the destination formula if it already exists."
named_args [:formula, :tap], number: 2 named_args [:formula, :tap], number: 2, without_api: true
end end
end end
@ -98,11 +98,11 @@ module Homebrew
if (match = args.named.first.match(HOMEBREW_TAP_FORMULA_REGEX)) if (match = args.named.first.match(HOMEBREW_TAP_FORMULA_REGEX))
name = match[3].downcase name = match[3].downcase
source_tap = Tap.fetch(match[1], match[2]) source_tap = Tap.fetch(match[1], match[2])
raise TapFormulaUnavailableError.new(source_tap, name) unless source_tap.installed?
else else
name = args.named.first.downcase name = args.named.first.downcase
source_tap = CoreTap.instance source_tap = CoreTap.instance
end end
raise TapFormulaUnavailableError.new(source_tap, name) unless source_tap.installed?
destination_tap = Tap.fetch(args.named.second) destination_tap = Tap.fetch(args.named.second)
unless Homebrew::EnvConfig.developer? unless Homebrew::EnvConfig.developer?

View File

@ -14,7 +14,7 @@ module Homebrew
Display the path where <formula> is located. Display the path where <formula> is located.
EOS EOS
named_args :formula, min: 1 named_args :formula, min: 1, without_api: true
end end
end end

View File

@ -43,6 +43,7 @@ module Homebrew
args = generate_cask_api_args.parse args = generate_cask_api_args.parse
tap = Tap.default_cask_tap tap = Tap.default_cask_tap
raise TapUnavailableError, tap.name unless tap.installed?
unless args.dry_run? unless args.dry_run?
directories = ["_data/cask", "api/cask", "api/cask-source", "cask"].freeze directories = ["_data/cask", "api/cask", "api/cask-source", "cask"].freeze
@ -50,22 +51,24 @@ module Homebrew
FileUtils.mkdir_p directories FileUtils.mkdir_p directories
end end
Cask::Cask.generating_hash! Homebrew.with_no_api_env do
Cask::Cask.generating_hash!
tap.cask_files.each do |path| tap.cask_files.each do |path|
cask = Cask::CaskLoader.load(path) cask = Cask::CaskLoader.load(path)
name = cask.token name = cask.token
json = JSON.pretty_generate(cask.to_hash_with_variations) json = JSON.pretty_generate(cask.to_hash_with_variations)
unless args.dry_run? unless args.dry_run?
File.write("_data/cask/#{name}.json", "#{json}\n") File.write("_data/cask/#{name}.json", "#{json}\n")
File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE) File.write("api/cask/#{name}.json", CASK_JSON_TEMPLATE)
File.write("api/cask-source/#{name}.rb", path.read) File.write("api/cask-source/#{name}.rb", path.read)
File.write("cask/#{name}.html", html_template(name)) File.write("cask/#{name}.html", html_template(name))
end
rescue
onoe "Error while generating data for cask '#{path.stem}'."
raise
end end
rescue
onoe "Error while generating data for cask '#{path.stem}'."
raise
end end
end end
end end

View File

@ -44,6 +44,7 @@ module Homebrew
args = generate_formula_api_args.parse args = generate_formula_api_args.parse
tap = CoreTap.instance tap = CoreTap.instance
raise TapUnavailableError, tap.name unless tap.installed?
unless args.dry_run? unless args.dry_run?
directories = ["_data/formula", "api/formula", "formula"] directories = ["_data/formula", "api/formula", "formula"]
@ -51,25 +52,27 @@ module Homebrew
FileUtils.mkdir_p directories FileUtils.mkdir_p directories
end end
Formulary.enable_factory_cache! Homebrew.with_no_api_env do
Formula.generating_hash! Formulary.enable_factory_cache!
Formula.generating_hash!
tap.formula_names.each do |name| tap.formula_names.each do |name|
formula = Formulary.factory(name) formula = Formulary.factory(name)
name = formula.name name = formula.name
json = JSON.pretty_generate(formula.to_hash_with_variations) json = JSON.pretty_generate(formula.to_hash_with_variations)
unless args.dry_run? unless args.dry_run?
File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n") File.write("_data/formula/#{name.tr("+", "_")}.json", "#{json}\n")
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE) File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
File.write("formula/#{name}.html", html_template(name)) File.write("formula/#{name}.html", html_template(name))
end
rescue
onoe "Error while generating data for formula '#{name}'."
raise
end end
rescue
onoe "Error while generating data for formula '#{name}'."
raise
end
canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table)) canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table))
File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run? File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run?
end
end end
end end

View File

@ -48,7 +48,7 @@ module Homebrew
conflicts "--tap=", "--eval-all", "--installed" conflicts "--tap=", "--eval-all", "--installed"
conflicts "--cask", "--formula" conflicts "--cask", "--formula"
named_args [:formula, :cask] named_args [:formula, :cask], without_api: true
end end
end end
@ -66,40 +66,42 @@ module Homebrew
puts Homebrew::EnvConfig.livecheck_watchlist if Homebrew::EnvConfig.livecheck_watchlist.present? puts Homebrew::EnvConfig.livecheck_watchlist if Homebrew::EnvConfig.livecheck_watchlist.present?
end end
formulae_and_casks_to_check = if args.tap formulae_and_casks_to_check = Homebrew.with_no_api_env do
tap = Tap.fetch(args.tap) if args.tap
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } tap = Tap.fetch(args.tap)
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) } formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
formulae + casks casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
elsif args.installed? formulae + casks
formulae = args.cask? ? [] : Formula.installed elsif args.installed?
casks = args.formula? ? [] : Cask::Caskroom.casks formulae = args.cask? ? [] : Formula.installed
formulae + casks casks = args.formula? ? [] : Cask::Caskroom.casks
elsif all formulae + casks
formulae = args.cask? ? [] : Formula.all elsif all
casks = args.formula? ? [] : Cask::Cask.all formulae = args.cask? ? [] : Formula.all
formulae + casks casks = args.formula? ? [] : Cask::Cask.all
elsif args.named.present? formulae + casks
if args.formula? elsif args.named.present?
args.named.to_formulae if args.formula?
elsif args.cask? args.named.to_formulae
args.named.to_casks elsif args.cask?
else args.named.to_casks
args.named.to_formulae_and_casks else
end args.named.to_formulae_and_casks
elsif File.exist?(WATCHLIST_PATH) end
begin elsif File.exist?(WATCHLIST_PATH)
names = Pathname.new(WATCHLIST_PATH).read.lines begin
.reject { |line| line.start_with?("#") || line.blank? } names = Pathname.new(WATCHLIST_PATH).read.lines
.map(&:strip) .reject { |line| line.start_with?("#") || line.blank? }
.map(&:strip)
named_args = CLI::NamedArgs.new(*names, parent: args) named_args = CLI::NamedArgs.new(*names, parent: args)
named_args.to_formulae_and_casks(ignore_unavailable: true) named_args.to_formulae_and_casks(ignore_unavailable: true)
rescue Errno::ENOENT => e rescue Errno::ENOENT => e
onoe e onoe e
end
else
raise UsageError, "A watchlist file is required when no arguments are given."
end end
else
raise UsageError, "A watchlist file is required when no arguments are given."
end end
formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask| formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask|

View File

@ -414,6 +414,7 @@ module Homebrew
workflows = args.workflows.presence || ["tests.yml"] workflows = args.workflows.presence || ["tests.yml"]
artifact = args.artifact || "bottles" artifact = args.artifact || "bottles"
tap = Tap.fetch(args.tap || CoreTap.instance.name) tap = Tap.fetch(args.tap || CoreTap.instance.name)
raise TapUnavailableError, tap.name unless tap.installed?
Utils::Git.set_name_email!(committer: args.committer.blank?) Utils::Git.set_name_email!(committer: args.committer.blank?)
Utils::Git.setup_gpg! Utils::Git.setup_gpg!

View File

@ -40,7 +40,7 @@ module Homebrew
conflicts "--formula", "--cask" conflicts "--formula", "--cask"
conflicts "--only-cops", "--except-cops" conflicts "--only-cops", "--except-cops"
named_args [:file, :tap, :formula, :cask] named_args [:file, :tap, :formula, :cask], without_api: true
end end
end end

View File

@ -30,7 +30,7 @@ module Homebrew
comma_array "--exclude-packages", comma_array "--exclude-packages",
description: "Exclude these packages when finding resources." description: "Exclude these packages when finding resources."
named_args :formula, min: 1 named_args :formula, min: 1, without_api: true
end end
end end