forked from PaulEcoffet/birdsonganalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
93 lines (70 loc) · 2.48 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
import os
import pathlib
import shutil
import nox
DIR = pathlib.Path(__file__).parent.resolve()
VENV_DIR = pathlib.Path('./.venv').resolve()
nox.options.sessions = ['tests', 'coverage']
@nox.session
def build(session: nox.Session) -> None:
"""
Build an SDist and wheel with ``flit``.
"""
dist_dir = DIR.joinpath("dist")
if dist_dir.exists():
shutil.rmtree(dist_dir)
session.install(".[dev]")
session.run("flit", "build")
@nox.session
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)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
# 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
session.run(python, "-m", "pip", "install", "-e", ".[dev,tests,docs]", external=True)
@nox.session
def tests(session) -> None:
"""
Run the unit and regular tests.
"""
session.install(".[test]")
session.run("pytest", *session.posargs)
@nox.session
def coverage(session) -> None:
"""
Run the unit and regular tests, and save coverage report
"""
session.install(".[tests]", "pytest-cov")
session.run(
"pytest", "--cov=./", "--cov-report=xml", *session.posargs
)
@nox.session
def docs(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(".[docs]")
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")