forked from TencentBlueKing/bkpaas-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
65 lines (55 loc) · 2.02 KB
/
noxfile.py
File metadata and controls
65 lines (55 loc) · 2.02 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
import os
import tempfile
import nox
ALL_PYTHON = ["3.10", "3.11", "3.12"]
# ref: https://stackoverflow.com/questions/59768651/how-to-use-nox-with-poetry
def install_with_constraints(session, *args: str, **kwargs) -> None:
"""
Install packages constrained by Poetry's lock file.
This function is a wrapper for nox.sessions.Session.install. It
invokes pip to install packages inside of the session's virtualenv.
Additionally, pip is passed a constraints file generated from
Poetry's lock file, to ensure that the packages are pinned to the
versions specified in poetry.lock. This allows you to manage the
packages as Poetry development dependencies.
Arguments:
session: The Session object.
args: Command-line arguments for pip.
kwargs: Additional keyword arguments for Session.install.
"""
req_path = os.path.join(tempfile.gettempdir(), os.urandom(24).hex())
session.run(
"poetry",
"export",
"--with=dev",
"--format=requirements.txt",
f"--output={req_path}",
external=True,
)
session.install(f"--constraint={req_path}", "--use-deprecated=legacy-resolver", *args, **kwargs)
os.unlink(req_path)
@nox.session(reuse_venv=True)
@nox.parametrize("python", ALL_PYTHON)
def tests(session):
# Prepare pip and poetry
session.run("python", "-m", "ensurepip", "--upgrade")
session.install("poetry")
session.run("poetry", "self", "add", "poetry-plugin-export@latest")
# Install dev/test dependencies
session.install("-e", ".[all]")
install_with_constraints(
session,
"pytest",
"pytest-django",
"pytest-mock",
)
# Install the SQLite driver manually because some environment's sqlite3 version is too old
# to meet the Django requirement.
session.install("pysqlite3-binary")
django_versions = [
">=4.2,<5",
">=5.0,<6",
]
for django in django_versions:
session.install(f"django{django}")
session.run("pytest", *session.posargs)