Skip to content

Commit

Permalink
Merge pull request Homebrew#16320 from dduugg/use-native-except
Browse files Browse the repository at this point in the history
Use native Hash#except, remove ActiveSupport 🐵-patch
  • Loading branch information
MikeMcQuaid authored Dec 12, 2023
2 parents 23f6ad6 + 0ce8438 commit 7755004
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 79 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/file/atomic.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_transform_values.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/except.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/keys.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/slice.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/dev-cmd/update-maintainers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
require "utils/github"
require "manpages"

require "active_support/core_ext/hash/slice"

module Homebrew
module_function

Expand Down Expand Up @@ -39,7 +37,7 @@ def update_maintainers

sentences = {}
members.each do |group, hash|
hash.slice!(*public_members)
hash.replace(hash.slice(*public_members))
hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" }
sentences[group] = hash.values.sort.to_sentence
end
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
require "active_support/core_ext/enumerable"
require "active_support/core_ext/file/atomic"
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/hash/except"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/string/exclude"
require "active_support/core_ext/string/filters"
Expand Down
55 changes: 33 additions & 22 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "livecheck/constants"
Expand All @@ -18,18 +18,18 @@ module Homebrew
module Livecheck
module_function

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

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

STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = [
STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = T.let([
:extract_plist,
:github_latest,
:header_match,
Expand All @@ -38,9 +38,9 @@ module Livecheck
:sparkle,
:xml,
:yaml,
].freeze
].freeze, T::Array[Symbol])

UNSTABLE_VERSION_KEYWORDS = %w[
UNSTABLE_VERSION_KEYWORDS = T.let(%w[
alpha
beta
bpo
Expand All @@ -49,21 +49,21 @@ module Livecheck
prerelease
preview
rc
].freeze
].freeze, T::Array[String])

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

# Cache demodulized strategy names, to avoid repeating this work
@livecheck_strategy_names = {}
@livecheck_strategy_names = T.let({}, T.nilable(T::Hash[Class, String]))
Strategy.constants.sort.each do |const_symbol|
constant = Strategy.const_get(const_symbol)
next unless constant.is_a?(Class)

@livecheck_strategy_names[constant] = Utils.demodulize(T.must(constant.name))
T.must(@livecheck_strategy_names)[constant] = Utils.demodulize(T.must(constant.name))
end
@livecheck_strategy_names.freeze
T.must(@livecheck_strategy_names).freeze
end

# Uses `formulae_and_casks_to_check` to identify taps in use other than
Expand All @@ -83,7 +83,7 @@ def load_other_tap_strategies(formulae_and_casks_to_check)

other_taps.each_value do |tap|
tap_strategy_path = "#{tap.path}/livecheck/strategy"
Dir["#{tap_strategy_path}/*.rb"].sort.each(&method(:require)) if Dir.exist?(tap_strategy_path)
Dir["#{tap_strategy_path}/*.rb"].sort.each { require(_1) } if Dir.exist?(tap_strategy_path)
end
end

Expand Down Expand Up @@ -321,7 +321,12 @@ def run_checks(
latest_info = status_hash(formula_or_cask, "error", [no_versions_msg], full_name: use_full_name,
verbose: verbose)
if check_for_resources
resource_version_info.map! { |r| r.except!(:meta) } unless verbose
unless verbose
resource_version_info.map! do |info|
info.delete(:meta)
info
end
end
latest_info[:resources] = resource_version_info
end

Expand Down Expand Up @@ -368,8 +373,13 @@ def run_checks(

if json
progress&.increment
info.except!(:meta) unless verbose
resource_version_info.map! { |r| r.except!(:meta) } if check_for_resources && !verbose
info.delete(:meta) unless verbose
if check_for_resources && !verbose
resource_version_info.map! do |info|
info.delete(:meta)
info
end
end
next info
end
puts if debug
Expand Down Expand Up @@ -446,7 +456,7 @@ def formula_name(formula, full_name: false)
messages: T.nilable(T::Array[String]),
full_name: T::Boolean,
verbose: T::Boolean,
).returns(Hash)
).returns(T::Hash[Symbol, T.untyped])
}
def 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)
Expand All @@ -473,7 +483,7 @@ def status_hash(package_or_resource, status_str, messages = nil, full_name: fals
end

# Formats and prints the livecheck result for a formula/cask/resource.
sig { params(info: Hash, verbose: T::Boolean, ambiguous_cask: T::Boolean).void }
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)
package_or_resource_s = info[:resource].present? ? " " : ""
package_or_resource_s += "#{Tty.blue}#{info[:formula] || info[:cask] || info[:resource]}#{Tty.reset}"
Expand All @@ -496,7 +506,7 @@ def print_latest_version(info, verbose: false, ambiguous_cask: false)
end

# Prints the livecheck result for the resources of a given Formula.
sig { params(info: T::Array[Hash], verbose: T::Boolean).void }
sig { params(info: T::Array[T::Hash[Symbol, T.untyped]], verbose: T::Boolean).void }
def print_resources_info(info, verbose: false)
info.each do |r_info|
if r_info[:status] && r_info[:messages]
Expand Down Expand Up @@ -633,7 +643,7 @@ def use_homebrew_curl?(formula_or_cask, url)
full_name: T::Boolean,
verbose: T::Boolean,
debug: T::Boolean,
).returns(T.nilable(Hash))
).returns(T.nilable(T::Hash[Symbol, T.untyped]))
}
def latest_version(
formula_or_cask,
Expand Down Expand Up @@ -834,6 +844,7 @@ def latest_version(
end
nil
end

# Identifies the latest version of a resource and returns a Hash containing the
# version information. Returns nil if a latest version couldn't be found.
sig {
Expand All @@ -844,7 +855,7 @@ def latest_version(
debug: T::Boolean,
quiet: T::Boolean,
verbose: T::Boolean,
).returns(Hash)
).returns(T::Hash[Symbol, T.untyped])
}
def resource_version(
resource,
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 7755004

Please sign in to comment.