New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable types in extensions, etc. #15124
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "delegate" | ||
|
@@ -16,19 +16,19 @@ def initialize(*args) | |
alias eql? == | ||
|
||
def optional | ||
select(&:optional?) | ||
__getobj__.select(&:optional?) | ||
end | ||
|
||
def recommended | ||
select(&:recommended?) | ||
__getobj__.select(&:recommended?) | ||
end | ||
|
||
def build | ||
select(&:build?) | ||
__getobj__.select(&:build?) | ||
end | ||
|
||
def required | ||
select(&:required?) | ||
__getobj__.select(&:required?) | ||
end | ||
|
||
def default | ||
|
@@ -37,7 +37,7 @@ def default | |
|
||
sig { returns(String) } | ||
def inspect | ||
"#<#{self.class.name}: #{to_a}>" | ||
"#<#{self.class.name}: #{__getobj__}>" | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This uses the explicit delegator method throughout. Since the delegated object is an array, we don't need to invoke |
||
end | ||
|
||
|
@@ -52,11 +52,11 @@ def initialize(*args) | |
end | ||
|
||
def <<(other) | ||
if other.is_a?(Comparable) | ||
grep(other.class) do |req| | ||
if other.is_a?(Object) && other.is_a?(Comparable) | ||
__getobj__.grep(other.class) do |req| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to type guard |
||
return self if req > other | ||
|
||
delete(req) | ||
__getobj__.delete(req) | ||
end | ||
end | ||
super | ||
|
@@ -65,6 +65,6 @@ def <<(other) | |
|
||
sig { returns(String) } | ||
def inspect | ||
"#<#{self.class.name}: {#{to_a.join(", ")}}>" | ||
"#<#{self.class.name}: {#{__getobj__.to_a.join(", ")}}>" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# typed: strict | ||
|
||
class Object | ||
sig { returns(T::Boolean) } | ||
def present?; end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary for the return type of |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Homebrew | ||
extend T::Sig | ||
|
||
module_function | ||
|
||
class << self | ||
alias generic_git_tags git_tags | ||
end | ||
|
||
def git_tags | ||
tags = generic_git_tags | ||
tags = Utils.popen_read("git tag --list | sort -rV") if tags.blank? | ||
tags | ||
def git_tags | ||
tags = generic_git_tags | ||
tags = Utils.popen_read("git tag --list | sort -rV") if tags.blank? | ||
tags | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "macho" | ||
|
@@ -114,7 +114,7 @@ def arm_family | |
end | ||
end | ||
|
||
def intel_family | ||
def intel_family(_family = nil, _cpu_model = nil) | ||
case sysctl_int("hw.cpufamily") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to match the arity of the same method in Library/Homebrew/extend/os/linux/hardware/cpu.rb |
||
when 0x73d67300 # Yonah: Core Solo/Duo | ||
:core | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
class Keg | ||
|
@@ -108,7 +108,7 @@ def prepare_debug_symbols | |
# Needed to make symlink permissions consistent on macOS and Linux for | ||
# reproducible bottles. | ||
def consistent_reproducible_symlink_permissions! | ||
find do |file| | ||
path.find do |file| | ||
File.lchmod 0777, file if file.symlink? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Predicable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# typed: strict | ||
|
||
module Predicable | ||
requires_ancestor { Class } | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Homebrew | ||
|
@@ -161,7 +161,7 @@ def from_url(url, livecheck_strategy: nil, url_provided: false, regex_provided: | |
# specifies the strategy and contains a `strategy` block | ||
next if (livecheck_strategy != strategy_symbol) || !block_provided | ||
elsif strategy.const_defined?(:PRIORITY) && | ||
!strategy::PRIORITY.positive? && | ||
!strategy.const_get(:PRIORITY).positive? && | ||
livecheck_strategy != strategy_symbol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorbet doesn't support dynamic constant references using the prior format, but i believe this is equivalent |
||
# Ignore strategies with a priority of 0 or lower, unless the | ||
# strategy is specified in the `livecheck` block | ||
|
@@ -174,7 +174,7 @@ def from_url(url, livecheck_strategy: nil, url_provided: false, regex_provided: | |
# Sort usable strategies in descending order by priority, using the | ||
# DEFAULT_PRIORITY when a strategy doesn't contain a PRIORITY constant | ||
usable_strategies.sort_by do |strategy| | ||
(strategy.const_defined?(:PRIORITY) ? -strategy::PRIORITY : -DEFAULT_PRIORITY) | ||
(strategy.const_defined?(:PRIORITY) ? -strategy.const_get(:PRIORITY) : -DEFAULT_PRIORITY) | ||
end | ||
end | ||
|
||
|
@@ -216,7 +216,7 @@ def self.page_headers(url, homebrew_curl: false) | |
# @return [Hash] | ||
sig { params(url: String, homebrew_curl: T::Boolean).returns(T::Hash[Symbol, T.untyped]) } | ||
def self.page_content(url, homebrew_curl: false) | ||
stderr = nil | ||
stderr = T.let(nil, T.nilable(String)) | ||
[:default, :browser].each do |user_agent| | ||
stdout, stderr, status = curl_with_workarounds( | ||
*PAGE_CONTENT_CURL_ARGS, url, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# typed: false | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
# Helper functions for updating PyPI resources. | ||
|
@@ -7,8 +7,6 @@ | |
module PyPI | ||
extend T::Sig | ||
|
||
module_function | ||
|
||
PYTHONHOSTED_URL_PREFIX = "https://files.pythonhosted.org/packages/" | ||
private_constant :PYTHONHOSTED_URL_PREFIX | ||
|
||
|
@@ -35,13 +33,16 @@ def initialize(package_string, is_url: false) | |
return | ||
end | ||
|
||
@name = package_string | ||
@name, @version = @name.split("==") if @name.include? "==" | ||
if package_string.include? "==" | ||
@name, @version = package_string.split("==") | ||
else | ||
@name = package_string | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a slight rearrangement to reduce the number of |
||
return unless (match = @name.match(/^(.*?)\[(.+)\]$/)) | ||
return unless (match = T.must(@name).match(/^(.*?)\[(.+)\]$/)) | ||
|
||
@name = match[1] | ||
@extras = match[2].split "," | ||
@extras = T.must(match[2]).split "," | ||
end | ||
|
||
# Get name, URL, SHA-256 checksum, and latest version for a given PyPI package. | ||
|
@@ -87,7 +88,7 @@ def to_s | |
|
||
sig { params(other: Package).returns(T::Boolean) } | ||
def same_package?(other) | ||
@name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero? | ||
T.must(@name.tr("_", "-").casecmp(other.name.tr("_", "-"))).zero? | ||
end | ||
|
||
# Compare only names so we can use .include? and .uniq on a Package array | ||
|
@@ -109,7 +110,7 @@ def <=>(other) | |
end | ||
|
||
sig { params(url: String, version: T.any(String, Version)).returns(T.nilable(String)) } | ||
def update_pypi_url(url, version) | ||
def self.update_pypi_url(url, version) | ||
package = Package.new url, is_url: true | ||
|
||
return unless package.valid_pypi_package? | ||
|
@@ -133,8 +134,9 @@ def update_pypi_url(url, version) | |
ignore_non_pypi_packages: T.nilable(T::Boolean), | ||
).returns(T.nilable(T::Boolean)) | ||
} | ||
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) | ||
def self.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) | ||
|
||
auto_update_list = formula.tap&.pypi_formula_mappings | ||
if auto_update_list.present? && auto_update_list.key?(formula.full_name) && | ||
|
@@ -282,7 +284,7 @@ def update_python_resources!(formula, version: nil, package_name: nil, extra_pac | |
true | ||
end | ||
|
||
def json_to_packages(json_tree, main_package, exclude_packages) | ||
def self.json_to_packages(json_tree, main_package, exclude_packages) | ||
return [] if json_tree.blank? | ||
|
||
json_tree.flat_map do |package_json| | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I almost wonder if we want to implement our own helper for this. I find it gross how verbose and repetitive this is. Something like
SORBET_FALSE
might be nicer.