-
Notifications
You must be signed in to change notification settings - Fork 6
/
noxfile.py
104 lines (73 loc) · 2.45 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 glob
from nox import session, Session, options
import shutil
options.sessions = ["lint", "tests", "examples"]
main_version = ["3.11"]
supported_versions = main_version + ["3.9", "3.10"]
locations = "pysketcher", "tests", "examples", "docs", "noxfile.py"
def _lint(session: Session, install: bool = True) -> None:
if install:
session.install(".[lint]")
session.run("flake8")
@session(python=False)
def local_lint(session: Session) -> None:
_lint(session, install=False)
@session(python=main_version)
def lint(session: Session) -> None:
_lint(session, install=True)
def _tests(
session: Session, cov_report: str = "xml:coverage.xml", install: bool = True
) -> None:
if install:
session.install(".[tests]")
session.run(
"pytest", "--cov", "--cov-report", cov_report, "--junitxml=test-results.xml"
)
@session(python=False)
def local_tests(session: Session):
_tests(session, "html", False)
@session(python=supported_versions)
def tests(session: Session):
_tests(session)
@session(python=False)
def install(session: Session):
session.run("pip", "install", "-e", ".[lint,tests,documentation,build]")
@session(python=supported_versions)
def build(session: Session):
session.run("pip", "install", ".[build]")
session.run("python", "-m", "build")
def _examples(session: Session, install: bool = False) -> None:
if install:
session.install(".[tests]")
session.run(
"pytest",
"--cov",
"--cov-append",
"-o",
"testpaths=examples",
"-o",
"python_files=*.py",
"-o",
"python_functions=main",
)
@session(python=False)
def local_examples(session: Session):
_examples(session)
@session(python=supported_versions)
def examples(session: Session):
_examples(session, install=True)
def _documentation(session: Session, install: bool = False) -> None:
"""Build the documentation."""
if install:
session.install(".[documentation,tests]")
session.run("pytest", "pysketcher") # generate the images by running the docstrings
for file in glob.glob("./pysketcher/images/*.png"):
print(f"{file}")
shutil.copy(file, "./docs/images")
session.run("sphinx-build", "docs", "docs/_build")
@session(python=main_version)
def documentation(session: Session):
_documentation(session, install=True)
@session(python=False)
def local_documentation(session: Session):
_documentation(session)