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