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
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15",
"Topic :: Software Development",
]
requires-python = ">=3.9"
Expand Down Expand Up @@ -52,6 +53,7 @@ dev = [
"sphinx-book-theme >=1.1.4",
"sphinx-taskgraph>=0.1.0",
"sphinxcontrib-mermaid>=1.0.0",
"tomli>=2.0; python_version < '3.11'",
"vermin>=1.8.0",
"zstandard>=0.25.0",
]
Expand Down
2 changes: 1 addition & 1 deletion taskcluster/docker/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ RUN apt-get update \
ENV PATH=/builds/worker/.local/bin:$PATH

# %ARG PYTHON_VERSIONS
RUN uv python install $PYTHON_VERSIONS
RUN uv python install --no-cache $PYTHON_VERSIONS
5 changes: 3 additions & 2 deletions taskcluster/kinds/codecov/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
loader: taskgraph.loader.transform:loader

transforms:
- self_taskgraph.transforms.python_versions
- taskgraph.transforms.from_deps
- taskgraph.transforms.run
- taskgraph.transforms.task
Expand All @@ -23,11 +24,11 @@ tasks:
set-name: null
with-attributes:
# exclude free-threaded python until it is officially supported
python: ["314", "313", "312", "311", "310", "39"]
python: [max..min]
resolution: default
fetches:
test:
- artifact: coverage.py{matrix[python]}
- artifact: "{coverage_artifact}"
worker-type: t-linux
worker:
docker-image: {in-tree: python}
Expand Down
7 changes: 5 additions & 2 deletions taskcluster/kinds/docker-image/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
loader: taskgraph.loader.transform:loader

transforms:
- self_taskgraph.transforms.python_versions
- taskgraph.transforms.docker_image:transforms
- taskgraph.transforms.cached_tasks:transforms
- self_taskgraph.transforms.add_pr_route
Expand All @@ -27,10 +28,12 @@ tasks:
symbol: I(py)
parent: run-task
args:
PYTHON_VERSIONS: "3.14t 3.14 3.13 3.12 3.11 3.10 3.9 3.8"
# 3.8 is the minimum version supported by run-task / fetch-content,
# see the `check-scripts-min-python` task.
PYTHON_VERSIONS: "maxt max..min 3.8"
run-task:
symbol: I(rt)
args:
UV_VERSION: "0.9.3"
UV_VERSION: "0.13.8"
skopeo:
symbol: I(skopeo)
1 change: 1 addition & 0 deletions taskcluster/kinds/test/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
loader: taskgraph.loader.transform:loader

transforms:
- self_taskgraph.transforms.python_versions
- taskgraph.transforms.matrix
- taskgraph.transforms.run
- taskgraph.transforms.task
Expand Down
20 changes: 13 additions & 7 deletions taskcluster/kinds/test/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ unit:
matrix:
set-name: "unit-py{matrix[python]}"
substitution-fields: [description, run.command, treeherder, worker, attributes]
python: ["314t", "314", "313", "312", "311", "310", "39"]
python: [maxt, max..min]
attributes:
coverage_artifact: "coverage.py{matrix[python]}"
worker:
docker-image: {in-tree: python}
artifacts:
Expand All @@ -56,7 +58,9 @@ unit-multithread:
matrix:
set-name: "unit-multithread-py{matrix[python]}"
substitution-fields: [description, run.command, treeherder, worker, attributes]
python: ["314t"]
python: [maxt]
attributes:
coverage_artifact: "coverage.py{matrix[python]}"
worker:
docker-image: {in-tree: python}
env:
Expand All @@ -77,15 +81,17 @@ unit-serial:
matrix:
set-name: "unit-serial-py{matrix[python]}"
substitution-fields: [description, run.command, treeherder, worker, attributes]
python: ["314"]
python: [max]
attributes:
coverage_artifact: "coverage.serial-py{matrix[python]}"
worker:
docker-image: {in-tree: python}
env:
TASKGRAPH_SERIAL: "1"
artifacts:
- type: file
path: "/builds/worker/artifacts/coverage"
name: "public/coverage.py{matrix[python]}"
name: "public/coverage.serial-py{matrix[python]}"
treeherder:
symbol: unit-serial(py{matrix[python]})
run:
Expand All @@ -99,12 +105,12 @@ integration:
resolution: "{matrix[resolution]}"
matrix:
set-name: "integration-py{matrix[python]}-deps-{matrix[resolution]}"
python: ["314", "39"]
python: [max, min]
resolution: ["highest", "lowest-direct"]
exclude:
- python: "314"
- python: max
resolution: "lowest-direct"
- python: "39"
- python: min
resolution: "highest"

