forked from nautechsystems/nautilus_trader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
127 lines (97 loc) · 3.46 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import tempfile
import nox
from nox.sessions import Session
ALL_EXTRAS = "betfair ccxt docs ib"
# Ensure everything runs within Poetry venvs
nox.options.error_on_external_run = True
@nox.session
def tests(session: Session) -> None:
"""Run the test suite."""
_setup_poetry(session, "--extras", ALL_EXTRAS)
_run_pytest(
session,
"--ignore=tests/integration_tests/",
"--ignore=tests/performance_tests/",
)
@nox.session
def tests_with_integration(session: Session) -> None:
"""Run the test suite including integration tests."""
_setup_poetry(session, "--extras", ALL_EXTRAS)
_run_pytest(session, "--ignore=tests/performance_tests/")
@nox.session
def integration_tests(session: Session) -> None:
"""Run the integration test suite."""
_setup_poetry(session, "--extras", ALL_EXTRAS)
_run_pytest(session, "tests/integration_tests/")
@nox.session
def performance_tests(session: Session) -> None:
"""Run the performance test suite."""
_setup_poetry(session, "--extras", ALL_EXTRAS)
_run_pytest(
session,
"tests/performance_tests/",
"--benchmark-json=output.json",
parallel=False,
)
@nox.session
def coverage(session: Session) -> None:
"""Run with test coverage."""
_setup_poetry(session, "--extras", ALL_EXTRAS, env={"PROFILING_MODE": "true"})
_run_coverage(session)
@nox.session
def build_docs(session: Session) -> None:
"""Build documentation."""
_setup_poetry(session, "--extras", "docs")
session.run("poetry", "run", "sphinx-build", "docs/source", "docs/build")
@nox.session
def safety(session):
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--dev",
"--format=requirements.txt",
"--without-hashes",
f"--output={requirements.name}",
external=True,
)
session.install("safety")
session.run("safety", "check", f"--file={requirements.name}", "--full-report")
def _setup_poetry(session: Session, *args, **kwargs) -> None:
"""Ensure that our environment is peaceful before running the session."""
# Makes sure that poetry and our build requirements are installed.
# Once they are, the package dependencies can be installed and the
# actual package can be compiled.
env = kwargs.get("env", {})
if "no-parallel" in session.posargs:
# Ensure deterministic builds by disabling parallelism
env["PARALLEL_BUILD"] = "" # Empty string parsed as false
# Skip the build copy when using Nox
env["SKIP_BUILD_COPY"] = "true"
kwargs["env"] = env
# Install poetry, then install the project (with its dependencies)
session.install("poetry")
session.run("poetry", "install", *args, **kwargs)
def _run_pytest(session: Session, *args, parallel: bool = False) -> None:
pytest_args = [
"poetry",
"run",
"pytest",
*args,
"--new-first",
"--failed-first",
]
if parallel:
pytest_args += ["--numprocesses=auto", "--dist=loadscope"]
session.run(*pytest_args)
def _run_coverage(session: Session):
_run_pytest(
session,
"--ignore=tests/performance_tests/",
"--cov-report=term",
"--cov-report=xml",
"--cov=nautilus_trader",
# There is an odd Coverage/Cython bug when using pytest-xdist
# so we have to run tests single-threaded here.
parallel=False,
)