2022-07-14 13:36:57 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2022-02-27 14:16:37 -05:00
|
|
|
import os
|
2021-05-21 17:45:43 -04:00
|
|
|
import shutil
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
2024-05-13 23:40:34 -04:00
|
|
|
from typing import Any
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
import nox
|
|
|
|
|
|
2024-05-13 23:40:34 -04:00
|
|
|
nox.needs_version = ">=2024.4.15"
|
2022-02-27 14:16:37 -05:00
|
|
|
nox.options.sessions = ["lint", "pylint", "check_manifest", "tests"]
|
2024-05-13 23:40:34 -04:00
|
|
|
nox.options.default_venv_backend = "uv|virtualenv"
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
DIR = Path(__file__).parent.resolve()
|
|
|
|
|
|
2024-05-13 23:40:34 -04:00
|
|
|
|
2026-03-16 19:24:46 +00:00
|
|
|
def install_and_run(session: nox.Session, script: str, *args: str, **kwargs: Any) -> Any:
|
2024-05-13 23:40:34 -04:00
|
|
|
deps = nox.project.load_toml(script)["dependencies"]
|
|
|
|
|
session.install(*deps)
|
|
|
|
|
return session.run("python", script, *args, **kwargs)
|
2022-02-27 14:16:37 -05:00
|
|
|
|
2021-05-21 17:45:43 -04:00
|
|
|
|
2024-11-19 13:30:06 -05:00
|
|
|
def dep_group(group: str) -> list[str]:
|
|
|
|
|
return nox.project.load_toml("pyproject.toml")["dependency-groups"][group] # type: ignore[no-any-return]
|
|
|
|
|
|
|
|
|
|
|
2021-05-21 17:45:43 -04:00
|
|
|
@nox.session
|
2021-07-15 22:44:39 -04:00
|
|
|
def tests(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
|
|
|
|
Run the unit and regular tests.
|
|
|
|
|
"""
|
2024-11-19 13:30:06 -05:00
|
|
|
session.install("-e.", *dep_group("test"))
|
2021-05-25 13:25:28 -04:00
|
|
|
if session.posargs:
|
|
|
|
|
session.run("pytest", *session.posargs)
|
|
|
|
|
else:
|
2024-05-13 23:40:34 -04:00
|
|
|
unit_test_args = ["--run-docker"] if sys.platform.startswith("linux") else []
|
2021-05-25 13:25:28 -04:00
|
|
|
session.run("pytest", "unit_test", *unit_test_args)
|
|
|
|
|
session.run("pytest", "test", "-x", "--durations", "0", "--timeout=2400", "test")
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session
|
2021-07-15 22:44:39 -04:00
|
|
|
def lint(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
|
|
|
|
Run the linter.
|
|
|
|
|
"""
|
|
|
|
|
session.install("pre-commit")
|
2021-07-15 22:44:39 -04:00
|
|
|
session.run("pre-commit", "run", "--all-files", *session.posargs)
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
|
2022-02-27 14:16:37 -05:00
|
|
|
@nox.session
|
|
|
|
|
def pylint(session: nox.Session) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Run pylint.
|
|
|
|
|
"""
|
|
|
|
|
|
2024-05-15 23:15:53 -04:00
|
|
|
session.install("pylint>=3.2", "-e.")
|
2022-02-27 14:16:37 -05:00
|
|
|
session.run("pylint", "cibuildwheel", *session.posargs)
|
|
|
|
|
|
|
|
|
|
|
2021-10-26 12:06:09 -04:00
|
|
|
@nox.session
|
|
|
|
|
def check_manifest(session: nox.Session) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Ensure all needed files are included in the manifest.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
session.install("check-manifest")
|
|
|
|
|
session.run("check-manifest", *session.posargs)
|
|
|
|
|
|
|
|
|
|
|
2024-03-21 15:41:31 -04:00
|
|
|
@nox.session
|
2021-07-15 22:44:39 -04:00
|
|
|
def update_constraints(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
|
|
|
|
Update the dependencies inplace.
|
|
|
|
|
"""
|
2024-03-21 15:41:31 -04:00
|
|
|
|
2024-05-28 05:31:36 -07:00
|
|
|
resources = Path("cibuildwheel/resources")
|
|
|
|
|
|
2024-05-13 23:40:34 -04:00
|
|
|
if session.venv_backend != "uv":
|
2024-03-21 15:41:31 -04:00
|
|
|
session.install("uv>=0.1.23")
|
|
|
|
|
|
2024-05-12 02:26:18 +02:00
|
|
|
for minor_version in range(7, 14):
|
2024-03-21 15:41:31 -04:00
|
|
|
python_version = f"3.{minor_version}"
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
|
# CUSTOM_COMPILE_COMMAND is a pip-compile option that tells users how to
|
|
|
|
|
# regenerate the constraints files
|
|
|
|
|
env["UV_CUSTOM_COMPILE_COMMAND"] = f"nox -s {session.name}"
|
2024-05-28 05:31:36 -07:00
|
|
|
output_file = resources / f"constraints-python{python_version.replace('.', '')}.txt"
|
2024-03-21 15:41:31 -04:00
|
|
|
session.run(
|
|
|
|
|
"uv",
|
|
|
|
|
"pip",
|
|
|
|
|
"compile",
|
|
|
|
|
f"--python-version={python_version}",
|
|
|
|
|
"--upgrade",
|
2024-05-28 05:31:36 -07:00
|
|
|
resources / "constraints.in",
|
|
|
|
|
f"--output-file={output_file}",
|
2024-03-21 15:41:31 -04:00
|
|
|
env=env,
|
2022-08-02 22:56:59 +02:00
|
|
|
)
|
2024-05-28 05:31:36 -07:00
|
|
|
|
2024-03-21 15:41:31 -04:00
|
|
|
shutil.copyfile(
|
2024-05-28 05:31:36 -07:00
|
|
|
resources / "constraints-python312.txt",
|
|
|
|
|
resources / "constraints.txt",
|
2024-03-21 15:41:31 -04:00
|
|
|
)
|
2021-05-21 17:45:43 -04:00
|
|
|
|
2024-05-28 05:31:36 -07:00
|
|
|
build_platforms = nox.project.load_toml(resources / "build-platforms.toml")
|
|
|
|
|
pyodides = build_platforms["pyodide"]["python_configurations"]
|
|
|
|
|
for pyodide in pyodides:
|
|
|
|
|
python_version = ".".join(pyodide["version"].split(".")[:2])
|
2024-11-23 02:47:51 +05:30
|
|
|
pyodide_build_version = pyodide["pyodide_build_version"]
|
2024-05-28 05:31:36 -07:00
|
|
|
output_file = resources / f"constraints-pyodide{python_version.replace('.', '')}.txt"
|
|
|
|
|
tmp_file = Path(session.create_tmp()) / "constraints-pyodide.in"
|
2024-11-23 02:47:51 +05:30
|
|
|
tmp_file.write_text(f"pip\nbuild[virtualenv]\npyodide-build=={pyodide_build_version}")
|
2024-05-28 05:31:36 -07:00
|
|
|
session.run(
|
|
|
|
|
"uv",
|
|
|
|
|
"pip",
|
|
|
|
|
"compile",
|
|
|
|
|
f"--python-version={python_version}",
|
|
|
|
|
"--upgrade",
|
|
|
|
|
tmp_file,
|
|
|
|
|
f"--output-file={output_file}",
|
|
|
|
|
env=env,
|
|
|
|
|
)
|
|
|
|
|
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
@nox.session
|
2021-07-15 22:44:39 -04:00
|
|
|
def update_pins(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
2022-01-08 11:30:48 +01:00
|
|
|
Update the python, docker and virtualenv pins version inplace.
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
2024-11-19 13:30:06 -05:00
|
|
|
session.install("-e.", *dep_group("bin"))
|
2021-05-21 17:45:43 -04:00
|
|
|
session.run("python", "bin/update_pythons.py", "--force")
|
|
|
|
|
session.run("python", "bin/update_docker.py")
|
2022-01-08 11:30:48 +01:00
|
|
|
session.run("python", "bin/update_virtualenv.py", "--force")
|
2024-05-28 05:31:36 -07:00
|
|
|
session.run("python", "bin/update_nodejs.py", "--force")
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
|
2024-05-13 23:40:34 -04:00
|
|
|
@nox.session(reuse_venv=True)
|
2021-07-15 22:44:39 -04:00
|
|
|
def update_proj(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
|
|
|
|
Update the README inplace.
|
|
|
|
|
"""
|
2024-05-13 23:40:34 -04:00
|
|
|
install_and_run(
|
|
|
|
|
session,
|
2021-07-15 22:44:39 -04:00
|
|
|
"bin/projects.py",
|
|
|
|
|
"docs/data/projects.yml",
|
|
|
|
|
*session.posargs,
|
|
|
|
|
)
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
|
2023-09-26 11:23:20 -05:00
|
|
|
@nox.session(reuse_venv=True)
|
|
|
|
|
def generate_schema(session: nox.Session) -> None:
|
2023-10-09 09:36:09 -04:00
|
|
|
"""
|
|
|
|
|
Generate the cibuildwheel.schema.json file.
|
|
|
|
|
"""
|
2024-05-13 23:40:34 -04:00
|
|
|
output = install_and_run(session, "bin/generate_schema.py", silent=True)
|
2023-09-26 11:23:20 -05:00
|
|
|
assert isinstance(output, str)
|
|
|
|
|
DIR.joinpath("cibuildwheel/resources/cibuildwheel.schema.json").write_text(output)
|
|
|
|
|
|
|
|
|
|
|
2024-05-13 23:40:34 -04:00
|
|
|
@nox.session(reuse_venv=True)
|
|
|
|
|
def bump_version(session: nox.Session) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Bump cibuildwheel's version. Interactive.
|
|
|
|
|
"""
|
|
|
|
|
install_and_run(session, "bin/bump_version.py")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python="3.12")
|
2021-07-15 22:44:39 -04:00
|
|
|
def docs(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
2024-03-21 15:41:31 -04:00
|
|
|
Build the docs. Will serve unless --non-interactive
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
2024-11-19 13:30:06 -05:00
|
|
|
session.install("-e.", *dep_group("docs"))
|
2024-05-12 00:51:20 -04:00
|
|
|
session.run("mkdocs", "serve" if session.interactive else "build", "--strict", *session.posargs)
|
2021-05-21 17:45:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session
|
2021-07-15 22:44:39 -04:00
|
|
|
def build(session: nox.Session) -> None:
|
2021-05-21 17:45:43 -04:00
|
|
|
"""
|
|
|
|
|
Build an SDist and wheel.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
build_p = DIR.joinpath("build")
|
|
|
|
|
if build_p.exists():
|
|
|
|
|
shutil.rmtree(build_p)
|
|
|
|
|
|
|
|
|
|
dist_p = DIR.joinpath("dist")
|
|
|
|
|
if dist_p.exists():
|
|
|
|
|
shutil.rmtree(dist_p)
|
|
|
|
|
|
|
|
|
|
session.install("build")
|
|
|
|
|
session.run("python", "-m", "build")
|