1
1
import os
2
2
import shutil
3
- from typing import List , Optional
3
+ from typing import Sequence
4
4
5
5
import nox
6
6
12
12
FRR_LATEST_MAJOR_VERSION = "9.1.0"
13
13
14
14
nox .options .sessions = SESSIONS
15
- os .environ .update ({"PDM_IGNORE_SAVED_PYTHON" : "1" })
16
15
17
16
18
- def pdm_sync (
17
+ def uv_run (
19
18
session : nox .Session ,
20
19
* ,
21
- self : bool = False ,
22
- default : bool = False ,
23
- editable : bool = True ,
24
- groups : Optional [List [str ]] = None ,
20
+ command : str ,
21
+ args : Sequence [str ],
25
22
) -> None :
26
- """Install dependencies using PDM .
23
+ """Use uv to run a command provided by a Python package .
27
24
28
25
Args:
29
26
session: The nox session.
30
- self: Whether to install the package itself.
31
- default: Whether to install the default dependencies.
32
- editable: Whether to install packages in editable mode.
33
- groups: The dependency groups to install.
27
+ command: The command to run.
28
+ args: The command arguments.
34
29
"""
35
- cmd = ["pdm" , "sync" ]
36
- if not self :
37
- cmd .append ("--no-self" )
38
- if not default :
39
- cmd .append ("--no-default" )
40
- if not editable :
41
- cmd .append ("--no-editable" )
42
- if groups :
43
- for group in groups :
44
- cmd .append ("-G" )
45
- cmd .append (group )
46
-
47
- session .run (* cmd , external = True )
30
+ session .run ("uv" , "run" , command , * args , external = True )
48
31
49
32
50
33
@nox .session (python = PYTHON )
51
34
def lockfile (session : nox .Session ) -> None :
52
35
"""Check if the lockfile is up-to-date."""
53
- session .run ("pdm " , "lock" , "--check " , external = True )
36
+ session .run ("uv " , "lock" , "--locked " , external = True )
54
37
55
38
56
- @nox .session (python = PYTHON )
39
+ @nox .session (python = PYTHON , venv_backend = "uv" )
57
40
def lint (session : nox .Session ) -> None :
58
41
"""Lint code and check formatting using ruff."""
59
- pdm_sync (session , groups = ["lint" ])
60
- session .run ("ruff" , "check" , "src" , "tests" )
42
+ uv_run (session , command = "ruff" , args = ["check" , "src" , "tests" ])
61
43
# Use ruff to check that formatting conforms to black.
62
- session .run ("ruff" , "format" , "--check" , "src" , "tests" )
44
+ uv_run (
45
+ session ,
46
+ command = "ruff" ,
47
+ args = ["format" , "--check" , "src" , "tests" ],
48
+ )
63
49
64
50
65
- @nox .session (python = PYTHON )
51
+ @nox .session (python = PYTHON , venv_backend = "uv" )
66
52
def mypy (session : nox .Session ) -> None :
67
53
"""Validate static types using mypy."""
68
- pdm_sync (session , default = True , groups = ["typecheck" , "type_stubs" ])
69
- session .run ("mypy" , "src" )
54
+ uv_run (session , command = "mypy" , args = ["src" ])
70
55
71
56
72
- @nox .session (python = PYTHON )
57
+ @nox .session (python = PYTHON , venv_backend = "uv" )
73
58
def test (session : nox .Session ) -> None :
74
59
"""Run tests without external dependencies if not running in CI.
75
60
@@ -80,18 +65,17 @@ def test(session: nox.Session) -> None:
80
65
pytest_no_external_dependencies (session )
81
66
else :
82
67
pytest_full (session )
83
- session . run ( "coverage" , "xml" )
68
+ uv_run ( session , command = "coverage" , args = [ "xml" ] )
84
69
85
70
86
- @nox .session (python = PYTHON )
71
+ @nox .session (python = PYTHON , venv_backend = "uv" )
87
72
def pytest_no_external_dependencies (session : nox .Session ) -> None :
88
73
"""Run pytest tests that have no external dependencies.
89
74
90
75
This session only runs tests that do not require external dependencies
91
76
such as real databases, Docker, etc. and thus should be able to run
92
77
on any developer machine.
93
78
"""
94
- pdm_sync (session , self = True , default = True , groups = ["test" ])
95
79
session .warn (
96
80
"Skipping the following test marker(s) "
97
81
"since they require external dependencies: {}.\n "
@@ -107,57 +91,53 @@ def pytest_no_external_dependencies(session: nox.Session) -> None:
107
91
else :
108
92
markexpr += f" and not { marker } "
109
93
110
- session . run ( "pytest" , "tests" , "-m" , markexpr , * session .posargs )
94
+ uv_run ( session , command = "pytest" , args = [ "tests" , "-m" , markexpr , * session .posargs ] )
111
95
112
96
113
- @nox .session (python = PYTHON )
97
+ @nox .session (python = PYTHON , venv_backend = "uv" )
114
98
def pytest_full (session : nox .Session ) -> None :
115
99
"""Run all pytest tests.
116
100
117
101
This session includes all tests and is intended to be
118
102
run in CI or before a commit.
119
103
"""
120
- pdm_sync (session , self = True , default = True , groups = ["test" ])
121
104
args = session .posargs if not CI else ["--cov" ]
122
- session .run (
123
- "pytest" ,
124
- "tests" ,
125
- "-m" ,
126
- # FRRouting tests that run against a FRRouting daemon have their own session
127
- "not frrouting_daemon_required" ,
128
- * args ,
105
+ uv_run (
106
+ session ,
107
+ command = "pytest" ,
108
+ args = [
109
+ "tests" ,
110
+ "-m" ,
111
+ # FRRouting tests that run against a FRRouting daemon have their own session
112
+ "not frrouting_daemon_required" ,
113
+ * args ,
114
+ ],
129
115
)
130
116
session .notify ("pytest_frrouting_daemon_required" )
131
117
132
118
133
- @nox .session (python = PYTHON )
119
+ @nox .session (python = PYTHON , venv_backend = "uv" )
134
120
def pytest_frrouting_daemon_required (session : nox .Session ) -> None :
135
121
"""Run pytest FRRouting integration tests against a FRRouting daemon.
136
122
137
123
This session runs the integration tests that run against a local FRRouting instance
138
124
using the FRRouting docker image.
139
125
"""
140
- pdm_sync (session , self = True , default = True , groups = ["test" ])
141
126
if shutil .which ("docker" ) is None :
142
127
session .error ("This session requires Docker to be installed" )
143
128
# If the FRR container version is not set in the environment, use the latest version
144
129
# defined at the top of this file.
145
130
if not session .env .get ("FRR_VERSION" ):
146
131
session .env ["FRR_VERSION" ] = FRR_LATEST_MAJOR_VERSION
147
- session .run (
148
- "pytest" ,
149
- "tests" ,
150
- "-m" ,
151
- "frrouting_daemon_required" ,
152
- "--cov" ,
153
- "--cov-append" ,
154
- * session .posargs ,
132
+ uv_run (
133
+ session ,
134
+ command = "pytest" ,
135
+ args = [
136
+ "tests" ,
137
+ "-m" ,
138
+ "frrouting_daemon_required" ,
139
+ "--cov" ,
140
+ "--cov-append" ,
141
+ * session .posargs ,
142
+ ],
155
143
)
156
-
157
-
158
- @nox .session (python = PYTHON )
159
- def safety (session : nox .Session ) -> None :
160
- """Scan dependencies for known security vulnerabilities using safety."""
161
- session .install ("safety" )
162
- session .run ("pdm" , "export" , "-o" , "requirements.txt" , external = True )
163
- session .run ("safety" , "check" , "--file=requirements.txt" , "--full-report" )
0 commit comments