-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
65 lines (48 loc) · 1.64 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
import shutil
import sys
from pathlib import Path
from typing import Union
import nox
THIS_DIR = Path(__file__).parent
WINDOWS = sys.platform.startswith("win")
SUPPORTED_PYTHONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "pypy3.7", "pypy3.8"]
nox.needs_version = ">=2021.10.1"
nox.options.error_on_external_run = True
def wipe(session: nox.Session, path: Union[str, Path]) -> None:
if "--install-only" in sys.argv:
return
if isinstance(path, str):
path = Path.cwd() / path
normalized = path.relative_to(Path.cwd())
if not path.exists():
return
if path.is_file():
session.log(f"Deleting '{normalized}' file.")
path.unlink()
elif path.is_dir():
session.log(f"Deleting '{normalized}' directory.")
shutil.rmtree(path)
def get_flag(session: nox.Session, flag: str) -> bool:
if flag in session.posargs:
index = session.posargs.index(flag)
del session.posargs[index]
return True
return False
@nox.session(name="lint")
def lint(session: nox.Session) -> None:
"""Run pre-commit."""
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files", "--show-diff-on-failure")
@nox.session(name="tests", python=SUPPORTED_PYTHONS)
def tests(session: nox.Session) -> None:
"""Run test suite."""
coverage = not get_flag(session, "--no-cov")
session.install("black")
session.install("-e", ".[test]")
cmd = ["pytest", "tests"]
if coverage:
wipe(session, "htmlcov")
cmd += ["--cov", "--cov-context", "test"]
session.run(*cmd, *session.posargs)
if coverage:
session.run("coverage", "html")