|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import os |
| 4 | +import pathlib |
| 5 | +import shutil |
| 6 | + |
| 7 | +import nox |
| 8 | + |
| 9 | +PROJECT = "heat" |
| 10 | +ROOT = pathlib.Path(__file__).parent |
| 11 | + |
| 12 | + |
| 13 | +@nox.session |
| 14 | +def test(session: nox.Session) -> None: |
| 15 | + """Run the tests.""" |
| 16 | + session.install(".[testing]") |
| 17 | + |
| 18 | + args = ["--cov", PROJECT, "-vvv"] + session.posargs |
| 19 | + |
| 20 | + if "CI" in os.environ: |
| 21 | + args.append(f"--cov-report=xml:{ROOT.absolute()!s}/coverage.xml") |
| 22 | + session.run("pytest", *args) |
| 23 | + |
| 24 | + if "CI" not in os.environ: |
| 25 | + session.run("coverage", "report", "--ignore-errors", "--show-missing") |
| 26 | + |
| 27 | + |
| 28 | +@nox.session |
| 29 | +def lint(session: nox.Session) -> None: |
| 30 | + """Look for lint.""" |
| 31 | + session.install("pre-commit") |
| 32 | + session.run("pre-commit", "run", "--all-files") |
| 33 | + |
| 34 | + |
| 35 | +@nox.session |
| 36 | +def build(session: nox.Session) -> None: |
| 37 | + session.install("pip") |
| 38 | + session.install("build") |
| 39 | + session.run("python", "--version") |
| 40 | + session.run("pip", "--version") |
| 41 | + session.run("python", "-m", "build", "--outdir", "./build/wheelhouse") |
| 42 | + |
| 43 | + |
| 44 | +@nox.session(name="publish-testpypi") |
| 45 | +def publish_testpypi(session): |
| 46 | + """Publish wheelhouse/* to TestPyPI.""" |
| 47 | + session.run("twine", "check", "build/wheelhouse/*") |
| 48 | + session.run( |
| 49 | + "twine", |
| 50 | + "upload", |
| 51 | + "--skip-existing", |
| 52 | + "--repository-url", |
| 53 | + "https://test.pypi.org/legacy/", |
| 54 | + "build/wheelhouse/*.tar.gz", |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +@nox.session(name="publish-pypi") |
| 59 | +def publish_pypi(session): |
| 60 | + """Publish wheelhouse/* to PyPI.""" |
| 61 | + session.run("twine", "check", "build/wheelhouse/*") |
| 62 | + session.run( |
| 63 | + "twine", |
| 64 | + "upload", |
| 65 | + "--skip-existing", |
| 66 | + "build/wheelhouse/*.tar.gz", |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +@nox.session(python=False) |
| 71 | +def clean(session): |
| 72 | + """Remove all .venv's, build files and caches in the directory.""" |
| 73 | + folders = ( |
| 74 | + (ROOT,) if not session.posargs else (pathlib.Path(f) for f in session.posargs) |
| 75 | + ) |
| 76 | + for folder in folders: |
| 77 | + if not str(folder.resolve()).startswith(str(ROOT.resolve())): |
| 78 | + session.log(f"skipping {folder}: folder is outside of repository") |
| 79 | + continue |
| 80 | + |
| 81 | + with session.chdir(folder): |
| 82 | + session.log(f"cleaning {folder}") |
| 83 | + |
| 84 | + shutil.rmtree("build", ignore_errors=True) |
| 85 | + shutil.rmtree("dist", ignore_errors=True) |
| 86 | + shutil.rmtree(f"src/{PROJECT}.egg-info", ignore_errors=True) |
| 87 | + shutil.rmtree(".pytest_cache", ignore_errors=True) |
| 88 | + shutil.rmtree(".venv", ignore_errors=True) |
| 89 | + |
| 90 | + for pattern in ["*.py[co]", "__pycache__"]: |
| 91 | + _clean_rglob(pattern) |
| 92 | + |
| 93 | + |
| 94 | +def _clean_rglob(pattern): |
| 95 | + nox_dir = pathlib.Path(".nox") |
| 96 | + |
| 97 | + for p in pathlib.Path(".").rglob(pattern): |
| 98 | + if nox_dir in p.parents: |
| 99 | + continue |
| 100 | + if p.is_dir(): |
| 101 | + p.rmdir() |
| 102 | + else: |
| 103 | + p.unlink() |
0 commit comments