1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# /// script
# dependencies = ["nox>=2025.2.9"]
# ///
from __future__ import annotations
import os
import sys
from pathlib import Path
import nox
nox.needs_version = ">=2025.2.9"
PYTHON_ALL_VERSIONS = ["3.10", "3.11", "3.12", "3.13", "3.14"]
RUNNING_CI = "TRAVIS" in os.environ or "GITHUB_ACTIONS" in os.environ
wheel = ""
sdist = ""
@nox.session(reuse_venv=True)
def lint(session: nox.Session) -> None:
"""
Run linters on the codebase.
"""
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files")
@nox.session(default=False)
def coverage(session: nox.Session) -> None:
"""
Run coverage using unit tests.
"""
pyproject = nox.project.load_toml("pyproject.toml")
deps = nox.project.dependency_groups(pyproject, "coverage")
session.install("-e", ".", *deps)
session.run(
"python",
"-m",
"pytest",
"tests/unit",
"--cov=auditwheel",
"--cov-report=term-missing",
)
def _docker_images(session: nox.Session) -> list[str]:
tmp_dir = Path(session.create_tmp())
script = tmp_dir / "list_images.py"
images_file = tmp_dir / "images.lst"
script.write_text(
rf"""
import sys
from pathlib import Path
sys.path.append("./tests/integration")
from test_manylinux import MANYLINUX_IMAGES
images = "\n".join(MANYLINUX_IMAGES.values())
Path(r"{images_file}").write_text(images)
"""
)
session.run("python", str(script), silent=True)
return images_file.read_text().splitlines()
@nox.session(python=PYTHON_ALL_VERSIONS, default=False)
def tests(session: nox.Session) -> None:
"""
Run tests.
"""
posargs = session.posargs
dep_group = "coverage" if RUNNING_CI else "test"
pyproject = nox.project.load_toml("pyproject.toml")
deps = nox.project.dependency_groups(pyproject, dep_group)
session.install("-U", "pip")
session.install("-e", ".", *deps)
# for tests/integration/test_bundled_wheels.py::test_analyze_wheel_abi_static_exe
session.run(
"pip",
"download",
"--only-binary",
":all:",
"--no-deps",
"--platform",
"manylinux1_x86_64",
"-d",
"./tests/integration/",
"patchelf==0.17.2.1",
)
if RUNNING_CI:
posargs.extend(["--cov", "auditwheel", "--cov-branch"])
# pull manylinux images that will be used.
# this helps passing tests which would otherwise timeout.
for image in _docker_images(session):
session.run("docker", "pull", image, external=True)
session.run("pytest", "-s", *posargs)
if RUNNING_CI:
session.run("auditwheel", "lddtree", sys.executable)
session.run("coverage", "xml", "-ocoverage.xml")
@nox.session(python=["3.10"], default=False)
def build(session: nox.Session) -> None:
session.install("build")
tmp_dir = Path(session.create_tmp()) / "build-output"
session.run("python", "-m", "build", "--outdir", str(tmp_dir))
(wheel_path,) = tmp_dir.glob("*.whl")
(sdist_path,) = tmp_dir.glob("*.tar.gz")
Path("dist").mkdir(exist_ok=True)
wheel_path.rename(f"dist/{wheel_path.name}")
sdist_path.rename(f"dist/{sdist_path.name}")
global sdist # noqa: PLW0603
sdist = f"dist/{sdist_path.name}"
global wheel # noqa: PLW0603
wheel = f"dist/{wheel_path.name}"
def _test_dist(session: nox.Session, path: str) -> None:
pyproject = nox.project.load_toml("pyproject.toml")
deps = nox.project.dependency_groups(pyproject, "test")
session.install(path, *deps)
session.run("pytest", "tests/unit")
@nox.session(name="test-sdist", python=PYTHON_ALL_VERSIONS, requires=["build"])
def test_sdist(session: nox.Session) -> None:
"""
Do not run explicitly.
"""
_test_dist(session, sdist)
@nox.session(name="test-wheel", python=PYTHON_ALL_VERSIONS, requires=["build"])
def test_wheel(session: nox.Session) -> None:
"""
Do not run explicitly.
"""
_test_dist(session, wheel)
@nox.session(python=PYTHON_ALL_VERSIONS, reuse_venv=True, default=False)
def develop(session: nox.Session) -> None:
session.run("python", "-m", "pip", "install", "--upgrade", "pip")
pyproject = nox.project.load_toml("pyproject.toml")
deps = nox.project.dependency_groups(pyproject, "dev")
session.install("-e", ".", *deps)
if __name__ == "__main__":
nox.main()
|