Skip to content
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

livecheck: remove module_function #18130

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def audit_livecheck_version
if referenced_cask
skip_info = Homebrew::Livecheck::SkipConditions.referenced_skip_information(
referenced_cask,
Homebrew::Livecheck.cask_name(cask),
Homebrew::Livecheck.package_or_resource_name(cask),
)
end

Expand Down
49 changes: 25 additions & 24 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
# command. These methods print the requested livecheck information
# for formulae.
module Livecheck
module_function

GITEA_INSTANCES = T.let(%w[
codeberg.org
gitea.com
opendev.org
tildegit.org
].freeze, T::Array[String])
private_constant :GITEA_INSTANCES

GOGS_INSTANCES = T.let(%w[
lolg.it
].freeze, T::Array[String])
private_constant :GOGS_INSTANCES

STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = T.let([
:extract_plist,
Expand All @@ -36,6 +36,7 @@
:xml,
:yaml,
].freeze, T::Array[Symbol])
private_constant :STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL

UNSTABLE_VERSION_KEYWORDS = T.let(%w[
alpha
Expand All @@ -47,9 +48,10 @@
preview
rc
].freeze, T::Array[String])
private_constant :UNSTABLE_VERSION_KEYWORDS

sig { returns(T::Hash[T::Class[T.anything], String]) }
def livecheck_strategy_names
private_class_method def self.livecheck_strategy_names
return T.must(@livecheck_strategy_names) if defined?(@livecheck_strategy_names)

# Cache demodulized strategy names, to avoid repeating this work
Expand All @@ -66,7 +68,7 @@
# Uses `formulae_and_casks_to_check` to identify taps in use other than
# homebrew/core and homebrew/cask and loads strategies from them.
sig { params(formulae_and_casks_to_check: T::Array[T.any(Formula, Cask::Cask)]).void }
def load_other_tap_strategies(formulae_and_casks_to_check)
def self.load_other_tap_strategies(formulae_and_casks_to_check)
other_taps = {}
formulae_and_casks_to_check.each do |formula_or_cask|
next if formula_or_cask.tap.blank?
Expand Down Expand Up @@ -95,7 +97,7 @@
debug: T::Boolean,
).returns(T.nilable(T::Array[T.untyped]))
}
def resolve_livecheck_reference(
def self.resolve_livecheck_reference(
formula_or_cask,
first_formula_or_cask = formula_or_cask,
references = [],
Expand Down Expand Up @@ -170,7 +172,7 @@
verbose: T::Boolean,
).void
}
def run_checks(
def self.run_checks(
formulae_and_casks_to_check,
full_name: false, handle_name_conflict: false, check_resources: false, json: false, newer_only: false,
extract_plist: false, debug: false, quiet: false, verbose: false
Expand Down Expand Up @@ -432,7 +434,7 @@
end

sig { params(package_or_resource: T.any(Formula, Cask::Cask, Resource), full_name: T::Boolean).returns(String) }
def package_or_resource_name(package_or_resource, full_name: false)
def self.package_or_resource_name(package_or_resource, full_name: false)
case package_or_resource
when Formula
formula_name(package_or_resource, full_name:)
Expand All @@ -448,14 +450,14 @@
# Returns the fully-qualified name of a cask if the `full_name` argument is
# provided; returns the name otherwise.
sig { params(cask: Cask::Cask, full_name: T::Boolean).returns(String) }
def cask_name(cask, full_name: false)
private_class_method def self.cask_name(cask, full_name: false)
full_name ? cask.full_name : cask.token
end

# Returns the fully-qualified name of a formula if the `full_name` argument is
# provided; returns the name otherwise.
sig { params(formula: Formula, full_name: T::Boolean).returns(String) }
def formula_name(formula, full_name: false)
private_class_method def self.formula_name(formula, full_name: false)
full_name ? formula.full_name : formula.name
end

Expand All @@ -468,7 +470,7 @@
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def status_hash(package_or_resource, status_str, messages = nil, full_name: false, verbose: false)
def self.status_hash(package_or_resource, status_str, messages = nil, full_name: false, verbose: false)
formula = package_or_resource if package_or_resource.is_a?(Formula)
cask = package_or_resource if package_or_resource.is_a?(Cask::Cask)
resource = package_or_resource if package_or_resource.is_a?(Resource)
Expand All @@ -494,7 +496,7 @@

# Formats and prints the livecheck result for a formula/cask/resource.
sig { params(info: T::Hash[Symbol, T.untyped], verbose: T::Boolean, ambiguous_cask: T::Boolean).void }
def print_latest_version(info, verbose: false, ambiguous_cask: false)
private_class_method def self.print_latest_version(info, verbose: false, ambiguous_cask: false)
package_or_resource_s = info[:resource].present? ? " " : ""
package_or_resource_s += "#{Tty.blue}#{info[:formula] || info[:cask] || info[:resource]}#{Tty.reset}"
package_or_resource_s += " (cask)" if ambiguous_cask
Expand All @@ -517,7 +519,7 @@

# Prints the livecheck result for the resources of a given Formula.
sig { params(info: T::Array[T::Hash[Symbol, T.untyped]], verbose: T::Boolean).void }
def print_resources_info(info, verbose: false)
private_class_method def self.print_resources_info(info, verbose: false)
info.each do |r_info|
if r_info[:status] && r_info[:messages]
SkipConditions.print_skip_information(r_info)
Expand All @@ -533,7 +535,7 @@
package_or_resource: T.any(Formula, Cask::Cask, Resource),
).returns(T.nilable(String))
}
def livecheck_url_to_string(livecheck_url, package_or_resource)
def self.livecheck_url_to_string(livecheck_url, package_or_resource)
case livecheck_url
when String
livecheck_url
Expand All @@ -548,7 +550,7 @@

