This repository has been archived by the owner on Aug 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
86 lines (73 loc) · 2.53 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
# Standard Library
import uuid
from pathlib import Path
from typing import Dict
from typing import List
# Third Party Library
import nox
python_code_path_list: List[str] = [
"src",
"noxfile.py",
]
env_common: Dict[str, str] = {
"PYTHONPATH": f"{Path(__file__).parent / 'src'}",
}
nox_tmp_dir: Path = Path(__file__).parent / ".nox_tmp"
python_version_list: List[str] = ["3.10"]
def install_package(session: nox.sessions.Session, dev: bool = False):
session.install("--upgrade", "pip")
session.run("pip", "-V")
requirements_txt_path: Path = nox_tmp_dir / f"poetry-requirements-{str(uuid.uuid4())}.txt"
requirements_txt_path.parent.mkdir(exist_ok=True, parents=True)
try:
cmd = [
"poetry",
"export",
"--without-hashes",
"--format",
"requirements.txt",
"--output",
f"{requirements_txt_path}",
] + (["--dev"] if dev else [])
session.run(*cmd, external=True)
session.install("-r", f"{requirements_txt_path}")
except Exception as e:
raise e
else:
requirements_txt_path.unlink(missing_ok=True)
@nox.session(python=python_version_list)
def test(session):
env: Dict[str, str] = {}
env.update(env_common)
kwargs = dict(env=env)
install_package(session, dev=True)
session.run("pytest", **kwargs)
@nox.session(python=python_version_list)
def lint(session):
env: Dict[str, str] = {}
env.update(env_common)
kwargs = dict(env=env, success_codes=[0, 1])
install_package(session, dev=True)
session.run("flake8", "--statistics", "--count", "--show-source", *python_code_path_list, **kwargs)
session.run("autoflake8", "--check", "--recursive", "--remove-unused-variables", *python_code_path_list, **kwargs)
session.run("isort", "--check", *python_code_path_list, **kwargs)
session.run("black", "--check", *python_code_path_list, **kwargs)
session.run("mypy", "--check", *python_code_path_list, **kwargs)
@nox.session(python=python_version_list)
def format(session):
env: Dict[str, str] = {}
env.update(env_common)
kwargs = dict(env=env, success_codes=[0, 1])
install_package(session, dev=True)
session.run(
"autoflake8",
"--in-place",
"--recursive",
"--remove-unused-variables",
"--in-place",
"--exit-zero-even-if-changed",
*python_code_path_list,
**kwargs,
)
session.run("isort", *python_code_path_list, **kwargs)
session.run("black", *python_code_path_list, **kwargs)