-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
84 lines (70 loc) · 2.25 KB
/
noxfile.py
File metadata and controls
84 lines (70 loc) · 2.25 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
import tempfile
from typing import Any
import nox
from nox.sessions import Session
nox.options.sessions = "lint", "mypy", "tests"
lint_annotations_locations = "agents", "noxfile.py", "utilities"
style_locations = (
"agents",
"noxfile.py",
"utilities",
"train_VPG_for_cartpole.py",
"train_DQN_for_cartpole.py",
"train_TRPG_for_cartpole.py",
"tests",
)
typing_locations = "agents", "noxfile.py", "utilities"
@nox.session(python=["3.10"])
def black(session: Session) -> None:
args = session.posargs or style_locations
install_with_constraints(session, "black")
session.run("black", *args)
@nox.session(python=["3.10"])
def tests(session: Session) -> None:
args = session.posargs
session.run("poetry", "install", external=True)
session.run("pytest", *args)
def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> None:
with tempfile.NamedTemporaryFile() as tmp:
session.run(
"poetry",
"export",
"--dev",
"--format=requirements.txt",
"--without-hashes",
f"--output={tmp.name}",
external=True,
)
# remove lines with extra constrains e.g. gymnasium[accept-rom-license]
# as they cause a pip error
requirements = tmp.readlines()
tmp.seek(0)
for line in requirements:
if "[" not in str(line):
tmp.write(line)
tmp.truncate()
session.install(f"--constraint={tmp.name}", *args, **kwargs)
@nox.session(python=["3.10"])
def lint(session: Session) -> None:
args = session.posargs or style_locations
install_with_constraints(
session,
"flake8",
"flake8-black",
"flake8-bugbear",
"flake8-import-order",
)
session.run("flake8", *args)
@nox.session(python=["3.10"])
def lint_annotations(session: Session) -> None:
args = session.posargs or lint_annotations_locations
install_with_constraints(
session,
"flake8-annotations",
)
session.run("flake8", *args)
@nox.session(python=["3.10"])
def mypy(session: Session) -> None:
args = session.posargs or typing_locations
install_with_constraints(session, "mypy", "numpy", "torch")
session.run("mypy", *args)