Skip to content

Commit 347fb84

Browse files
authored
chore!: raise minimum Python version to 3.11 (#1022)
1 parent ac4be41 commit 347fb84

11 files changed

Lines changed: 32 additions & 781 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
fail-fast: false
5454
matrix:
5555
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
56-
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
56+
python-version: ['3.11', '3.12', '3.13', '3.14']
5757

5858
steps:
5959
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -93,7 +93,7 @@ jobs:
9393
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
9494

9595
- name: Run tests with lowest resolution
96-
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
96+
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
9797
run: just test-lowest
9898

9999
- name: Run tests with highest resolution

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
77

88
## Unreleased
99

10+
- [#1022](https://github.com/pytask-dev/pytask/pull/1022) raises the minimum supported
11+
Python version to 3.11.
1012
- [#935](https://github.com/pytask-dev/pytask/pull/935) detects when a cached task
1113
module comes from a different path and raises
1214
`ImportPathMismatchError`, while recognizing cached bytecode modules by their source

‎docs/source/tutorials/set_up_a_project.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ to manage dependencies and project metadata.
8787
[project]
8888
name = "my_project"
8989
version = "0.1.0"
90-
requires-python = ">=3.10"
90+
requires-python = ">=3.11"
9191
dependencies = ["pytask"]
9292

9393
[build-system]
@@ -109,7 +109,7 @@ to manage dependencies and project metadata.
109109
[project]
110110
name = "my_project"
111111
version = "0.1.0"
112-
requires-python = ">=3.10"
112+
requires-python = ">=3.11"
113113
channels = ["conda-forge"] # (1)!
114114
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
115115

@@ -119,7 +119,7 @@ to manage dependencies and project metadata.
119119

120120
[dependencies]
121121
pytask = "*"
122-
python = ">=3.10"
122+
python = ">=3.11"
123123

124124
[tool.pytask.ini_options]
125125
paths = ["src/my_project"] # (2)!

‎justfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ docs-serve *FLAGS:
4242

4343
# Run tests with lowest dependency resolution (like CI)
4444
test-lowest:
45-
uv run --python 3.10 --group test --resolution lowest-direct pytest --nbmake
45+
uv run --python 3.11 --group test --resolution lowest-direct pytest --nbmake
4646

4747
# Run tests with highest dependency resolution (like CI)
4848
test-highest:

‎pyproject.toml‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "pytask"
33
description = "pytask is a workflow management system that facilitates reproducible data analyses."
4-
requires-python = ">=3.10"
4+
requires-python = ">=3.11"
55
classifiers = [
66
"Development Status :: 4 - Beta",
77
"Environment :: Console",
@@ -11,7 +11,6 @@ classifiers = [
1111
"Operating System :: Microsoft :: Windows",
1212
"Operating System :: POSIX",
1313
"Programming Language :: Python :: 3 :: Only",
14-
"Programming Language :: Python :: 3.10",
1514
"Programming Language :: Python :: 3.11",
1615
"Programming Language :: Python :: 3.12",
1716
"Programming Language :: Python :: 3.13",
@@ -30,8 +29,7 @@ dependencies = [
3029
"rich>=13.8.0",
3130
"sqlalchemy>=2.0.31",
3231
"msgspec[toml]>=0.18.6",
33-
'tomli>=1; python_version < "3.11"',
34-
'typing-extensions>=4.8.0; python_version < "3.11"',
32+
"typing-extensions>=4.8.0",
3533
"universal-pathlib>=0.2.2",
3634
]
3735

‎src/_pytask/_hashlib.py‎

Lines changed: 1 addition & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import hashlib
44
import os
55
import sys
6-
from contextlib import suppress
6+
from hashlib import file_digest
77
from pathlib import Path
88
from typing import Any
99

@@ -13,212 +13,6 @@
1313
_WINDOWS_DRIVE_PREFIX_LENGTH = 3
1414

1515

16-
if sys.version_info >= (3, 11): # pragma: no cover
17-
from hashlib import file_digest
18-
else: # pragma: no cover
19-
# This tuple and __get_builtin_constructor() must be modified if a new
20-
# always available algorithm is added.
21-
__always_supported = (
22-
"md5",
23-
"sha1",
24-
"sha224",
25-
"sha256",
26-
"sha384",
27-
"sha512",
28-
"blake2b",
29-
"blake2s",
30-
"sha3_224",
31-
"sha3_256",
32-
"sha3_384",
33-
"sha3_512",
34-
"shake_128",
35-
"shake_256",
36-
)
37-
38-
algorithms_guaranteed = set(__always_supported)
39-
algorithms_available = set(__always_supported)
40-
41-
__all__ = __always_supported + (
42-
"new",
43-
"algorithms_guaranteed",
44-
"algorithms_available",
45-
"file_digest",
46-
)
47-
48-
__builtin_constructor_cache = {}
49-
50-
# Prefer our blake2 implementation
51-
# OpenSSL 1.1.0 comes with a limited implementation of blake2b/s. The OpenSSL
52-
# implementations neither support keyed blake2 (blake2 MAC) nor advanced
53-
# features like salt, personalization, or tree hashing. OpenSSL hash-only
54-
# variants are available as 'blake2b512' and 'blake2s256', though.
55-
__block_openssl_constructor = {
56-
"blake2b",
57-
"blake2s",
58-
}
59-
60-
def __get_builtin_constructor(name):
61-
cache = __builtin_constructor_cache
62-
constructor = cache.get(name)
63-
if constructor is not None:
64-
return constructor
65-
66-
with suppress(ImportError):
67-
if name in {"SHA1", "sha1"}:
68-
import _sha1
69-
70-
cache["SHA1"] = cache["sha1"] = _sha1.sha1
71-
elif name in {"MD5", "md5"}:
72-
import _md5
73-
74-
cache["MD5"] = cache["md5"] = _md5.md5
75-
elif name in {"SHA256", "sha256", "SHA224", "sha224"}:
76-
try:
77-
import _sha2
78-
except ImportError:
79-
import _sha256 as _sha2
80-
cache["SHA224"] = cache["sha224"] = _sha2.sha224
81-
cache["SHA256"] = cache["sha256"] = _sha2.sha256
82-
elif name in {"SHA512", "sha512", "SHA384", "sha384"}:
83-
try:
84-
import _sha2
85-
except ImportError:
86-
import _sha256 as _sha2
87-
cache["SHA384"] = cache["sha384"] = _sha2.sha384
88-
cache["SHA512"] = cache["sha512"] = _sha2.sha512
89-
elif name in {"blake2b", "blake2s"}:
90-
import _blake2
91-
92-
cache["blake2b"] = _blake2.blake2b
93-
cache["blake2s"] = _blake2.blake2s
94-
elif name in {"sha3_224", "sha3_256", "sha3_384", "sha3_512"}:
95-
import _sha3
96-
97-
cache["sha3_224"] = _sha3.sha3_224
98-
cache["sha3_256"] = _sha3.sha3_256
99-
cache["sha3_384"] = _sha3.sha3_384
100-
cache["sha3_512"] = _sha3.sha3_512
101-
elif name in {"shake_128", "shake_256"}:
102-
import _sha3
103-
104-
cache["shake_128"] = _sha3.shake_128
105-
cache["shake_256"] = _sha3.shake_256
106-
107-
constructor = cache.get(name)
108-
if constructor is not None:
109-
return constructor
110-
111-
raise ValueError("unsupported hash type " + name)
112-
113-
def __get_openssl_constructor(name):
114-
if name in __block_openssl_constructor:
115-
# Prefer our builtin blake2 implementation.
116-
return __get_builtin_constructor(name)
117-
try:
118-
# MD5, SHA1, and SHA2 are in all supported OpenSSL versions
119-
# SHA3/shake are available in OpenSSL 1.1.1+
120-
f = getattr(_hashlib, "openssl_" + name)
121-
# Allow the C module to raise ValueError. The function will be
122-
# defined but the hash not actually available. Don't fall back to
123-
# builtin if the current security policy blocks a digest, bpo#40695.
124-
f(usedforsecurity=False)
125-
# Use the C function directly (very fast)
126-
return f
127-
except (AttributeError, ValueError):
128-
return __get_builtin_constructor(name)
129-
130-
def __py_new(name, data=b"", **kwargs):
131-
"""new(name, data=b'', **kwargs) - Return a new hashing object using the
132-
named algorithm; optionally initialized with data (which must be
133-
a bytes-like object).
134-
"""
135-
return __get_builtin_constructor(name)(data, **kwargs)
136-
137-
def __hash_new(name, data=b"", **kwargs):
138-
"""new(name, data=b'') - Return a new hashing object using the named algorithm;
139-
optionally initialized with data (which must be a bytes-like object).
140-
"""
141-
if name in __block_openssl_constructor:
142-
# Prefer our builtin blake2 implementation.
143-
return __get_builtin_constructor(name)(data, **kwargs)
144-
try:
145-
return _hashlib.new(name, data, **kwargs)
146-
except ValueError:
147-
# If the _hashlib module (OpenSSL) doesn't support the named
148-
# hash, try using our builtin implementations.
149-
# This allows for SHA224/256 and SHA384/512 support even though
150-
# the OpenSSL library prior to 0.9.8 doesn't provide them.
151-
return __get_builtin_constructor(name)(data)
152-
153-
try:
154-
import _hashlib
155-
156-
new = __hash_new
157-
__get_hash = __get_openssl_constructor
158-
algorithms_available = algorithms_available.union(
159-
_hashlib.openssl_md_meth_names
160-
)
161-
except ImportError:
162-
_hashlib = None
163-
new = __py_new
164-
__get_hash = __get_builtin_constructor
165-
166-
with suppress(ImportError):
167-
# OpenSSL's PKCS5_PBKDF2_HMAC requires OpenSSL 1.0+ with HMAC and SHA
168-
from _hashlib import pbkdf2_hmac
169-
170-
__all__ += ("pbkdf2_hmac",)
171-
172-
with suppress(ImportError):
173-
# OpenSSL's scrypt requires OpenSSL 1.1+
174-
from _hashlib import scrypt
175-
176-
def file_digest(fileobj, digest, /, *, _bufsize=2**18):
177-
"""Hash the contents of a file-like object. Returns a digest object.
178-
179-
*fileobj* must be a file-like object opened for reading in binary mode.
180-
It accepts file objects from open(), io.BytesIO(), and SocketIO objects.
181-
The function may bypass Python's I/O and use the file descriptor *fileno*
182-
directly.
183-
184-
*digest* must either be a hash algorithm name as a *str*, a hash
185-
constructor, or a callable that returns a hash object.
186-
"""
187-
# On Linux we could use AF_ALG sockets and sendfile() to archive zero-copy
188-
# hashing with hardware acceleration.
189-
if isinstance(digest, str):
190-
digestobj = new(digest)
191-
else:
192-
digestobj = digest()
193-
194-
if hasattr(fileobj, "getbuffer"):
195-
# io.BytesIO object, use zero-copy buffer
196-
digestobj.update(fileobj.getbuffer())
197-
return digestobj
198-
199-
# Only binary files implement readinto().
200-
if not (
201-
hasattr(fileobj, "readinto")
202-
and hasattr(fileobj, "readable")
203-
and fileobj.readable()
204-
):
205-
raise ValueError(
206-
f"'{fileobj!r}' is not a file-like object in binary reading mode."
207-
)
208-
209-
# binary file, socket.SocketIO object
210-
# Note: socket I/O uses different syscalls than file I/O.
211-
buf = bytearray(_bufsize) # Reusable buffer to reduce allocations.
212-
view = memoryview(buf)
213-
while True:
214-
size = fileobj.readinto(buf)
215-
if size == 0:
216-
break # EOF
217-
digestobj.update(view[:size])
218-
219-
return digestobj
220-
221-
22216
def hash_value(value: Any) -> int | str:
22317
"""Hash values.
22418

‎src/_pytask/capture.py‎

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
from typing import BinaryIO
3939
from typing import Generic
4040
from typing import NamedTuple
41+
from typing import Self
4142
from typing import TextIO
4243
from typing import cast
4344
from typing import final
4445

4546
import click
46-
from typing_extensions import Self
4747

4848
from _pytask.capture_utils import CaptureMethod
4949
from _pytask.capture_utils import ShowCapture
@@ -606,26 +606,12 @@ def writeorg(self, data: str) -> None:
606606
# MultiCapture
607607

608608

609-
# Generic NamedTuple only supported since Python 3.11.
610-
if sys.version_info >= (3, 11) or TYPE_CHECKING:
609+
@final
610+
class CaptureResult(NamedTuple, Generic[AnyStr]):
611+
"""A class for capture results."""
611612

612-
@final
613-
class CaptureResult(NamedTuple, Generic[AnyStr]):
614-
"""A class for capture results."""
615-
616-
out: AnyStr
617-
err: AnyStr
618-
619-
else:
620-
import collections
621-
622-
class CaptureResult(
623-
collections.namedtuple("CaptureResult", ["out", "err"]), # noqa: PYI024
624-
Generic[AnyStr],
625-
):
626-
"""A class for capture results."""
627-
628-
__slots__ = ()
613+
out: AnyStr
614+
err: AnyStr
629615

630616

631617
class MultiCapture(Generic[AnyStr]):

‎src/_pytask/config_utils.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import enum
66
import os
7-
import sys
7+
import tomllib
88
from pathlib import Path
99
from typing import TYPE_CHECKING
1010
from typing import Any
@@ -18,12 +18,6 @@
1818
if TYPE_CHECKING:
1919
from collections.abc import Sequence
2020

21-
if sys.version_info >= (3, 11): # pragma: no cover
22-
import tomllib
23-
else: # pragma: no cover
24-
import tomli as tomllib # ty: ignore[unresolved-import]
25-
26-
2721
__all__ = [
2822
"find_project_root_and_config",
2923
"normalize_programmatic_config",

‎tests/test_execute.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,6 @@ def task2() -> None:
670670
assert session2.exit_code == ExitCode.OK
671671

672672

673-
@pytest.mark.xfail(
674-
sys.platform == "linux" and sys.version_info[:2] == (3, 10), reason="flakey"
675-
)
676673
def test_pytask_on_a_module_that_uses_the_functional_api(tmp_path):
677674
source = """
678675
from pytask import task, ExitCode, build

‎tests/test_typing.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pytask import is_task_function
77

88
if TYPE_CHECKING:
9-
from typing_extensions import assert_type
9+
from typing import assert_type
1010

1111
from pytask import CollectionMetadata
1212
from pytask import task

0 commit comments

Comments
 (0)