From a10b635fe90d2eca6e7c1c94f705e2b33050ba5c Mon Sep 17 00:00:00 2001 From: botantony Date: Thu, 24 Apr 2025 16:13:29 +0200 Subject: [PATCH] `no_autobump!`: suggestions from contributors and docs Co-authored-by: Mike McQuaid Signed-off-by: botantony --- Library/Homebrew/cask/dsl.rb | 16 +++++++++++----- Library/Homebrew/formula.rb | 32 +++++++++++++++++++++++++++----- Library/Homebrew/formulary.rb | 4 ++-- Library/Homebrew/tap.rb | 17 ++++++++++++----- Library/Homebrew/tap_auditor.rb | 1 + 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index a1b09c9678..5363e58237 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -105,7 +105,6 @@ module Cask :livecheckable?, # TODO: remove once `#livecheckable?` is removed :no_autobump!, :autobump?, - :no_autobump_defined?, :no_autobump_message, :on_system_blocks_exist?, :on_system_block_min_os, @@ -547,8 +546,15 @@ module Cask @livecheck_defined == true end + # Excludes the cask from autobump list. + # + # TODO: limit this method to the official taps only (f.e. raise + # an error if `!tap.official?`) + # + # @api public + sig { params(because: T.any(String, Symbol)).void } def no_autobump!(because:) - if !because.is_a?(String) && (!because.is_a?(Symbol) || !NO_AUTOBUMP_REASONS_LIST.key?(because)) + if because.is_a?(Symbol) && !NO_AUTOBUMP_REASONS_LIST.key?(because) raise ArgumentError, "'because' argument should use valid symbol or a string!" end @@ -557,16 +563,16 @@ module Cask end @no_autobump_defined = true - # TODO: add symbol support when a list of common reasons is ready. - # At this moment just convert symbols to a string - @no_autobump_message = because.to_s + @no_autobump_message = because @autobump = false end + # Is the cask in autobump list? def autobump? @autobump == true end + # Is no_autobump! method defined? def no_autobump_defined? @no_autobump_defined == true end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 150489f0b4..b2f7e9bc13 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -214,7 +214,11 @@ class Formula sig { returns(T::Boolean) } attr_accessor :follow_installed_alias - sig { returns(T.nilable(String)) } + # Message that explains why the formula was excluded from autobump list. + # Returns `nil` if no message is specified. + # + # @see .no_autobump! + sig { returns(T.nilable(T.any(String, Symbol))) } attr_reader :no_autobump_message alias follow_installed_alias? follow_installed_alias @@ -247,7 +251,7 @@ class Formula @stable = T.let(nil, T.nilable(SoftwareSpec)) @autobump = T.let(true, T::Boolean) - @no_autobump_message = T.let(nil, T.nilable(String)) + @no_autobump_message = T.let(nil, T.nilable(T.any(String, Symbol))) @force_bottle = T.let(force_bottle, T::Boolean) @@ -481,10 +485,19 @@ class Formula # @see .livecheckable? delegate livecheckable?: :"self.class" + # Exclude the formula from autobump list. + # @!method no_autobump! + # @see .no_autobump! delegate no_autobump!: :"self.class" + # Is the formula in autobump list? + # @!method autobump? + # @see .autobump? delegate autobump?: :"self.class" + # Is no_autobump! method defined? + # @!method no_autobump_defined? + # @see .no_autobump_defined? delegate no_autobump_defined?: :"self.class" delegate no_autobump_message: :"self.class" @@ -4202,27 +4215,36 @@ class Formula # Method that excludes the formula from the autobump list. # + # TODO: limit this method to the official taps only (f.e. raise + # an error if `!tap.official?`) + # # @api public - sig { params(because: T.any(String, Symbol)).returns(T.untyped) } + sig { params(because: T.any(String, Symbol)).void } def no_autobump!(because:) if because.is_a?(Symbol) && !NO_AUTOBUMP_REASONS_LIST.key?(because) raise ArgumentError, "'because' argument should use valid symbol or a string!" end @no_autobump_defined = T.let(true, T.nilable(T::Boolean)) - @no_autobump_message = T.let(because.to_s, T.nilable(String)) + @no_autobump_message = T.let(because, T.nilable(T.any(String, Symbol))) @autobump = T.let(false, T.nilable(T::Boolean)) end + # Is the formula in autobump list? sig { returns(T::Boolean) } def autobump? @autobump != false # @autobump may be `nil` end + # Is no_autobump! method defined? sig { returns(T::Boolean) } def no_autobump_defined? = @no_autobump_defined == true - sig { returns(T.nilable(String)) } + # Message that explains why the formula was excluded from autobump list. + # Returns `nil` if no message is specified. + # + # @see .no_autobump! + sig { returns(T.nilable(T.any(String, Symbol))) } attr_reader :no_autobump_message # Service can be used to define services. diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e948a26800..2f191fb787 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -291,8 +291,8 @@ module Formulary end end - if (no_autobump_msg = json_formula["no_autobump_msg"]) - no_autobump! because: no_autobump_msg + if (because = json_formula["no_autobump_msg"]) + no_autobump!(because:) end bottles_stable = json_formula["bottle"]["stable"].presence diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 6bf7930732..bc1cc8ad5e 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -20,6 +20,8 @@ class Tap private_constant :HOMEBREW_TAP_FORMULA_RENAMES_FILE HOMEBREW_TAP_MIGRATIONS_FILE = "tap_migrations.json" private_constant :HOMEBREW_TAP_MIGRATIONS_FILE + HOMEBREW_TAP_AUTOBUMP_FILE = ".github/autobump.txt" + private_constant :HOMEBREW_TAP_AUTOBUMP_FILE HOMEBREW_TAP_PYPI_FORMULA_MAPPINGS_FILE = "pypi_formula_mappings.json" private_constant :HOMEBREW_TAP_PYPI_FORMULA_MAPPINGS_FILE HOMEBREW_TAP_SYNCED_VERSIONS_FORMULAE_FILE = "synced_versions_formulae.json" @@ -983,11 +985,6 @@ class Tap # Array with autobump names sig { returns(T::Array[String]) } def autobump - unless official? - @autobump ||= [] - return @autobump - end - @autobump ||= if core_cask_tap? Homebrew::API::Cask.all_casks.select do |_, cask| cask["autobump"] == true && !cask["skip_livecheck"] @@ -997,6 +994,16 @@ class Tap formula["autobump"] == true && !formula["skip_livecheck"] end.keys end + + if @autobump.empty? + @autobump = if (autobump_file = path/HOMEBREW_TAP_AUTOBUMP_FILE).file? + autobump_file.readlines(chomp: true) + else + [] + end + end + + @autobump end # Whether this {Tap} allows running bump commands on the given {Formula} or {Cask}. diff --git a/Library/Homebrew/tap_auditor.rb b/Library/Homebrew/tap_auditor.rb index b270eedcdd..a6fa8b307a 100644 --- a/Library/Homebrew/tap_auditor.rb +++ b/Library/Homebrew/tap_auditor.rb @@ -54,6 +54,7 @@ module Homebrew check_formula_list_directory "audit_exceptions", @tap_audit_exceptions check_formula_list_directory "style_exceptions", @tap_style_exceptions check_formula_list "pypi_formula_mappings", @tap_pypi_formula_mappings + check_formula_list ".github/autobump.txt", @tap_autobump check_formula_list "formula_renames", @formula_renames.values end