From ccd46af7c6345bdcec102a23d27cc307a050293e Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 14 Jun 2022 16:42:10 -0400 Subject: [PATCH] Cleanup --- Library/Homebrew/api/formula.rb | 22 +++++++--------------- Library/Homebrew/formulary.rb | 24 ------------------------ Library/Homebrew/test/formulary_spec.rb | 23 ----------------------- 3 files changed, 7 insertions(+), 62 deletions(-) diff --git a/Library/Homebrew/api/formula.rb b/Library/Homebrew/api/formula.rb index 3cc9fb2414..a70fe31b8c 100644 --- a/Library/Homebrew/api/formula.rb +++ b/Library/Homebrew/api/formula.rb @@ -29,7 +29,13 @@ module Homebrew sig { returns(Array) } def all_formulae @all_formulae ||= begin - download_formulae_if_needed + curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json] + if cached_formula_json_file.exist? + last_modified = cached_formula_json_file.mtime.utc + last_modified = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT") + curl_args = ["--header", "If-Modified-Since: #{last_modified}", *curl_args] + end + curl_download(*curl_args, to: HOMEBREW_CACHE_API/"#{formula_api_path}.json", max_time: 5) json_formulae = JSON.parse(cached_formula_json_file.read) @@ -38,20 +44,6 @@ module Homebrew end end end - - private - - sig { void } - def download_formulae_if_needed - curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json] - if cached_formula_json_file.exist? - last_modified = cached_formula_json_file.mtime.utc - last_modified = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT") - curl_args = ["--header", "If-Modified-Since: #{last_modified}", *curl_args] - end - - curl_download(*curl_args, to: HOMEBREW_CACHE_API/"#{formula_api_path}.json", max_time: 5) - end end end end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index d98ceff026..000acb1db0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -520,12 +520,6 @@ module Formulary ) raise ArgumentError, "Formulae must have a ref!" unless ref - if Homebrew::EnvConfig.install_from_api? && - @formula_name_local_bottle_path_map.present? && - @formula_name_local_bottle_path_map.key?(ref) - ref = @formula_name_local_bottle_path_map[ref] - end - cache_key = "#{ref}-#{spec}-#{alias_path}-#{from}" if factory_cached? && cache[:formulary_factory] && cache[:formulary_factory][cache_key] @@ -542,24 +536,6 @@ module Formulary formula end - # Map a formula name to a local/fetched bottle archive. This mapping will be used by {Formulary::factory} - # to allow formulae to be loaded automatically from their local bottle archive without - # needing to exist in a tap or be passed as a complete path. For example, - # to map `hello` from its bottle archive: - #
Formulary.map_formula_name_to_local_bottle_path "hello", HOMEBREW_CACHE/"hello--2.10"
-  # Formulary.factory "hello" # returns the hello formula from the local bottle archive
-  # 
- # @param formula_name the formula name string to map. - # @param local_bottle_path a path pointing to the target bottle archive. - def self.map_formula_name_to_local_bottle_path(formula_name, local_bottle_path) - unless Homebrew::EnvConfig.install_from_api? - raise UsageError, "HOMEBREW_INSTALL_FROM_API not set but required for #{__method__}!" - end - - @formula_name_local_bottle_path_map ||= {} - @formula_name_local_bottle_path_map[formula_name] = Pathname(local_bottle_path).realpath - end - # Return a {Formula} instance for the given rack. # # @param spec when nil, will auto resolve the formula's spec. diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 78b0a413fc..7beed155a0 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -203,29 +203,6 @@ describe Formulary do end end - describe "::map_formula_name_to_local_bottle_path" do - before do - formula_path.dirname.mkpath - formula_path.write formula_content - end - - it "maps a reference to a new Formula" do - expect { - described_class.factory("formula-to-map") - }.to raise_error(FormulaUnavailableError) - - ENV["HOMEBREW_INSTALL_FROM_API"] = nil - expect { - described_class.map_formula_name_to_local_bottle_path "formula-to-map", formula_path - }.to raise_error(UsageError, /HOMEBREW_INSTALL_FROM_API not set/) - - ENV["HOMEBREW_INSTALL_FROM_API"] = "1" - described_class.map_formula_name_to_local_bottle_path "formula-to-map", formula_path - - expect(described_class.factory("formula-to-map")).to be_kind_of(Formula) - end - end - specify "::from_contents" do expect(described_class.from_contents(formula_name, formula_path, formula_content)).to be_kind_of(Formula) end