-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathnoxfile.py
More file actions
125 lines (93 loc) · 2.99 KB
/
noxfile.py
File metadata and controls
125 lines (93 loc) · 2.99 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
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
# Copyright 2022-2026 Broadcom.
# SPDX-License-Identifier: Apache-2
"""
Nox session definitions.
"""
import datetime
import os
import pathlib
import nox # isort:skip
CI_RUN = os.environ.get("CI") is not None
PIP_INSTALL_SILENT = CI_RUN is False
SKIP_REQUIREMENTS_INSTALL = os.environ.get("SKIP_REQUIREMENTS_INSTALL", "0") == "1"
# Global Path Definitions
REPO_ROOT = pathlib.Path(os.path.dirname(__file__)).resolve()
os.chdir(str(REPO_ROOT))
ARTIFACTS_DIR = REPO_ROOT / "artifacts"
PYTEST_LOGFILE = ARTIFACTS_DIR.joinpath(
"logs",
"pytest-{}.log".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S.%f")),
)
# Nox options
# Reuse existing virtualenvs
nox.options.reuse_existing_virtualenvs = True
# Don't fail on missing interpreters
nox.options.error_on_missing_interpreters = False
# Prevent Python from writing bytecode
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
# <---------------------- SESSIONS ---------------------->
@nox.session
def tests(session):
run_pytest_session(session)
@nox.session
@nox.parametrize("arch", ("x86_64", "aarch64"))
def build(session, arch):
invoke_relenv(session, "toolchain", "download", f"--arch={arch}")
invoke_relenv(session, "build", f"--arch={arch}")
# Convenience sessions
@nox.session
def build_x86_64(session):
session.notify("build(arch='x86_64')")
@nox.session
def build_aarch64(session):
session.notify("build(arch='aarch64')")
@nox.session
def toolchain_x86_64(session):
session.notify("toolchain(arch='x86_64')")
@nox.session
def toolchain_aarch64(session):
session.notify("toolchain(arch='aarch64')")
@nox.session
def docs(session):
if not SKIP_REQUIREMENTS_INSTALL:
session.install(
"-r",
str(REPO_ROOT / "requirements" / "docs.txt"),
silent=PIP_INSTALL_SILENT,
)
os.chdir("docs")
session.run("sphinx-build", "-b", "html", "source", "build")
# <---------------------- HELPERS ---------------------->
def run_pytest_session(session, *cmd_args):
make_artifacts_directory()
if not SKIP_REQUIREMENTS_INSTALL:
session.install(
"-r",
str(REPO_ROOT / "requirements" / "tests.txt"),
silent=PIP_INSTALL_SILENT,
)
default_args = [
"-vv",
"--showlocals",
"--show-capture=no",
"-ra",
"-s",
"--log-file-level=debug",
"--strict-markers",
]
# check for --log-file
for arg in cmd_args:
if arg.startswith("--log-file"):
break
else:
default_args.append(f"--log-file={PYTEST_LOGFILE}")
pytest_args = default_args + list(cmd_args) + session.posargs
env = {}
if "RELENV_DATA" in os.environ:
env["RELENV_DATA"] = os.environ["RELENV_DATA"]
session.run("python", "-m", "pytest", *pytest_args, env=env)
def invoke_relenv(session, *cmd_args):
session.run("python", "-m", "relenv", *cmd_args)
def make_artifacts_directory():
ARTIFACTS_DIR.mkdir(parents=True, exist_ok=True)
ARTIFACTS_DIR.chmod(0o777)