-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnoxfile.py
More file actions
84 lines (65 loc) · 2.03 KB
/
noxfile.py
File metadata and controls
84 lines (65 loc) · 2.03 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
from pathlib import Path
import nox
package_path = Path.cwd()
nox.options.default_venv_backend = 'uv'
@nox.session
def pytest(session: nox.Session):
uv_sync(session)
# TODO: no coverage because the far majority of the code in this project is just for testing.
# But it wouldn't hurt to add it.
session.run(
'pytest',
'-ra',
'--tb=native',
'--strict-markers',
'tests',
*session.posargs,
)
@nox.session
def precommit(session: nox.Session):
uv_sync(session, 'pre-commit')
session.run(
'pre-commit',
'run',
'--all-files',
)
@nox.session
def audit(session: nox.Session):
# Much faster to install the deps first and have pip-audit run against the venv
uv_sync(session)
session.run(
'pip-audit',
'--desc',
'--skip-editable',
*pip_audit_ignore_args(),
)
def uv_sync(session: nox.Session, *groups, project=False, extra=None):
# If no group given, assume group shares name of session.
if not groups:
groups = (session.name,)
# At least pytest needs the project installed.
project_args = () if project or session.name.startswith('pytest') else ('--no-install-project',)
group_args = [arg for group in groups for arg in ('--group', group)]
extra_args = ('--extra', extra) if extra else ()
run_args = (
'uv',
'sync',
'--active',
'--frozen',
'--exact',
# Use --no-default-groups instead of --only-group as the latter implies
# --no-install-project.
'--no-default-groups',
*project_args,
*group_args,
*extra_args,
)
session.run(*run_args)
def pip_audit_ignore_args() -> list | tuple:
ignore_fpath = package_path / 'pip-audit-ignore.txt'
if not ignore_fpath.exists():
return ()
vuln_ids = [
line for line in ignore_fpath.read_text().strip().splitlines() if not line.startswith('#')
]
return [arg for vuln_id in vuln_ids for arg in ('--ignore-vuln', vuln_id)]