Skip to content

Commit 325dbc2

Browse files
authored
chore(nox): make Python 3.12 the minimum and stop linting on 3.10 (#14784)
Problem: the shared nox config and the GitHub lint job still targeted Python 3.10, which reached end of life in Oct 2026. Most samples only tested 3.10 and 3.14, and linting used each sample's oldest tested version. So contributors working on 3.12 were asked for a 3.10 interpreter and saw py-3.12 skipped. Solution: - noxfile-template.py: ALL_VERSIONS is now 3.12-3.15 and the default tests 3.12 + 3.14. Lint always runs on 3.12. A new OPT_IN_VERSIONS / "opt_in_versions" setting keeps 3.15 off unless a sample asks for it, because existing configs only list the versions they skip. - noxfile_config.py: the default tests 3.12 + 3.14 and documents how to opt in to 3.13 and 3.15. - .github: the lint job and noxfile-lint.py use 3.12. Also fixes two flake8 issues and black formatting that were already in the file. Old version strings such as "3.8" in per-sample configs are now ignored. Per-sample configs still need updating to test 3.12; that's planned for a follow-up PR. Signed-off-by: Jennifer Davis <sigje@google.com>
1 parent be26e32 commit 325dbc2

4 files changed

Lines changed: 42 additions & 15 deletions

File tree

‎.github/scripts/noxfile-lint.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import nox
2020

2121
# Use a stable Python version for running the style utilities
22-
LINTING_VERSION = "3.10"
22+
LINTING_VERSION = "3.12"
2323

2424
# Error out if the runner is missing the target python interpreter
2525
nox.options.error_on_missing_interpreters = True
@@ -33,11 +33,15 @@ def _determine_local_import_names(start_dir: str) -> list[str]:
3333
basename
3434
for basename, extension in file_ext_pairs
3535
if extension == ".py"
36-
or (os.path.isdir(os.path.join(start_dir, basename)) and basename != "__pycache__")
36+
or (
37+
os.path.isdir(os.path.join(start_dir, basename))
38+
and basename != "__pycache__"
39+
)
3740
]
3841
except Exception:
3942
return []
4043

44+
4145
# Linting with flake8.
4246
#
4347
# We ignore the following rules:
@@ -88,7 +92,7 @@ def lint(session: nox.sessions.Session) -> None:
8892
def blacken(session: nox.sessions.Session) -> None:
8993
"""Runs black code formatting checks. Honors incremental PR file arguments."""
9094
session.install("black")
91-
95+
9296
# If explicit target files are passed via posargs, target ONLY those files.
9397
if session.posargs:
9498
targets = session.posargs

‎.github/workflows/lint.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup Python
2828
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
2929
with:
30-
python-version: '3.10'
30+
python-version: '3.12'
3131

3232
- name: Install nox
3333
run: |

‎noxfile-template.py‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import nox
2525

26-
2726
# WARNING - WARNING - WARNING - WARNING - WARNING
2827
# WARNING - WARNING - WARNING - WARNING - WARNING
2928
# BE CAREFUL WHEN EDITING THIS FILE!
@@ -40,7 +39,12 @@
4039

4140
TEST_CONFIG = {
4241
# You can opt out from the test for specific Python versions.
43-
"ignored_versions": ["2.7", "3.7", "3.8", "3.10", "3.11", "3.12"],
42+
# By default, samples are tested on the minimum (3.12) and the
43+
# latest stable (3.14) supported Python versions.
44+
"ignored_versions": ["3.13"],
45+
# Newly released Python versions are only tested when a sample
46+
# explicitly opts in, for example: "opt_in_versions": ["3.15"].
47+
"opt_in_versions": [],
4448
# Old samples are opted out of enforcing Python type hints
4549
# All new samples should feature them
4650
"enforce_type_hints": False,
@@ -87,20 +91,33 @@ def get_pytest_env_vars() -> dict[str, str]:
8791
return ret
8892

8993

90-
# All versions used to tested samples.
91-
ALL_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
94+
# All Python versions that samples can be tested on. 3.12 is the minimum
95+
# supported version.
96+
ALL_VERSIONS = ["3.12", "3.13", "3.14", "3.15"]
97+
98+
# Newly released versions that are only tested when a sample lists them
99+
# in "opt_in_versions". Existing configs only list the versions they
100+
# ignore, so without this a new version would be enabled for all of them.
101+
OPT_IN_VERSIONS = ["3.15"]
92102

93-
# Any default versions that should be ignored.
103+
# Any default versions that should be ignored. Versions that are no
104+
# longer in ALL_VERSIONS (for example "3.8") are safely ignored.
94105
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]
95106

96-
TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
107+
TESTED_VERSIONS = sorted(
108+
[
109+
v
110+
for v in ALL_VERSIONS
111+
if v not in IGNORED_VERSIONS
112+
and (v not in OPT_IN_VERSIONS or v in TEST_CONFIG.get("opt_in_versions", []))
113+
]
114+
)
97115

98116
INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False))
99117

100-
# Use the oldest tested Python version for linting (defaults to 3.10)
101-
LINTING_VERSION = "3.10"
102-
if len(TESTED_VERSIONS) > 0:
103-
LINTING_VERSION = TESTED_VERSIONS[0]
118+
# Run style checks on the minimum supported Python version, regardless of
119+
# which versions a sample is tested on, so contributors only need 3.12.
120+
LINTING_VERSION = "3.12"
104121

105122
# Error if a python version is missing
106123
nox.options.error_on_missing_interpreters = True

‎noxfile_config.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222

2323
TEST_CONFIG_OVERRIDE = {
2424
# You can opt out from the test for specific Python versions.
25-
"ignored_versions": ["3.8", "3.9", "3.11", "3.12", "3.13"],
25+
# By default, samples are tested on the minimum (3.12) and the
26+
# latest stable (3.14) supported Python versions. Remove "3.13"
27+
# from this list to also test on 3.13.
28+
"ignored_versions": ["3.13"],
29+
# Newly released Python versions are only tested when listed here,
30+
# for example: "opt_in_versions": ["3.15"].
31+
"opt_in_versions": [],
2632
# Old samples are opted out of enforcing Python type hints
2733
# All new samples should feature them
2834
"enforce_type_hints": True,

0 commit comments

Comments
 (0)