Merge pull request #20182 from Homebrew/some-bundle-files-werent-typed-at-all-but-now-some-are

Reapply "Make some of the `bundle` commands Sorbet `typed: true`"
This commit is contained in:
Issy Long 2025-06-27 21:37:41 +00:00 committed by GitHub
commit c3ec61b7cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 21 deletions

View File

@ -1,4 +1,4 @@
# typed: false # rubocop:todo Sorbet/TrueSigil # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "json" require "json"
@ -8,9 +8,7 @@ module Homebrew
module Bundle module Bundle
# TODO: refactor into multiple modules # TODO: refactor into multiple modules
module BrewDumper module BrewDumper
module_function def self.reset!
def reset!
require "bundle/brew_services" require "bundle/brew_services"
Homebrew::Bundle::BrewServices.reset! Homebrew::Bundle::BrewServices.reset!
@ -21,14 +19,14 @@ module Homebrew
@formula_oldnames = nil @formula_oldnames = nil
end end
def formulae def self.formulae
return @formulae if @formulae return @formulae if @formulae
formulae_by_full_name formulae_by_full_name
@formulae @formulae
end end
def formulae_by_full_name(name = nil) def self.formulae_by_full_name(name = nil)
return @formulae_by_full_name[name] if name.present? && @formulae_by_full_name&.key?(name) return @formulae_by_full_name[name] if name.present? && @formulae_by_full_name&.key?(name)
require "formula" require "formula"
@ -51,11 +49,11 @@ module Homebrew
{} {}
end end
def formulae_by_name(name) def self.formulae_by_name(name)
formulae_by_full_name(name) || @formulae_by_name[name] formulae_by_full_name(name) || @formulae_by_name[name]
end end
def dump(describe: false, no_restart: false) def self.dump(describe: false, no_restart: false)
require "bundle/brew_services" require "bundle/brew_services"
requested_formula = formulae.select do |f| requested_formula = formulae.select do |f|
@ -77,7 +75,7 @@ module Homebrew
end.join("\n") end.join("\n")
end end
def formula_aliases def self.formula_aliases
return @formula_aliases if @formula_aliases return @formula_aliases if @formula_aliases
@formula_aliases = {} @formula_aliases = {}
@ -96,7 +94,7 @@ module Homebrew
@formula_aliases @formula_aliases
end end
def formula_oldnames def self.formula_oldnames
return @formula_oldnames if @formula_oldnames return @formula_oldnames if @formula_oldnames
@formula_oldnames = {} @formula_oldnames = {}
@ -115,7 +113,7 @@ module Homebrew
@formula_oldnames @formula_oldnames
end end
def add_formula(formula) private_class_method def self.add_formula(formula)
hash = formula_to_hash formula hash = formula_to_hash formula
@formulae_by_name[hash[:name]] = hash @formulae_by_name[hash[:name]] = hash
@ -123,9 +121,8 @@ module Homebrew
hash hash
end end
private_class_method :add_formula
def formula_to_hash(formula) private_class_method def self.formula_to_hash(formula)
keg = if formula.linked? keg = if formula.linked?
link = true if formula.keg_only? link = true if formula.keg_only?
formula.linked_keg formula.linked_keg
@ -185,17 +182,21 @@ module Homebrew
official_tap: formula.tap&.official? || false, official_tap: formula.tap&.official? || false,
} }
end end
private_class_method :formula_to_hash
class Topo < Hash class Topo < Hash
include TSort include TSort
def each_key(&block)
keys.each(&block)
end
alias tsort_each_node each_key alias tsort_each_node each_key
def tsort_each_child(node, &block) def tsort_each_child(node, &block)
fetch(node.downcase).sort.each(&block) fetch(node.downcase).sort.each(&block)
end end
end end
def sort!(formulae) private_class_method def self.sort!(formulae)
# Step 1: Sort by formula full name while putting tap formulae behind core formulae. # Step 1: Sort by formula full name while putting tap formulae behind core formulae.
# So we can have a nicer output. # So we can have a nicer output.
formulae = formulae.sort do |a, b| formulae = formulae.sort do |a, b|
@ -230,15 +231,14 @@ module Homebrew
odie <<~EOS odie <<~EOS
Formulae dependency graph sorting failed (likely due to a circular dependency): Formulae dependency graph sorting failed (likely due to a circular dependency):
#{cycle_first}: #{topo[cycle_first]} #{cycle_first}: #{topo[cycle_first] if topo}
#{cycle_last}: #{topo[cycle_last]} #{cycle_last}: #{topo[cycle_last] if topo}
Please run the following commands and try again: Please run the following commands and try again:
brew update brew update
brew uninstall --ignore-dependencies --force #{cycle_first} #{cycle_last} brew uninstall --ignore-dependencies --force #{cycle_first} #{cycle_last}
brew install #{cycle_first} #{cycle_last} brew install #{cycle_first} #{cycle_last}
EOS EOS
end end
private_class_method :sort!
end end
end end
end end

View File

@ -1,4 +1,4 @@
# typed: false # rubocop:todo Sorbet/TrueSigil # typed: true
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
@ -23,7 +23,7 @@ module Homebrew
else else
"needs to be installed or updated." "needs to be installed or updated."
end end
"#{self.class::PACKAGE_TYPE_NAME} #{name} #{reason}" "#{self.class.const_get(:PACKAGE_TYPE_NAME)} #{name} #{reason}"
end end
def full_check(packages, no_upgrade:) def full_check(packages, no_upgrade:)
@ -33,7 +33,7 @@ module Homebrew
def checkable_entries(all_entries) def checkable_entries(all_entries)
require "bundle/skipper" require "bundle/skipper"
all_entries.select { |e| e.type == self.class::PACKAGE_TYPE } all_entries.select { |e| e.type == self.class.const_get(:PACKAGE_TYPE) }
.reject(&Bundle::Skipper.method(:skip?)) .reject(&Bundle::Skipper.method(:skip?))
end end