treeherder:
Expand Down
130 changes: 130 additions & 0 deletions taskcluster/self_taskgraph/transforms/python_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Expand symbolic Python versions into concrete versions. The supported range
is derived from the repository's ``pyproject.toml``.
"""

import re

try:
import tomllib
except ImportError:
# Python < 3.11, provided by the `tomli` dev dependency.
import tomli as tomllib

from taskgraph.transforms.base import TransformSequence

transforms = TransformSequence()

CLASSIFIER_PREFIX = "Programming Language :: Python :: "
LITERAL_VERSION_RE = re.compile(r"\d+\.\d+t?")


def _parse(version):
major, minor = version.strip().split(".")[:2]
return int(major), int(minor)


def _endpoints(graph_config):
"""Return the major version and min/max minor versions from
``pyproject.toml``."""
pyproject = graph_config.vcs_root / "pyproject.toml"
with open(pyproject, "rb") as fh:
project = tomllib.load(fh)["project"]

lower = [
spec.strip()[2:]
for spec in project["requires-python"].split(",")
if spec.strip().startswith(">=")
]
if len(lower) != 1:
raise ValueError(
f"expected a single '>=' bound in requires-python in {pyproject}"
)
min_major, min_minor = _parse(lower[0])

versions = [
_parse(c.removeprefix(CLASSIFIER_PREFIX))
for c in project["classifiers"]
if c.startswith(CLASSIFIER_PREFIX) and "." in c.removeprefix(CLASSIFIER_PREFIX)
]
if not versions:
raise ValueError(f"no '{CLASSIFIER_PREFIX}X.Y' classifiers in {pyproject}")
max_major, max_minor = max(versions)

if min_major != max_major or min_minor > max_minor:
raise ValueError(
f"invalid python version range {min_major}.{min_minor} to "
f"{max_major}.{max_minor} derived from {pyproject}"
)
return min_major, {"min": min_minor, "max": max_minor}


@transforms.add
def expand_python_versions(config, tasks):
major, endpoints = _endpoints(config.graph_config)

def resolve(symbol):
"""Return the (minor version, suffix) for a symbol."""
name, suffix = (symbol[:-1], "t") if symbol.endswith("t") else (symbol, "")
if name not in endpoints:
valid = ", ".join(f"{e}, {e}t" for e in endpoints)
raise ValueError(
f"unknown python version symbol '{symbol}', expected one of: {valid}"
)
return endpoints[name], suffix

def expand(value, sep=""):
start, _, end = value.partition("..")
start, start_suffix = resolve(start)
end, end_suffix = resolve(end) if end else (start, start_suffix)
if start_suffix != end_suffix:
raise ValueError(
f"invalid python version range '{value}': endpoints must both "
"be free-threaded or not"
)
step = 1 if end >= start else -1
return [
f"{major}{sep}{minor}{start_suffix}"
for minor in range(start, end + step, step)
]

def expand_list(values):
return [v for value in values for v in expand(value)]

def expand_args(value):
versions = []
for token in value.split():
if LITERAL_VERSION_RE.fullmatch(token):
versions.append(token)
else:
versions.extend(expand(token, sep="."))
return " ".join(versions)

for task in tasks:
matrix = task.get("matrix", {})
if "python" in matrix:
matrix["python"] = expand_list(matrix["python"])

expanded_rules = []
for rule in matrix.get("exclude", []):
if "python" not in rule:
expanded_rules.append(rule)
continue
for v in expand(rule["python"]):
expanded_rules.append({**rule, "python": v})
if expanded_rules:
matrix["exclude"] = expanded_rules

with_attributes = task.get("from-deps", {}).get("with-attributes", {})
if "python" in with_attributes:
with_attributes["python"] = expand_list(with_attributes["python"])

if config.kind == "docker-image":
args = task.get("args", {})
if "PYTHON_VERSIONS" in args:
args["PYTHON_VERSIONS"] = expand_args(args["PYTHON_VERSIONS"])

yield task
2 changes: 2 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading