Skip to content

Commit 7ecb804

Browse files
author
OCCAM Coder
committed
Warn on Python 3.10 that 0.15 will not support it
- DeprecationWarning at import time below the interpreter floor of 0.15 - the floor as one constant, the check as a function taking the version - pyproject comment on the requires-python line to raise in 0.15 - test both branches of the check on any interpreter
1 parent 2b1692c commit 7ecb804

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎numpy_groupies/__init__.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import sys
4+
import warnings
35
from typing import TYPE_CHECKING, Any
46

57
from numpy_groupies.aggregate_purepy import aggregate as aggregate_py
@@ -90,3 +92,29 @@ def uaggregate(
9092
else:
9193
__version__ = get_version(root="..", relative_to=__file__)
9294
del get_version
95+
96+
97+
# the interpreter floor of the next minor release - 0.14 is the last version
98+
# that runs below it, 0.15 is the first one that will not
99+
_next_release_floor = (3, 11)
100+
101+
102+
def _warn_python_eol(version_info, floor=_next_release_floor):
103+
"""The end-of-support notice for an interpreter older than *floor*.
104+
105+
Takes the version as an argument rather than reading ``sys.version_info``
106+
itself so that both of its branches are testable on any interpreter, and so
107+
that dropping 3.10 for real is a change of the one constant above.
108+
"""
109+
if tuple(version_info[:2]) < tuple(floor):
110+
running = ".".join(str(part) for part in tuple(version_info[:3]))
111+
required = ".".join(str(part) for part in floor)
112+
warnings.warn(
113+
f"numpy-groupies will require Python {required} or newer from version 0.15, "
114+
f"and the 0.14 releases are the last to support this interpreter ({running}).",
115+
DeprecationWarning,
116+
stacklevel=2,
117+
)
118+
119+
120+
_warn_python_eol(sys.version_info)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""The end-of-support notice of ``numpy_groupies`` for old interpreters.
2+
3+
The package warns while it is imported, but the check takes the interpreter
4+
version as an argument, so both of its branches run on whatever interpreter the
5+
suite happens to use.
6+
"""
7+
8+
from warnings import catch_warnings, simplefilter
9+
10+
import pytest
11+
12+
from numpy_groupies import _warn_python_eol
13+
14+
15+
@pytest.mark.parametrize("version_info", [(3, 11), (3, 12), (3, 14), (3, 15)])
16+
def test_supported_interpreters_stay_quiet(version_info):
17+
# the filter turns every warning into an error, so getting out of the block
18+
# at all is the assertion
19+
with catch_warnings():
20+
simplefilter("error")
21+
_warn_python_eol(version_info)
22+
23+
24+
@pytest.mark.parametrize("version_info", [(3, 9), (3, 10), (3, 10, 12)])
25+
def test_the_dropped_interpreter_is_warned(version_info):
26+
with pytest.warns(DeprecationWarning) as record:
27+
_warn_python_eol(version_info)
28+
message = str(record[-1].message)
29+
assert "Python 3.11 or newer from version 0.15" in message
30+
assert ".".join(str(part) for part in version_info) in message

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ classifiers = [
3232
"Topic :: Software Development :: Libraries",
3333
]
3434
keywords = ["accumarray", "aggregate", "groupby", "grouping", "indexing"]
35-
requires-python = ">=3.10"
35+
requires-python = ">=3.10" # 0.15 will raise this to ">=3.11"
3636
dependencies = ["numpy"]
3737

3838
[project.optional-dependencies]

0 commit comments

Comments
 (0)