Skip to content

Commit c1dfe75

Browse files
authored
fix: add support for python 3.14 (#533)
1 parent 5bac7bc commit c1dfe75

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
py313-ansible218
4141
py314-devel
4242
py310-macos:tox -e py310
43-
py314-macos:tox -e py314
43+
py314-devel-macos:tox -e py314-devel
4444
smoke
4545
skip_explode: "1"
4646
secrets: inherit

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ classifiers = [
2121
"Programming Language :: Python :: 3.11",
2222
"Programming Language :: Python :: 3.12",
2323
"Programming Language :: Python :: 3.13",
24+
"Programming Language :: Python :: 3.14",
2425
"Topic :: Software Development :: Bug Tracking",
2526
"Topic :: Software Development :: Quality Assurance",
2627
"Topic :: Software Development :: Testing",
@@ -479,6 +480,7 @@ env_list = [
479480
"py312-ansible218",
480481
"py313-ansible218",
481482
"py313-devel",
483+
"py314-devel",
482484
]
483485
requires = [
484486
"setuptools>=65.3",
@@ -590,6 +592,11 @@ deps = ["ansible-core @ git+https://github.com/ansible/ansible.git@devel"]
590592
description = "ansible-core devel py{py_dot_ver}"
591593
runner = "uv-venv-runner"
592594

595+
[tool.tox.env.py314-devel]
596+
deps = ["ansible-core @ git+https://github.com/ansible/ansible.git@devel"]
597+
description = "ansible-core devel py{py_dot_ver}"
598+
runner = "uv-venv-runner"
599+
593600
[tool.tox.env.rpm]
594601
commands = [["sh", "-c", "packit build in-mock --root=fedora-40-$(arch)"]]
595602
deps = ["packitos"]

src/ansible_compat/prerun.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
"""Utilities for configuring ansible runtime environment."""
1+
"""Utilities for configuring ansible runtime environment.
2+
3+
No import of ansible-core must happen within this file!
4+
"""
25

36
import hashlib
47
import os
8+
import sys
59
import tempfile
610
import warnings
11+
from importlib.metadata import version
712
from pathlib import Path
813

14+
from packaging.version import Version
15+
16+
# This module is early loaded by tools like ansible-lint and we want to fail
17+
# fast even for `ansible-lint --version` if the setup is known as broken.
18+
if sys.version_info >= (3, 14):
19+
core_version = Version(version("ansible-core"))
20+
if core_version < Version("2.20.0dev0"): # pragma: no cover
21+
msg = f"Python 3.14 requires ansible-core version >= 2.20.0, and we found {core_version}."
22+
raise RuntimeError(msg)
23+
924

1025
def is_writable(path: Path) -> bool:
1126
"""Check if path is writable, creating if necessary.
@@ -43,7 +58,7 @@ def get_cache_dir(project_dir: Path, *, isolated: bool = True) -> Path:
4358
if is_writable(path):
4459
cache_dir = path
4560
else:
46-
msg = f"Found VIRTUAL_ENV={os.environ['VIRTUAL_ENV']} but we cannot use it for caching as it is not writable."
61+
msg = f"Found VIRTUAL_ENV={os.environ['VIRTUAL_ENV']} but we cannot use it for caching as it is not writable." # pylint: disable=W0621
4762
warnings.warn(
4863
message=msg,
4964
stacklevel=2,

test/test_runtime_scan_path.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import subprocess
6+
import sys
67
import textwrap
78
from pathlib import Path
89

@@ -20,6 +21,10 @@
2021
V2_COLLECTION_FULL_NAME = f"{V2_COLLECTION_NAMESPACE}.{V2_COLLECTION_NAME}"
2122

2223

24+
@pytest.mark.skipif(
25+
sys.version_info >= (3, 14),
26+
reason="Python 3.14 requires unreleased ansible-core which will fail this test.",
27+
)
2328
@pytest.mark.parametrize(
2429
("scan", "raises_not_found"),
2530
(

0 commit comments

Comments
 (0)