-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
104 lines (84 loc) · 2.67 KB
/
noxfile.py
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
import os
import pathlib
import shutil
from itertools import chain
import nox
PROJECT = "nbgitpuller-link"
PACKAGE = "nbgitpuller_link"
HERE = pathlib.Path(__file__)
ROOT = HERE.parent
PATHS = ["nbgitpuller_link", "examples", "tests", HERE.name]
PYTHON_VERSIONS = ["3.10", "3.11", "3.12"]
@nox.session(python=PYTHON_VERSIONS)
def test(session: nox.Session) -> None:
"""Run the tests."""
session.install(".[testing]")
args = session.posargs or ["--cov", "--cov-report=term", "-vvv"]
session.run("pytest", *args)
@nox.session(name="test-cli", python=PYTHON_VERSIONS)
def test_cli(session: nox.Session) -> None:
"""Test the command line interface."""
session.install(".")
session.run(PROJECT, "--version")
session.run(PROJECT, "--help")
@nox.session
def format(session: nox.Session) -> None:
"""Clean lint and assert style."""
session.install(".[dev]")
session.run("black", *PATHS)
session.run("isort", *PATHS)
session.run("flake8", *PATHS)
@nox.session
def build(session: nox.Session) -> None:
"""Build source and binary distributions."""
session.install(".[build]")
session.run("python", "-m", "build")
@nox.session
def release(session):
"""Tag, build, and publish a new release to PyPI."""
session.install("zest.releaser[recommended]")
session.run("fullrelease")
@nox.session(name="testpypi")
def publish_testpypi(session):
"""Upload package to TestPyPI."""
session.run("twine", "check", "dist/*")
session.run(
"twine",
"upload",
"--skip-existing",
"--repository-url",
"https://test.pypi.org/legacy/",
"dist/*",
)
@nox.session(name="pypi")
def publish_pypi(session):
"""Upload package to PyPI."""
session.run("twine", "check", "dist/*")
session.run(
"twine",
"upload",
"--skip-existing",
"--repository-url",
"https://upload.pypi.org/legacy/",
"dist/*",
)
@nox.session(python=False)
def clean(session):
"""Remove virtual environments, build files, and caches."""
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree("dist", ignore_errors=True)
shutil.rmtree(f"{PACKAGE}.egg-info", ignore_errors=True)
shutil.rmtree(".pytest_cache", ignore_errors=True)
shutil.rmtree(".venv", ignore_errors=True)
if os.path.exists(".coverage"):
os.remove(".coverage")
for p in chain(ROOT.rglob("*.py[co]"), ROOT.rglob("__pycache__")):
if p.is_dir():
p.rmdir()
else:
p.unlink()
@nox.session(python=False)
def nuke(session):
"""Clean and also remove the .nox directory."""
clean(session)
shutil.rmtree(".nox", ignore_errors=True)