Skip to content

Commit

Permalink
Enable typing in a few more files
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Mar 9, 2023
1 parent cb5e829 commit 02fd042
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Cask
Expand Down
7 changes: 7 additions & 0 deletions Library/Homebrew/cask/metdata.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# typed: strict

module Cask
module Metadata
requires_ancestor { Cask }
end
end
1 change: 0 additions & 1 deletion Library/Homebrew/cask/url.rbi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# typed: strict
# typed: false

class URL
include Kernel
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "keg"
Expand Down Expand Up @@ -31,7 +31,7 @@ def self.missing_deps(formulae, hide = nil)

def self.checks(type, fatal: true)
@checks ||= Checks.new
failed = false
failed = T.let(false, T::Boolean)
@checks.public_send(type).each do |check|
out = @checks.public_send(check)
next if out.nil?
Expand Down Expand Up @@ -64,6 +64,7 @@ def find_relative_paths(*relative_paths)
end
end

sig { params(list: T::Array[String], string: String).returns(String) }
def inject_file_list(list, string)
list.reduce(string.dup) { |acc, elem| acc << " #{elem}\n" }
.freeze
Expand Down Expand Up @@ -642,10 +643,11 @@ def check_deprecated_disabled
EOS
end

sig { returns(T.nilable(String)) }
def check_git_status
return unless Utils::Git.available?

message = nil
message = T.let(nil, T.nilable(String))

repos = {
"Homebrew/brew" => HOMEBREW_REPOSITORY,
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Homebrew
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/formula_assertions.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# typed: strict

module Homebrew::Assertions
include Kernel
end
10 changes: 5 additions & 5 deletions Library/Homebrew/keg_relocate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

class Keg
Expand Down Expand Up @@ -44,7 +44,7 @@ def replace_text(text)
key.is_a?(String) ? key.length : 999
end.reverse

any_changed = false
any_changed = T.let(nil, T.nilable(String))
sorted_keys.each do |key|
changed = text.gsub!(key, replacements[key])
any_changed ||= changed
Expand Down Expand Up @@ -144,7 +144,7 @@ def openjdk_dep_name_if_applicable
def replace_text_in_files(relocation, files: nil)
files ||= text_files | libtool_files

changed_files = []
changed_files = T.let([], Array)
files.map(&path.method(:join)).group_by { |f| f.stat.ino }.each_value do |first, *rest|
s = first.open("rb", &:read)

Expand Down Expand Up @@ -179,11 +179,11 @@ def relocate_build_prefix(keg, old_prefix, new_prefix)
binary = File.binread file
odebug "Replacing build prefix in: #{file}"
binary_strings = binary.split(/#{NULL_BYTE}/o, -1)
match_indices = binary_strings.each_index.select { |i| binary_strings[i].include?(old_prefix) }
match_indices = binary_strings.each_index.select { |i| binary_strings.fetch(i).include?(old_prefix) }

# Only perform substitution on strings which match prefix regex.
match_indices.each do |i|
s = binary_strings[i]
s = binary_strings.fetch(i)
binary_strings[i] = s.gsub(old_prefix, new_prefix)
.ljust(s.size, NULL_BYTE)
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Language
Expand Down
11 changes: 11 additions & 0 deletions Library/Homebrew/language/python.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# typed: strict

module Language::Python
module Shebang
include Kernel
end

module Virtualenv
requires_ancestor { Formula }
end
end
8 changes: 3 additions & 5 deletions Library/Homebrew/test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

raise "#{__FILE__} must not be loaded via `require`." if $PROGRAM_NAME != __FILE__
Expand Down Expand Up @@ -38,12 +38,10 @@
formula.extend(Debrew::Formula) if args.debug?

ENV.extend(Stdenv)
T.cast(ENV, Stdenv).setup_build_environment(formula: formula, testing_formula: true)
ENV.setup_build_environment(formula: formula, testing_formula: true)

# tests can also return false to indicate failure
run_test = proc do
raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false
end
run_test = proc { |_ = nil| raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false }
if args.debug? # --debug is interactive
run_test.call
else
Expand Down
8 changes: 3 additions & 5 deletions Library/Homebrew/unlink.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# typed: false
# typed: true
# frozen_string_literal: true

module Homebrew
# Provides helper methods for unlinking formulae and kegs with consistent output.
module Unlink
module_function

def unlink_versioned_formulae(formula, verbose: false)
def self.unlink_versioned_formulae(formula, verbose: false)
formula.versioned_formulae
.select(&:keg_only?)
.select(&:linked?)
Expand All @@ -18,7 +16,7 @@ def unlink_versioned_formulae(formula, verbose: false)
end
end

def unlink(keg, dry_run: false, verbose: false)
def self.unlink(keg, dry_run: false, verbose: false)
options = { dry_run: dry_run, verbose: verbose }

keg.lock do
Expand Down
11 changes: 5 additions & 6 deletions Library/Homebrew/utils/analytics.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "context"
Expand Down Expand Up @@ -42,7 +42,6 @@ def report_google(type, metadata = {})
--data av=#{HOMEBREW_VERSION}
]
metadata.each do |key, value|
next unless key
next unless value

key = ERB::Util.url_encode key
Expand Down Expand Up @@ -146,13 +145,13 @@ def report_influx_event(measurement, package_and_options, on_request: false)
report_influx(measurement, package_and_options, on_request, additional_tags_influx)
end

sig { params(exception: Exception).void }
sig { params(exception: BuildError).void }
def report_build_error(exception)
report_google_build_error(exception)
report_influx_error(exception)
end

sig { params(exception: Exception).void }
sig { params(exception: BuildError).void }
def report_google_build_error(exception)
return if not_this_run? || disabled?

Expand All @@ -165,10 +164,10 @@ def report_google_build_error(exception)
else
formula_full_name
end
report_google_event("BuildError", package_and_options)
report_google_event(:BuildError, package_and_options)
end

sig { params(exception: Exception).void }
sig { params(exception: BuildError).void }
def report_influx_error(exception)
return if not_this_run? || disabled?

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/utils/github/api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "tempfile"
Expand Down Expand Up @@ -214,15 +214,15 @@ def open_rest(url, data: nil, data_binary_path: nil, request_method: nil, scopes

headers_tmpfile = Tempfile.new("github_api_headers", HOMEBREW_TEMP)
begin
if data
if data_tmpfile
data_tmpfile.write data
data_tmpfile.close
args += ["--data", "@#{data_tmpfile.path}"]

args += ["--request", request_method.to_s] if request_method
end

args += ["--dump-header", headers_tmpfile.path]
args += ["--dump-header", T.must(headers_tmpfile.path)]

output, errors, status = curl_output("--location", url.to_s, *args, secrets: [token])
output, _, http_code = output.rpartition("\n")
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/utils/github/api.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# typed: strict

module GitHub::API
include Kernel
end
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/repology.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "utils/curl"
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/utils/repology.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# typed: strict

module Repology
include Kernel
requires_ancestor { Utils::Curl }
end

0 comments on commit 02fd042

Please sign in to comment.