mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
move pypi list to tap formula_lists directory
This commit is contained in:
parent
b1d907291b
commit
51a1b7c9e1
@ -27,7 +27,6 @@ module Homebrew
|
||||
description: "Use the specified <version> when finding resources for <formula>. "\
|
||||
"If no version is specified, the current version for <formula> will be used."
|
||||
flag "--package-name=",
|
||||
depends_on: "--version",
|
||||
description: "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."
|
||||
comma_array "--extra-packages=",
|
||||
|
@ -21,11 +21,13 @@ class Tap
|
||||
HOMEBREW_TAP_FORMULA_RENAMES_FILE = "formula_renames.json"
|
||||
HOMEBREW_TAP_MIGRATIONS_FILE = "tap_migrations.json"
|
||||
HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR = "audit_exceptions"
|
||||
HOMEBREW_TAP_FORMULA_LISTS_DIR = "formula_lists"
|
||||
|
||||
HOMEBREW_TAP_JSON_FILES = %W[
|
||||
#{HOMEBREW_TAP_FORMULA_RENAMES_FILE}
|
||||
#{HOMEBREW_TAP_MIGRATIONS_FILE}
|
||||
#{HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR}/*.json
|
||||
#{HOMEBREW_TAP_FORMULA_LISTS_DIR}/*.json
|
||||
].freeze
|
||||
|
||||
def self.fetch(*args)
|
||||
@ -112,6 +114,7 @@ class Tap
|
||||
@formula_renames = nil
|
||||
@tap_migrations = nil
|
||||
@audit_exceptions = nil
|
||||
@formula_lists = nil
|
||||
@config = nil
|
||||
remove_instance_variable(:@private) if instance_variable_defined?(:@private)
|
||||
end
|
||||
@ -560,22 +563,12 @@ class Tap
|
||||
|
||||
# Hash with audit exceptions
|
||||
def audit_exceptions
|
||||
@audit_exceptions = {}
|
||||
|
||||
Pathname.glob(path/HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR/"*").each do |exception_file|
|
||||
list_name = exception_file.basename.to_s.chomp(".json").to_sym
|
||||
list_contents = begin
|
||||
JSON.parse exception_file.read
|
||||
rescue JSON::ParserError
|
||||
opoo "#{exception_file} contains invalid JSON"
|
||||
@audit_exceptions = read_formula_list_directory HOMEBREW_TAP_AUDIT_EXCEPTIONS_DIR
|
||||
end
|
||||
|
||||
next if list_contents.nil?
|
||||
|
||||
@audit_exceptions[list_name] = list_contents
|
||||
end
|
||||
|
||||
@audit_exceptions
|
||||
# Hash with formula lists
|
||||
def formula_lists
|
||||
@formula_lists = read_formula_list_directory HOMEBREW_TAP_FORMULA_LISTS_DIR
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@ -636,6 +629,25 @@ class Tap
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def read_formula_list_directory(directory)
|
||||
list = {}
|
||||
|
||||
Pathname.glob(path/directory/"*").each do |exception_file|
|
||||
list_name = exception_file.basename.to_s.chomp(".json").to_sym
|
||||
list_contents = begin
|
||||
JSON.parse exception_file.read
|
||||
rescue JSON::ParserError
|
||||
opoo "#{exception_file} contains invalid JSON"
|
||||
end
|
||||
|
||||
next if list_contents.nil?
|
||||
|
||||
list[list_name] = list_contents
|
||||
end
|
||||
|
||||
list
|
||||
end
|
||||
end
|
||||
|
||||
# A specialized {Tap} class for the core formulae.
|
||||
@ -739,6 +751,13 @@ class CoreTap < Tap
|
||||
end
|
||||
end
|
||||
|
||||
def formula_lists
|
||||
@formula_lists ||= begin
|
||||
self.class.ensure_installed!
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# @private
|
||||
def formula_file_to_name(file)
|
||||
file.basename(".rb").to_s
|
||||
|
@ -15,13 +15,14 @@ module Homebrew
|
||||
@name = tap.name
|
||||
@path = tap.path
|
||||
@tap_audit_exceptions = tap.audit_exceptions
|
||||
@tap_formula_lists = tap.formula_lists
|
||||
@problems = []
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def audit
|
||||
audit_json_files
|
||||
audit_tap_audit_exceptions
|
||||
audit_tap_formula_lists
|
||||
end
|
||||
|
||||
sig { void }
|
||||
@ -35,11 +36,16 @@ module Homebrew
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def audit_tap_audit_exceptions
|
||||
@tap_audit_exceptions.each do |list_name, formula_names|
|
||||
def audit_tap_formula_lists
|
||||
tap_lists = {
|
||||
audit_exceptions: @tap_audit_exceptions,
|
||||
formula_lists: @tap_formula_lists,
|
||||
}
|
||||
tap_lists.each do |list_directory, list|
|
||||
list.each do |list_name, formula_names|
|
||||
unless [Hash, Array].include? formula_names.class
|
||||
problem <<~EOS
|
||||
audit_exceptions/#{list_name}.json should contain a JSON array
|
||||
#{list_directory}/#{list_name}.json should contain a JSON array
|
||||
of formula names or a JSON object mapping formula names to values
|
||||
EOS
|
||||
next
|
||||
@ -57,12 +63,13 @@ module Homebrew
|
||||
next if invalid_formulae.empty?
|
||||
|
||||
problem <<~EOS
|
||||
audit_exceptions/#{list_name}.json references
|
||||
#{list_directory}/#{list_name}.json references
|
||||
formulae that are not found in the #{@name} tap.
|
||||
Invalid formulae: #{invalid_formulae.join(", ")}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(message: String).void }
|
||||
def problem(message)
|
||||
|
@ -26,8 +26,9 @@ module PyPI
|
||||
url
|
||||
end
|
||||
|
||||
# Get name, URL and SHA-256 checksum for a given PyPI package.
|
||||
def get_pypi_info(package, version)
|
||||
# Get name, URL, SHA-256 checksum, and latest version for a given PyPI package.
|
||||
def get_pypi_info(package, version = nil)
|
||||
package = package.split("[").first
|
||||
metadata_url = if version.present?
|
||||
"https://pypi.org/pypi/#{package}/#{version}/json"
|
||||
else
|
||||
@ -46,15 +47,15 @@ module PyPI
|
||||
sdist = json["urls"].find { |url| url["packagetype"] == "sdist" }
|
||||
return json["info"]["name"] if sdist.nil?
|
||||
|
||||
[json["info"]["name"], sdist["url"], sdist["digests"]["sha256"]]
|
||||
[json["info"]["name"], sdist["url"], sdist["digests"]["sha256"], json["info"]["version"]]
|
||||
end
|
||||
|
||||
# Return true if resources were checked (even if no change).
|
||||
def update_python_resources!(formula, version: nil, package_name: nil, extra_packages: nil, exclude_packages: nil,
|
||||
print_only: false, silent: false, ignore_non_pypi_packages: false)
|
||||
|
||||
auto_update_list = formula.tap.audit_exceptions[:automatic_resource_update_list]
|
||||
if package_name.blank? && extra_packages.blank? && !print_only &&
|
||||
auto_update_list = formula.tap.formula_lists[:pypi_automatic_resource_update_list]
|
||||
if package_name.blank? && extra_packages.blank? && exclude_packages.blank? && !print_only &&
|
||||
auto_update_list.present? && auto_update_list.key?(formula.full_name)
|
||||
|
||||
list_entry = auto_update_list[formula.full_name]
|
||||
@ -70,18 +71,12 @@ module PyPI
|
||||
end
|
||||
end
|
||||
|
||||
version ||= formula.version if package_name.blank?
|
||||
package_name ||= url_to_pypi_package_name formula.stable.url
|
||||
version ||= formula.version
|
||||
extra_packages ||= []
|
||||
exclude_packages ||= []
|
||||
|
||||
# opoo "package_name: #{package_name}"
|
||||
# opoo "version: #{version}"
|
||||
# opoo "extra_packages: #{extra_packages}"
|
||||
# opoo "exclude_packages: #{exclude_packages}"
|
||||
# odie ""
|
||||
|
||||
if package_name.nil?
|
||||
if package_name.blank?
|
||||
return if ignore_non_pypi_packages
|
||||
|
||||
odie <<~EOS
|
||||
@ -140,7 +135,7 @@ module PyPI
|
||||
EOS
|
||||
end
|
||||
|
||||
found_packages.merge!(JSON.parse(pipgrip_output).sort.to_h) do |conflicting_package, old_version, new_version|
|
||||
found_packages.merge!(JSON.parse(pipgrip_output).to_h) do |conflicting_package, old_version, new_version|
|
||||
next old_version if old_version == new_version
|
||||
|
||||
odie "Conflicting versions found for the `#{conflicting_package}` resource: #{old_version}, #{new_version}"
|
||||
@ -148,11 +143,11 @@ module PyPI
|
||||
end
|
||||
|
||||
# Remove extra packages that may be included in pipgrip output
|
||||
exclude_list = %W[#{package_name.downcase} argparse pip setuptools wheel wsgiref]
|
||||
exclude_list = %W[#{package_name.split("[").first.downcase} argparse pip setuptools wheel wsgiref]
|
||||
found_packages.delete_if { |package| exclude_list.include? package }
|
||||
|
||||
new_resource_blocks = ""
|
||||
found_packages.each do |package, package_version|
|
||||
found_packages.sort.each do |package, package_version|
|
||||
if exclude_packages.include? package
|
||||
ohai "Excluding \"#{package}==#{package_version}\"" if !print_only && !silent
|
||||
next
|
||||
|
Loading…
x
Reference in New Issue
Block a user