# Returns an Array containing the formula/cask/resource URLs that can be used by livecheck.
sig { params(package_or_resource: T.any(Formula, Cask::Cask, Resource)).returns(T::Array[String]) }
def checkable_urls(package_or_resource)
def self.checkable_urls(package_or_resource)
urls = []

case package_or_resource
Expand All @@ -573,7 +575,7 @@

# Preprocesses and returns the URL used by livecheck.
sig { params(url: String).returns(String) }
def preprocess_url(url)
def self.preprocess_url(url)
begin
uri = Addressable::URI.parse url
rescue Addressable::URI::InvalidURIError
Expand Down Expand Up @@ -617,7 +619,7 @@
# contains a `stable`/`url` or `head` URL `using: :homebrew_curl` that
# shares the same root domain.
sig { params(formula_or_cask: T.any(Formula, Cask::Cask), url: String).returns(T::Boolean) }
def use_homebrew_curl?(formula_or_cask, url)
def self.use_homebrew_curl?(formula_or_cask, url)
url_root_domain = Addressable::URI.parse(url)&.domain
return false if url_root_domain.blank?

Expand Down Expand Up @@ -655,7 +657,7 @@
debug: T::Boolean,
).returns(T.nilable(T::Hash[Symbol, T.untyped]))
}
def latest_version(
def self.latest_version(
formula_or_cask,
referenced_formula_or_cask: nil,
livecheck_references: [],
Expand All @@ -674,13 +676,12 @@
livecheck_strategy_block = livecheck.strategy_block || referenced_livecheck&.strategy_block
livecheck_throttle = livecheck.throttle || referenced_livecheck&.throttle

livecheck_url_string = livecheck_url_to_string(
livecheck_url,
referenced_formula_or_cask || formula_or_cask,
)
referenced_package = referenced_formula_or_cask || formula_or_cask

Check warning on line 679 in Library/Homebrew/livecheck/livecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/livecheck.rb#L679

Added line #L679 was not covered by tests

livecheck_url_string = livecheck_url_to_string(livecheck_url, referenced_package) if livecheck_url

urls = [livecheck_url_string] if livecheck_url_string
urls ||= checkable_urls(referenced_formula_or_cask || formula_or_cask)
urls ||= checkable_urls(referenced_package)

Check warning on line 684 in Library/Homebrew/livecheck/livecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/livecheck.rb#L684

Added line #L684 was not covered by tests

if debug
if formula
Expand Down Expand Up @@ -751,7 +752,7 @@

homebrew_curl = case strategy_name
when "PageMatch", "HeaderMatch"
use_homebrew_curl?((referenced_formula_or_cask || formula_or_cask), url)
use_homebrew_curl?(referenced_package, url)
end
puts "Homebrew curl?: Yes" if debug && homebrew_curl.present?

Expand Down Expand Up @@ -888,7 +889,7 @@
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def resource_version(
def self.resource_version(
resource,
formula_latest,
json: false,
Expand Down
11 changes: 0 additions & 11 deletions Library/Homebrew/livecheck/livecheck.rbi

This file was deleted.

42 changes: 27 additions & 15 deletions Library/Homebrew/livecheck/skip_conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ module Livecheck
# The `Livecheck::SkipConditions` module primarily contains methods that
# check for various formula/cask/resource conditions where a check should be skipped.
module SkipConditions
module_function

sig {
params(
package_or_resource: T.any(Formula, Cask::Cask, Resource),
Expand All @@ -16,7 +14,12 @@ module SkipConditions
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def package_or_resource_skip(package_or_resource, livecheckable, full_name: false, verbose: false)
private_class_method def self.package_or_resource_skip(
package_or_resource,
livecheckable,
full_name: false,
verbose: false
)
formula = package_or_resource if package_or_resource.is_a?(Formula)

if (stable_url = formula&.stable&.url)
Expand Down Expand Up @@ -53,7 +56,7 @@ def package_or_resource_skip(package_or_resource, livecheckable, full_name: fals
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def formula_head_only(formula, _livecheckable, full_name: false, verbose: false)
private_class_method def self.formula_head_only(formula, _livecheckable, full_name: false, verbose: false)
return {} if !formula.head_only? || formula.any_version_installed?

Livecheck.status_hash(
Expand All @@ -73,7 +76,7 @@ def formula_head_only(formula, _livecheckable, full_name: false, verbose: false)
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def formula_deprecated(formula, livecheckable, full_name: false, verbose: false)
private_class_method def self.formula_deprecated(formula, livecheckable, full_name: false, verbose: false)
return {} if !formula.deprecated? || livecheckable

Livecheck.status_hash(formula, "deprecated", full_name:, verbose:)
Expand All @@ -87,7 +90,7 @@ def formula_deprecated(formula, livecheckable, full_name: false, verbose: false)
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def formula_disabled(formula, livecheckable, full_name: false, verbose: false)
private_class_method def self.formula_disabled(formula, livecheckable, full_name: false, verbose: false)
return {} if !formula.disabled? || livecheckable

Livecheck.status_hash(formula, "disabled", full_name:, verbose:)
Expand All @@ -101,7 +104,7 @@ def formula_disabled(formula, livecheckable, full_name: false, verbose: false)
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def formula_versioned(formula, livecheckable, full_name: false, verbose: false)
private_class_method def self.formula_versioned(formula, livecheckable, full_name: false, verbose: false)
return {} if !formula.versioned_formula? || livecheckable

Livecheck.status_hash(formula, "versioned", full_name:, verbose:)
Expand All @@ -115,7 +118,7 @@ def formula_versioned(formula, livecheckable, full_name: false, verbose: false)
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def cask_deprecated(cask, livecheckable, full_name: false, verbose: false)
private_class_method def self.cask_deprecated(cask, livecheckable, full_name: false, verbose: false)
return {} if !cask.deprecated? || livecheckable

Livecheck.status_hash(cask, "deprecated", full_name:, verbose:)
Expand All @@ -129,7 +132,7 @@ def cask_deprecated(cask, livecheckable, full_name: false, verbose: false)
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def cask_disabled(cask, livecheckable, full_name: false, verbose: false)
private_class_method def self.cask_disabled(cask, livecheckable, full_name: false, verbose: false)
return {} if !cask.disabled? || livecheckable

Livecheck.status_hash(cask, "disabled", full_name:, verbose:)
Expand All @@ -144,7 +147,13 @@ def cask_disabled(cask, livecheckable, full_name: false, verbose: false)
extract_plist: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def cask_extract_plist(cask, _livecheckable, full_name: false, verbose: false, extract_plist: false)
private_class_method def self.cask_extract_plist(
cask,
_livecheckable,
full_name: false,
verbose: false,
extract_plist: false
)
return {} if extract_plist || cask.livecheck.strategy != :extract_plist

Livecheck.status_hash(
Expand All @@ -164,7 +173,7 @@ def cask_extract_plist(cask, _livecheckable, full_name: false, verbose: false, e
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def cask_version_latest(cask, livecheckable, full_name: false, verbose: false)
private_class_method def self.cask_version_latest(cask, livecheckable, full_name: false, verbose: false)
return {} if !(cask.present? && cask.version&.latest?) || livecheckable

Livecheck.status_hash(cask, "latest", full_name:, verbose:)
Expand All @@ -178,7 +187,7 @@ def cask_version_latest(cask, livecheckable, full_name: false, verbose: false)
verbose: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
private_class_method def self.cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
return {} if !(cask.present? && cask.url&.unversioned?) || livecheckable

Livecheck.status_hash(cask, "unversioned", full_name:, verbose:)
Expand All @@ -192,6 +201,7 @@ def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
:formula_disabled,
:formula_versioned,
].freeze, T::Array[Symbol])
private_constant :FORMULA_CHECKS

# Skip conditions for casks.
CASK_CHECKS = T.let([
Expand All @@ -202,11 +212,13 @@ def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
:cask_version_latest,
:cask_url_unversioned,
].freeze, T::Array[Symbol])
private_constant :CASK_CHECKS

# Skip conditions for resources.
RESOURCE_CHECKS = T.let([
:package_or_resource_skip,
].freeze, T::Array[Symbol])
private_constant :RESOURCE_CHECKS

# If a formula/cask/resource should be skipped, we return a hash from
# `Livecheck#status_hash`, which contains a `status` type and sometimes
Expand All @@ -219,7 +231,7 @@ def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
extract_plist: T::Boolean,
).returns(T::Hash[Symbol, T.untyped])
}
def skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true)
def self.skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true)
livecheckable = package_or_resource.livecheckable?

checks = case package_or_resource
Expand Down Expand Up @@ -257,7 +269,7 @@ def skip_information(package_or_resource, full_name: false, verbose: false, extr
extract_plist: T::Boolean,
).returns(T.nilable(T::Hash[Symbol, T.untyped]))
}
def referenced_skip_information(
def self.referenced_skip_information(
livecheck_package_or_resource,
original_package_or_resource_name,
full_name: false,
Expand Down Expand Up @@ -299,7 +311,7 @@ def referenced_skip_information(

# Prints default livecheck output in relation to skip conditions.
sig { params(skip_hash: T::Hash[Symbol, T.untyped]).void }
def print_skip_information(skip_hash)
def self.print_skip_information(skip_hash)
return unless skip_hash.is_a?(Hash)

name = if skip_hash[:formula].is_a?(String)
Expand Down
Loading