Skip to content

Commit

Permalink
info: change disabled dates
Browse files Browse the repository at this point in the history
- Remove useless REMOVE_DISABLED_BEFORE
- Add deprecated_period attribute to be able to finetune the disable date
- This new attribute is set to :long by default to be backward compatible
- This will allow to write an automated script that will disable the formula after the right amount of time

This also fixes the issue that the disabled date displayed in brew info right now
is way to far in the future (1 year) instead of 6 months (either it's a bug or the code does not aligne with the doc)
  • Loading branch information
iMichka committed Oct 12, 2024
1 parent 587949b commit 1345056
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Library/Homebrew/cask/cask.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module Cask

def deprecation_reason; end

def deprecation_period; end

def disabled?; end

def disable_date; end
Expand Down
15 changes: 12 additions & 3 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class DSL
:deprecated?,
:deprecation_date,
:deprecation_reason,
:deprecation_period,
:disable!,
:disabled?,
:disable_date,
Expand All @@ -105,7 +106,13 @@ class DSL
extend Attrable
include OnSystem::MacOSOnly

attr_reader :cask, :token, :deprecation_date, :deprecation_reason, :disable_date, :disable_reason,
attr_reader :cask,
:token,
:deprecation_date,
:deprecation_reason,
:disable_date,
:disable_reason,
:deprecation_period,
:on_system_block_min_os

attr_predicate :deprecated?, :disabled?, :livecheckable?, :on_system_blocks_exist?, :depends_on_set_in_block?
Expand Down Expand Up @@ -442,10 +449,11 @@ def livecheck(&block)
# NOTE: A warning will be shown when trying to install this cask.
#
# @api public
def deprecate!(date:, because:)
def deprecate!(date:, because:, deprecation_period: :long)
@deprecation_date = Date.parse(date)
return if @deprecation_date > Date.today

@deprecation_period = deprecation_period
@deprecation_reason = because
@deprecated = true
end
Expand All @@ -455,11 +463,12 @@ def deprecate!(date:, because:)
# NOTE: An error will be thrown when trying to install this cask.
#
# @api public
def disable!(date:, because:)
def disable!(date:, because:, deprecation_period:)
@disable_date = Date.parse(date)

if @disable_date > Date.today
@deprecation_reason = because
@deprecation_period = deprecation_period
@deprecated = true
return
end
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/deprecate_disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ module DeprecateDisable
unsigned: "is unsigned or does not meet signature requirements",
}.freeze

DEPRECATE_TIME_WINDOW_MONTHS = {
short: 1,
long: 6,
}.freeze

# One year when << or >> to Date.today.
REMOVE_DISABLED_TIME_WINDOW = 12
REMOVE_DISABLED_BEFORE = (Date.today << REMOVE_DISABLED_TIME_WINDOW).freeze

def type(formula_or_cask)
return :deprecated if formula_or_cask.deprecated?
Expand Down Expand Up @@ -65,7 +69,7 @@ def message(formula_or_cask)

disable_date = formula_or_cask.disable_date
if !disable_date && formula_or_cask.deprecation_date
disable_date = formula_or_cask.deprecation_date >> REMOVE_DISABLED_TIME_WINDOW
disable_date = formula_or_cask.deprecation_date >> DEPRECATE_TIME_WINDOW_MONTHS[formula_or_cask.deprecation_period]
end
if disable_date
message += if disable_date < Date.today
Expand Down
17 changes: 16 additions & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,13 @@ def link_overwrite?(path)
# @see .deprecate!
delegate deprecation_reason: :"self.class"

# The time before the {Formula} becomes disabled
# Returns `nil` if no date is specified.
# @!method deprecation_period
# @return [String, Symbol]
# @see .deprecate!
delegate deprecation_period: :"self.class"

# Whether this {Formula} is disabled (i.e. cannot be installed).
# Defaults to false.
# @!method disabled?
Expand Down Expand Up @@ -4225,10 +4232,11 @@ def pour_bottle?(only_if: nil, &block)
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae
# @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS
# @api public
def deprecate!(date:, because:)
def deprecate!(date:, because:, deprecation_period: :long)
@deprecation_date = Date.parse(date)
return if @deprecation_date > Date.today

@deprecation_period = deprecation_period
@deprecation_reason = because
@deprecated = true
end
Expand All @@ -4255,6 +4263,13 @@ def deprecated?
# @see .deprecate!
attr_reader :deprecation_reason

# The time before the {Formula} becomes disabled.
#
# @return [nil] if no reason was provided or the formula is not deprecated.
# @return [String, Symbol]
# @see .deprecate!
attr_reader :deprecation_period

# Disables a {Formula} (on the given date) so it cannot be
# installed. If the date has not yet passed the formula
# will be deprecated instead of disabled.
Expand Down
9 changes: 5 additions & 4 deletions docs/Deprecating-Disabling-and-Removing-Formulae.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ Formulae with dependents should not be deprecated until or when all dependents a
To deprecate a formula, add a `deprecate!` call. This call should include a deprecation date (in the ISO 8601 format) and a deprecation reason:

```ruby
deprecate! date: "YYYY-MM-DD", because: :reason
deprecate! date: "YYYY-MM-DD", because: :reason, deprecation_period: :short
```

The `date` parameter should be set to the date that the deprecation period should begin, which is usually today's date. If the `date` parameter is set to a date in the future, the formula will not become deprecated until that date. This can be useful if the upstream developers have indicated a date when the project or version will stop being supported. Do not backdate the `date` parameter as it causes confusion for users and maintainers.

The `because` parameter can be a preset reason (using a symbol) or a custom reason. See the [Deprecate and Disable Reasons](#deprecate-and-disable-reasons) section below for more details about the `because` parameter.

The `deprecation_period:` can be either :short or :long (1 or 6 months). After this period a formula should be disabled.

## Disabling

If a user attempts to install a disabled formula, they will be shown an error message and the install will fail.
Expand All @@ -49,10 +51,9 @@ The most common reasons for disabling a formula are:
- it has been deprecated for a long time
- the project has no license

Popular formulae (e.g. have more than 1000 [analytics installs in the last 90 days](https://formulae.brew.sh/analytics/install/90d/)) should not be disabled without a deprecation period of at least six months even if e.g. they do not build from source and do not have a license.
Popular formulae (e.g. have more than 1000 [analytics installs in the last 90 days](https://formulae.brew.sh/analytics/install/90d/)) should not be disabled without a deprecation period of six months even if e.g. they do not build from source and do not have a license.

Unpopular formulae (e.g. have fewer than 1000 [analytics installs in the last 90 days](https://formulae.brew.sh/analytics/install/90d/)) can be disabled immediately for any of the reasons above e.g. they cannot be built from source on any supported macOS version or Linux.
They can be manually removed three months after their disable date.
Unpopular formulae (e.g. have fewer than 1000 [analytics installs in the last 90 days](https://formulae.brew.sh/analytics/install/90d/)) can be disabled after one month for any of the reasons above e.g. they cannot be built from source on any supported macOS version or Linux.

To disable a formula, add a `disable!` call. This call should include a deprecation date in the ISO 8601 format and a deprecation reason:

Expand Down

0 comments on commit 1345056

Please sign in to comment.