mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Enable types in extensions, etc.
This commit is contained in:
parent
931327df1f
commit
6397229f68
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
@ -60,10 +60,10 @@ module Homebrew
|
|||||||
|
|
||||||
odie "No #{name} #{pg_version_data}.* version installed!" unless old_bin
|
odie "No #{name} #{pg_version_data}.* version installed!" unless old_bin
|
||||||
|
|
||||||
server_stopped = false
|
server_stopped = T.let(false, T::Boolean)
|
||||||
moved_data = false
|
moved_data = T.let(false, T::Boolean)
|
||||||
initdb_run = false
|
initdb_run = T.let(false, T::Boolean)
|
||||||
upgraded = false
|
upgraded = T.let(false, T::Boolean)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# Following instructions from:
|
# Following instructions from:
|
||||||
@ -88,7 +88,7 @@ module Homebrew
|
|||||||
system "#{old_bin}/pg_ctl", "-w", "-D", datadir, "start"
|
system "#{old_bin}/pg_ctl", "-w", "-D", datadir, "start"
|
||||||
end
|
end
|
||||||
|
|
||||||
initdb_args = []
|
initdb_args = T.let([], T::Array[String])
|
||||||
locale_settings = %w[
|
locale_settings = %w[
|
||||||
lc_collate
|
lc_collate
|
||||||
lc_ctype
|
lc_ctype
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "delegate"
|
require "delegate"
|
||||||
@ -16,19 +16,19 @@ class Dependencies < SimpleDelegator
|
|||||||
alias eql? ==
|
alias eql? ==
|
||||||
|
|
||||||
def optional
|
def optional
|
||||||
select(&:optional?)
|
__getobj__.select(&:optional?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recommended
|
def recommended
|
||||||
select(&:recommended?)
|
__getobj__.select(&:recommended?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build
|
def build
|
||||||
select(&:build?)
|
__getobj__.select(&:build?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def required
|
def required
|
||||||
select(&:required?)
|
__getobj__.select(&:required?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def default
|
def default
|
||||||
@ -37,7 +37,7 @@ class Dependencies < SimpleDelegator
|
|||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def inspect
|
def inspect
|
||||||
"#<#{self.class.name}: #{to_a}>"
|
"#<#{self.class.name}: #{__getobj__}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ class Requirements < SimpleDelegator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def <<(other)
|
def <<(other)
|
||||||
if other.is_a?(Comparable)
|
if other.is_a?(Object) && other.is_a?(Comparable)
|
||||||
grep(other.class) do |req|
|
__getobj__.grep(other.class) do |req|
|
||||||
return self if req > other
|
return self if req > other
|
||||||
|
|
||||||
delete(req)
|
__getobj__.delete(req)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
super
|
super
|
||||||
@ -65,6 +65,6 @@ class Requirements < SimpleDelegator
|
|||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def inspect
|
def inspect
|
||||||
"#<#{self.class.name}: {#{to_a.join(", ")}}>"
|
"#<#{self.class.name}: {#{__getobj__.to_a.join(", ")}}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
class Dependencies < SimpleDelegator
|
class Dependencies < SimpleDelegator
|
||||||
include Kernel
|
include Kernel
|
||||||
|
# This is a workaround to enable `alias eql? ==`
|
||||||
|
# @see https://github.com/sorbet/sorbet/issues/2378#issuecomment-569474238
|
||||||
|
sig { params(arg0: BasicObject).returns(T::Boolean) }
|
||||||
|
def ==(arg0); end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Requirements < SimpleDelegator
|
class Requirements < SimpleDelegator
|
||||||
|
6
Library/Homebrew/extend/object.rbi
Normal file
6
Library/Homebrew/extend/object.rbi
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
class Object
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def present?; end
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "macho"
|
require "macho"
|
||||||
@ -114,7 +114,7 @@ module Hardware
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def intel_family
|
def intel_family(_family = nil, _cpu_model = nil)
|
||||||
case sysctl_int("hw.cpufamily")
|
case sysctl_int("hw.cpufamily")
|
||||||
when 0x73d67300 # Yonah: Core Solo/Duo
|
when 0x73d67300 # Yonah: Core Solo/Duo
|
||||||
:core
|
:core
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Keg
|
class Keg
|
||||||
@ -108,7 +108,7 @@ class Keg
|
|||||||
# Needed to make symlink permissions consistent on macOS and Linux for
|
# Needed to make symlink permissions consistent on macOS and Linux for
|
||||||
# reproducible bottles.
|
# reproducible bottles.
|
||||||
def consistent_reproducible_symlink_permissions!
|
def consistent_reproducible_symlink_permissions!
|
||||||
find do |file|
|
path.find do |file|
|
||||||
File.lchmod 0777, file if file.symlink?
|
File.lchmod 0777, file if file.symlink?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Predicable
|
module Predicable
|
||||||
|
5
Library/Homebrew/extend/predicable.rbi
Normal file
5
Library/Homebrew/extend/predicable.rbi
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
module Predicable
|
||||||
|
requires_ancestor { Class }
|
||||||
|
end
|
@ -1,16 +1,17 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module TimeRemaining
|
module TimeRemaining
|
||||||
refine Time do
|
refine Time do
|
||||||
def remaining
|
def remaining
|
||||||
|
T.bind(self, Time)
|
||||||
[0, self - Time.now].max
|
[0, self - Time.now].max
|
||||||
end
|
end
|
||||||
|
|
||||||
def remaining!
|
def remaining!
|
||||||
r = remaining
|
r = remaining
|
||||||
|
|
||||||
raise Timeout::Error if r <= 0
|
Kernel.raise Timeout::Error if r <= 0
|
||||||
|
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -161,7 +161,7 @@ module Homebrew
|
|||||||
# specifies the strategy and contains a `strategy` block
|
# specifies the strategy and contains a `strategy` block
|
||||||
next if (livecheck_strategy != strategy_symbol) || !block_provided
|
next if (livecheck_strategy != strategy_symbol) || !block_provided
|
||||||
elsif strategy.const_defined?(:PRIORITY) &&
|
elsif strategy.const_defined?(:PRIORITY) &&
|
||||||
!strategy::PRIORITY.positive? &&
|
!strategy.const_get(:PRIORITY).positive? &&
|
||||||
livecheck_strategy != strategy_symbol
|
livecheck_strategy != strategy_symbol
|
||||||
# Ignore strategies with a priority of 0 or lower, unless the
|
# Ignore strategies with a priority of 0 or lower, unless the
|
||||||
# strategy is specified in the `livecheck` block
|
# strategy is specified in the `livecheck` block
|
||||||
@ -174,7 +174,7 @@ module Homebrew
|
|||||||
# Sort usable strategies in descending order by priority, using the
|
# Sort usable strategies in descending order by priority, using the
|
||||||
# DEFAULT_PRIORITY when a strategy doesn't contain a PRIORITY constant
|
# DEFAULT_PRIORITY when a strategy doesn't contain a PRIORITY constant
|
||||||
usable_strategies.sort_by do |strategy|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ module Homebrew
|
|||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig { params(url: String, homebrew_curl: T::Boolean).returns(T::Hash[Symbol, T.untyped]) }
|
sig { params(url: String, homebrew_curl: T::Boolean).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
def self.page_content(url, homebrew_curl: false)
|
def self.page_content(url, homebrew_curl: false)
|
||||||
stderr = nil
|
stderr = T.let(nil, T.nilable(String))
|
||||||
[:default, :browser].each do |user_agent|
|
[:default, :browser].each do |user_agent|
|
||||||
stdout, stderr, status = curl_with_workarounds(
|
stdout, stderr, status = curl_with_workarounds(
|
||||||
*PAGE_CONTENT_CURL_ARGS, url,
|
*PAGE_CONTENT_CURL_ARGS, url,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Helper functions for updating PyPI resources.
|
# Helper functions for updating PyPI resources.
|
||||||
@ -7,8 +7,6 @@
|
|||||||
module PyPI
|
module PyPI
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
PYTHONHOSTED_URL_PREFIX = "https://files.pythonhosted.org/packages/"
|
PYTHONHOSTED_URL_PREFIX = "https://files.pythonhosted.org/packages/"
|
||||||
private_constant :PYTHONHOSTED_URL_PREFIX
|
private_constant :PYTHONHOSTED_URL_PREFIX
|
||||||
|
|
||||||
@ -35,13 +33,16 @@ module PyPI
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@name = package_string
|
if package_string.include? "=="
|
||||||
@name, @version = @name.split("==") if @name.include? "=="
|
@name, @version = package_string.split("==")
|
||||||
|
else
|
||||||
|
@name = package_string
|
||||||
|
end
|
||||||
|
|
||||||
return unless (match = @name.match(/^(.*?)\[(.+)\]$/))
|
return unless (match = T.must(@name).match(/^(.*?)\[(.+)\]$/))
|
||||||
|
|
||||||
@name = match[1]
|
@name = match[1]
|
||||||
@extras = match[2].split ","
|
@extras = T.must(match[2]).split ","
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get name, URL, SHA-256 checksum, and latest version for a given PyPI package.
|
# Get name, URL, SHA-256 checksum, and latest version for a given PyPI package.
|
||||||
@ -87,7 +88,7 @@ module PyPI
|
|||||||
|
|
||||||
sig { params(other: Package).returns(T::Boolean) }
|
sig { params(other: Package).returns(T::Boolean) }
|
||||||
def same_package?(other)
|
def same_package?(other)
|
||||||
@name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero?
|
T.must(@name.tr("_", "-").casecmp(other.name.tr("_", "-"))).zero?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Compare only names so we can use .include? and .uniq on a Package array
|
# Compare only names so we can use .include? and .uniq on a Package array
|
||||||
@ -109,7 +110,7 @@ module PyPI
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(url: String, version: T.any(String, Version)).returns(T.nilable(String)) }
|
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
|
package = Package.new url, is_url: true
|
||||||
|
|
||||||
return unless package.valid_pypi_package?
|
return unless package.valid_pypi_package?
|
||||||
@ -133,8 +134,9 @@ module PyPI
|
|||||||
ignore_non_pypi_packages: T.nilable(T::Boolean),
|
ignore_non_pypi_packages: T.nilable(T::Boolean),
|
||||||
).returns(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,
|
def self.update_python_resources!(formula, version: nil, package_name: nil, extra_packages: nil,
|
||||||
print_only: false, silent: false, ignore_non_pypi_packages: false)
|
exclude_packages: nil, print_only: false, silent: false,
|
||||||
|
ignore_non_pypi_packages: false)
|
||||||
|
|
||||||
auto_update_list = formula.tap&.pypi_formula_mappings
|
auto_update_list = formula.tap&.pypi_formula_mappings
|
||||||
if auto_update_list.present? && auto_update_list.key?(formula.full_name) &&
|
if auto_update_list.present? && auto_update_list.key?(formula.full_name) &&
|
||||||
@ -282,7 +284,7 @@ module PyPI
|
|||||||
true
|
true
|
||||||
end
|
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?
|
return [] if json_tree.blank?
|
||||||
|
|
||||||
json_tree.flat_map do |package_json|
|
json_tree.flat_map do |package_json|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user