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