dev-cmd/unbottled: Bump to Sorbet typed: strict

This commit is contained in:
Issy Long 2024-06-30 17:49:27 +01:00
parent 09223c700a
commit 34caeb7ea8
No known key found for this signature in database

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command" require "abstract_command"
@ -34,11 +34,11 @@ module Homebrew
def run def run
Formulary.enable_factory_cache! Formulary.enable_factory_cache!
@bottle_tag = if (tag = args.tag) @bottle_tag = T.let(if (tag = args.tag)
Utils::Bottles::Tag.from_symbol(tag.to_sym) Utils::Bottles::Tag.from_symbol(tag.to_sym)
else else
Utils::Bottles.tag Utils::Bottles.tag
end end, T.nilable(Utils::Bottles::Tag))
if args.lost? if args.lost?
if args.named.present? if args.named.present?
@ -51,13 +51,13 @@ module Homebrew
end end
end end
os = @bottle_tag.system os = T.must(@bottle_tag).system
arch = if Hardware::CPU::INTEL_ARCHS.include?(@bottle_tag.arch) arch = if Hardware::CPU::INTEL_ARCHS.include?(T.must(@bottle_tag).arch)
:intel :intel
elsif Hardware::CPU::ARM_ARCHS.include?(@bottle_tag.arch) elsif Hardware::CPU::ARM_ARCHS.include?(T.must(@bottle_tag).arch)
:arm :arm
else else
raise "Unknown arch #{@bottle_tag.arch}." raise "Unknown arch #{T.must(@bottle_tag).arch}."
end end
Homebrew::SimulateSystem.with(os:, arch:) do Homebrew::SimulateSystem.with(os:, arch:) do
@ -98,12 +98,13 @@ module Homebrew
["installs", formula_installs] ["installs", formula_installs]
end end
output_unbottled(formulae, deps_hash, noun, hash, args.named.present?) output_unbottled(formulae, deps_hash, noun, T.must(hash), args.named.present?)
end end
end end
private private
sig { params(all: T::Boolean).returns([T::Array[Formula], T::Array[Formula], T.nilable(T::Hash[Symbol, Integer])]) }
def formulae_all_installs_from_args(all) def formulae_all_installs_from_args(all)
if args.named.present? if args.named.present?
formulae = all_formulae = args.named.to_formulae formulae = all_formulae = args.named.to_formulae
@ -115,7 +116,7 @@ module Homebrew
formulae = all_formulae = Formula.all(eval_all: args.eval_all?) formulae = all_formulae = Formula.all(eval_all: args.eval_all?)
@sort = " (sorted by number of dependents)" @sort = T.let(" (sorted by number of dependents)", T.nilable(String))
elsif all elsif all
formulae = all_formulae = Formula.all(eval_all: args.eval_all?) formulae = all_formulae = Formula.all(eval_all: args.eval_all?)
else else
@ -142,7 +143,7 @@ module Homebrew
nil nil
end end
end end
@sort = " (sorted by installs in the last 90 days; top 10,000 only)" @sort = T.let(" (sorted by installs in the last 90 days; top 10,000 only)", T.nilable(String))
all_formulae = Formula.all(eval_all: args.eval_all?) all_formulae = Formula.all(eval_all: args.eval_all?)
end end
@ -151,9 +152,10 @@ module Homebrew
formulae = Array(formulae).reject(&:deprecated?) if formulae.present? formulae = Array(formulae).reject(&:deprecated?) if formulae.present?
all_formulae = Array(all_formulae).reject(&:deprecated?) if all_formulae.present? all_formulae = Array(all_formulae).reject(&:deprecated?) if all_formulae.present?
[formulae, all_formulae, formula_installs] [T.let(formulae, T::Array[Formula]), T.let(all_formulae, T::Array[Formula]), T.let(T.must(formula_installs), T.nilable(T::Hash[Symbol, Integer]))]
end end
sig { params(all_formulae: T.untyped).returns([T::Hash[String, T.untyped], T::Hash[String, T.untyped]]) }
def deps_uses_from_formulae(all_formulae) def deps_uses_from_formulae(all_formulae)
ohai "Populating dependency tree..." ohai "Populating dependency tree..."
@ -175,6 +177,7 @@ module Homebrew
[deps_hash, uses_hash] [deps_hash, uses_hash]
end end
sig { params(formulae: T::Array[Formula]).returns(NilClass) }
def output_total(formulae) def output_total(formulae)
ohai "Unbottled :#{@bottle_tag} formulae" ohai "Unbottled :#{@bottle_tag} formulae"
unbottled_formulae = 0 unbottled_formulae = 0
@ -188,6 +191,7 @@ module Homebrew
puts "#{unbottled_formulae}/#{formulae.length} remaining." puts "#{unbottled_formulae}/#{formulae.length} remaining."
end end
sig { params(formulae: T::Array[Formula], deps_hash: T::Hash[T.any(Symbol, String), T.untyped], noun: T.nilable(String), hash: T::Hash[T.any(Symbol, String), T.untyped], any_named_args: T::Boolean).returns(NilClass) }
def output_unbottled(formulae, deps_hash, noun, hash, any_named_args) def output_unbottled(formulae, deps_hash, noun, hash, any_named_args)
ohai ":#{@bottle_tag} bottle status#{@sort}" ohai ":#{@bottle_tag} bottle status#{@sort}"
any_found = T.let(false, T::Boolean) any_found = T.let(false, T::Boolean)
@ -201,7 +205,7 @@ module Homebrew
end end
requirements = f.recursive_requirements requirements = f.recursive_requirements
if @bottle_tag.linux? if T.must(@bottle_tag).linux?
if requirements.any? { |r| r.is_a?(MacOSRequirement) && !r.version } if requirements.any? { |r| r.is_a?(MacOSRequirement) && !r.version }
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args
next next
@ -210,7 +214,7 @@ module Homebrew
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args
next next
else else
macos_version = @bottle_tag.to_macos_version macos_version = T.must(@bottle_tag).to_macos_version
macos_satisfied = requirements.all? do |r| macos_satisfied = requirements.all? do |r|
case r case r
when MacOSRequirement when MacOSRequirement
@ -222,7 +226,7 @@ module Homebrew
Version.new(MacOS::Xcode.latest_version(macos: macos_version)) >= r.version Version.new(MacOS::Xcode.latest_version(macos: macos_version)) >= r.version
when ArchRequirement when ArchRequirement
r.arch == @bottle_tag.arch r.arch == T.must(@bottle_tag).arch
else else
true true
end end
@ -258,6 +262,7 @@ module Homebrew
puts "No unbottled dependencies found!" puts "No unbottled dependencies found!"
end end
sig { returns(NilClass) }
def output_lost_bottles def output_lost_bottles
ohai ":#{@bottle_tag} lost bottles" ohai ":#{@bottle_tag} lost bottles"