Skip to content

Simplify code after end of brownout period #31

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

Merged
merged 4 commits into from
Dec 1, 2023
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
50 changes: 20 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,6 @@
- as a last resort, set the environment variable
`SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True` to avoid this error

# Brownout schedule

The following table shows the dates and time windows, where an exception will be
raised if you attempt to install the `sklearn` package from PyPI.

| Dates | Window(s) |
|---------------------------------------|--------------------------------|
| 2022 December 1st - 2023 January 31st | :00-:05 every hour |
| 2023 February 1st - March 31st | :00-:10 every hour |
| 2023 April 1st - May 31st | :00-:15 every hour |
| 2023 June 1st - July 31st | :00-:10 and :30-:40 every hour |
| 2023 August 1st - September 30th | :00-:15 and :30-:45 every hour |
| 2023 October 1st - November 30th | :00-:20 and :30-:50 every hour |
| 2023 December 1st onwards | always raise an exception |

# How to test whether a package will be affected by the `sklearn` deprecation

If you want to test whether a package has `sklearn` in its dependencies
independently of the brownout schedule, you can do:

```
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=False \
pip install package-to-test-goes-here
```

If you get an error that means that the package has `sklearn` in one of its
dependencies. It would be greatly appreciated if you track which package it is,
and if you report it to the appropriate project issue tracker to make them
aware of the `sklearn` deprecation.

# Reason for the deprecation

`sklearn` package on PyPI exists to prevent malicious actors from using the
Expand All @@ -67,3 +37,23 @@ implemented:
list` output, prompting questions like "why do I have scikit-learn 1.1.3 and
sklearn 0.0, and what does it even mean"?

# Historical brownout schedule (from 2022-12-01 to 2023-11-31)

Starting 2023 December 1st, trying to install the `sklearn` PyPI package raises
an error.

The table shows the historical brownout schedule that was used between 2022
December 1st and 2023 December 1st, in order to get people aware of the
deprecation and give them some time to adapt. During these dates and time
windows, an exception was raised if you attempted to install the `sklearn`
package from PyPI.

| Dates | Window(s) |
|---------------------------------------|--------------------------------|
| 2022 December 1st - 2023 January 31st | :00-:05 every hour |
| 2023 February 1st - March 31st | :00-:10 every hour |
| 2023 April 1st - May 31st | :00-:15 every hour |
| 2023 June 1st - July 31st | :00-:10 and :30-:40 every hour |
| 2023 August 1st - September 30th | :00-:15 and :30-:45 every hour |
| 2023 October 1st - November 30th | :00-:20 and :30-:50 every hour |
| 2023 December 1st onwards | always raise an exception |
63 changes: 7 additions & 56 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
import os
import sys
from datetime import datetime, MAXYEAR
from collections import namedtuple
import warnings

from setuptools import setup


with open("README.md", encoding='utf-8') as f:
with open("README.md", encoding="utf-8") as f:
LONG_DESCRIPTION = f.read()


def get_brownout_schedule():
all_start_dates = [datetime(2022, 12, 1)] + [
datetime(2023, 2 * i, 1) for i in range(1, 7)
]
date_in_the_far_future = datetime(MAXYEAR, 12, 31, 23, 59, 59)
all_end_dates = all_start_dates[1:] + [date_in_the_far_future]
all_check_functions = [
lambda dt: dt.minute < 5,
lambda dt: dt.minute < 10,
lambda dt: dt.minute < 15,
lambda dt: (dt.minute < 10) or (30 <= dt.minute < 40),
lambda dt: (dt.minute < 15) or (30 <= dt.minute < 45),
lambda dt: (dt.minute < 20) or (30 <= dt.minute < 50),
lambda dt: True,
]

CheckedDatetimeWindow = namedtuple(
"CheckedDatetimeWindow", "start_datetime end_datetime check_function"
)
brownout_schedule = [
CheckedDatetimeWindow(*each)
for each in zip(all_start_dates, all_end_dates, all_check_functions)
]

return brownout_schedule


def maybe_raise_error(checked_datetime):
def likely_error():
accept_deprecated_sklearn_package_install = os.environ.get(
"SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL", "use-brownout-schedule"
"SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL", "unset"
)
accept_deprecated_sklearn_package_install = (
accept_deprecated_sklearn_package_install.lower()
Expand All @@ -48,12 +20,6 @@ def maybe_raise_error(checked_datetime):
if accept_deprecated_sklearn_package_install == "true":
return

if accept_deprecated_sklearn_package_install == "false":
raise SystemExit(
"Refusing to install the deprecated sklearn package, "
"because SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=False is set"
)

error_message = "\n".join(
[
"The 'sklearn' PyPI package is deprecated, use 'scikit-learn'",
Expand All @@ -71,18 +37,10 @@ def maybe_raise_error(checked_datetime):
"",
"More information is available at",
"https://github.com/scikit-learn/sklearn-pypi-package",
"",
"If the previous advice does not cover your use case, feel free to report it at",
"https://github.com/scikit-learn/sklearn-pypi-package/issues/new",
]
)

brownout_schedule = get_brownout_schedule()
for start_date, end_date, check_function in brownout_schedule:
if (start_date <= checked_datetime < end_date) and check_function(
checked_datetime
):
raise SystemExit(error_message)
raise SystemExit(error_message)


if __name__ == "__main__":
Expand All @@ -91,19 +49,12 @@ def maybe_raise_error(checked_datetime):
sdist_mode = len(sys.argv) == 2 and sys.argv[1] == "sdist"

if not sdist_mode:
# environment variable for test purposes
datetime_str = os.getenv("SKLEARN_DEPRECATED_SKLEARN_CHECKED_DATETIME", None)
if datetime_str is None:
checked_datetime = datetime.now()
else:
checked_datetime = datetime.fromisoformat(datetime_str)

maybe_raise_error(checked_datetime)
likely_error()

setup(
description="deprecated sklearn package, use scikit-learn instead",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
name="sklearn",
version="0.0.post10",
version="0.0.post12",
)
93 changes: 0 additions & 93 deletions test_brownout.py

This file was deleted.