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,6 +188,7 @@ module Homebrew
EOS EOS
end end
Homebrew.with_no_api_env do
if Formula.aliases.include? fc.name if Formula.aliases.include? fc.name
realname = Formulary.canonical_name(fc.name) realname = Formulary.canonical_name(fc.name)
odie <<~EOS odie <<~EOS
@ -197,10 +198,14 @@ module Homebrew
EOS 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,6 +51,7 @@ module Homebrew
FileUtils.mkdir_p directories FileUtils.mkdir_p directories
end end
Homebrew.with_no_api_env do
Cask::Cask.generating_hash! Cask::Cask.generating_hash!
tap.cask_files.each do |path| tap.cask_files.each do |path|
@ -69,3 +71,4 @@ module Homebrew
end 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,6 +52,7 @@ module Homebrew
FileUtils.mkdir_p directories FileUtils.mkdir_p directories
end end
Homebrew.with_no_api_env do
Formulary.enable_factory_cache! Formulary.enable_factory_cache!
Formula.generating_hash! Formula.generating_hash!
@ -73,3 +75,4 @@ module Homebrew
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,7 +66,8 @@ 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
if args.tap
tap = Tap.fetch(args.tap) tap = Tap.fetch(args.tap)
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) } casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
@ -101,6 +102,7 @@ module Homebrew
else else
raise UsageError, "A watchlist file is required when no arguments are given." raise UsageError, "A watchlist file is required when no arguments are given."
end 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|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name

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