-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnoxfile.py
More file actions
112 lines (88 loc) · 3.47 KB
/
noxfile.py
File metadata and controls
112 lines (88 loc) · 3.47 KB
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
import os
import pathlib
import shutil
import sys
import nox
DIR = pathlib.Path(__file__).parent.resolve()
VENV_DIR = pathlib.Path('./.venv').resolve()
nox.options.sessions = ['test', 'coverage']
TEST_PYTHONS = [
"3.12",
"3.13",
"3.14",
]
@nox.session(python=TEST_PYTHONS[1])
def dev(session: nox.Session) -> None:
"""
Sets up a python development environment for the project.
This session will:
- Create a python virtualenv for the session
- Install the `virtualenv` cli tool into this environment
- Use `virtualenv` to create a global project virtual environment
- Invoke the python interpreter from the global project environment to install
the project and all it's development dependencies.
"""
session.install("virtualenv")
# VENV_DIR here is a pathlib.Path location of the project virtualenv
# e.g. .venv
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
if sys.platform.startswith("linux") or sys.platform == "darwin":
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
elif sys.platform.startswith("win"):
python = os.fsdecode(VENV_DIR.joinpath("Scripts/python.exe"))
# Use the venv's interpreter to install the project along with
# all it's dev dependencies, this ensures it's installed in the right way
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*nox.project.dependency_groups(pyproject, "dev"))
session.run(python, "-m", "pip", "install", "-e", ".", external=True)
@nox.session(python=TEST_PYTHONS[1])
def lint(session):
"""
Run the linter.
"""
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*nox.project.dependency_groups(pyproject, "lint"))
session.run("isort", "./src") # run isort first since black disagrees with it
session.run("black", "./src", "--line-length=120")
session.run("flake8", "./src", "--max-line-length", "120", "--exclude", "./src/crowsetta/_vendor")
@nox.session(python=TEST_PYTHONS)
def test(session) -> None:
"""
Run the unit and regular tests.
"""
session.install(".")
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*nox.project.dependency_groups(pyproject, "test"))
session.run("pytest", "-n", "auto", *session.posargs)
@nox.session
def coverage(session) -> None:
"""
Run the unit and regular tests, and save coverage report
"""
session.install(".")
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*nox.project.dependency_groups(pyproject, "test"))
session.install("pytest-cov")
session.run(
"pytest", "-n", "auto", "--cov=crowsetta", "--cov-report=xml", *session.posargs
)
@nox.session
def doc(session: nox.Session) -> None:
"""
Build the docs.
To run ``sphinx-autobuild``, do:
.. code-block::console
nox -s doc -- autobuild
Otherwise the docs will be built once using
"""
session.install(".")
pyproject = nox.project.load_toml("pyproject.toml")
session.install(*nox.project.dependency_groups(pyproject, "doc"))
if session.posargs:
if "autobuild" in session.posargs:
print("Building docs at http://127.0.0.1:8000 with sphinx-autobuild -- use Ctrl-C to quit")
session.run("sphinx-autobuild", "doc", "doc/_build/html")
else:
print("Unsupported argument to docs")
else:
session.run("sphinx-build", "-nW", "--keep-going", "-b", "html", "doc/", "doc/_build/html")