Skip to content
Open
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
10 changes: 7 additions & 3 deletions .github/scripts/noxfile-lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import nox

# Use a stable Python version for running the style utilities
LINTING_VERSION = "3.10"
LINTING_VERSION = "3.12"

# Error out if the runner is missing the target python interpreter
nox.options.error_on_missing_interpreters = True
Expand All @@ -33,11 +33,15 @@ def _determine_local_import_names(start_dir: str) -> list[str]:
basename
for basename, extension in file_ext_pairs
if extension == ".py"
or (os.path.isdir(os.path.join(start_dir, basename)) and basename != "__pycache__")
or (
os.path.isdir(os.path.join(start_dir, basename))
and basename != "__pycache__"
)
]
except Exception:
return []


# Linting with flake8.
#
# We ignore the following rules:
Expand Down Expand Up @@ -88,7 +92,7 @@ def lint(session: nox.sessions.Session) -> None:
def blacken(session: nox.sessions.Session) -> None:
"""Runs black code formatting checks. Honors incremental PR file arguments."""
session.install("black")

# If explicit target files are passed via posargs, target ONLY those files.
if session.posargs:
targets = session.posargs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.10'
python-version: '3.12'

- name: Install nox
run: |
Expand Down
37 changes: 27 additions & 10 deletions noxfile-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import nox


# WARNING - WARNING - WARNING - WARNING - WARNING
# WARNING - WARNING - WARNING - WARNING - WARNING
# BE CAREFUL WHEN EDITING THIS FILE!
Expand All @@ -40,7 +39,12 @@

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


# All versions used to tested samples.
ALL_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
# All Python versions that samples can be tested on. 3.12 is the minimum
# supported version.
ALL_VERSIONS = ["3.12", "3.13", "3.14", "3.15"]

# Newly released versions that are only tested when a sample lists them
# in "opt_in_versions". Existing configs only list the versions they
# ignore, so without this a new version would be enabled for all of them.
OPT_IN_VERSIONS = ["3.15"]

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

TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])
TESTED_VERSIONS = sorted(
[
v
for v in ALL_VERSIONS
if v not in IGNORED_VERSIONS
and (v not in OPT_IN_VERSIONS or v in TEST_CONFIG.get("opt_in_versions", []))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the version filtering more robust and prevent potential TypeError exceptions, use TEST_CONFIG.get("opt_in_versions") or [] instead of TEST_CONFIG.get("opt_in_versions", []). If a user's custom noxfile_config.py explicitly overrides opt_in_versions to None or another falsy value, .get(..., []) would still return None, leading to a TypeError: argument of type 'NoneType' is not iterable during the membership check.

Suggested change
and (v not in OPT_IN_VERSIONS or v in TEST_CONFIG.get("opt_in_versions", []))
and (v not in OPT_IN_VERSIONS or v in (TEST_CONFIG.get("opt_in_versions") or []))

]
)

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

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

# Error if a python version is missing
nox.options.error_on_missing_interpreters = True
Expand Down
8 changes: 7 additions & 1 deletion noxfile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@

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