1111from __future__ import annotations
1212
1313import argparse
14+ import contextlib
1415import os
1516import shutil
17+ import tempfile
1618from typing import TYPE_CHECKING
1719
1820import nox
1921
2022if TYPE_CHECKING :
21- from collections .abc import Sequence
23+ from collections .abc import Generator , Sequence
2224
2325
2426nox .needs_version = ">=2024.3.2"
3537 nox .options .error_on_missing_interpreters = True
3638
3739
40+ @contextlib .contextmanager
41+ def preserve_lockfile () -> Generator [None ]:
42+ """Preserve the lockfile by moving it to a temporary directory."""
43+ with tempfile .TemporaryDirectory () as temp_dir_name :
44+ shutil .move ("uv.lock" , f"{ temp_dir_name } /uv.lock" )
45+ try :
46+ yield
47+ finally :
48+ shutil .move (f"{ temp_dir_name } /uv.lock" , "uv.lock" )
49+
50+
3851@nox .session (reuse_venv = True )
3952def lint (session : nox .Session ) -> None :
4053 """Run the linter."""
@@ -64,7 +77,6 @@ def _run_tests(
6477 "--no-dev" ,
6578 "--group" ,
6679 "test" ,
67- "--frozen" ,
6880 * install_args ,
6981 "pytest" ,
7082 * pytest_run_args ,
@@ -83,14 +95,14 @@ def tests(session: nox.Session) -> None:
8395@nox .session (reuse_venv = True , venv_backend = "uv" , python = PYTHON_ALL_VERSIONS )
8496def minimums (session : nox .Session ) -> None :
8597 """Test the minimum versions of dependencies."""
86- _run_tests (
87- session ,
88- install_args = [ "--resolution=lowest-direct" ] ,
89- pytest_run_args = ["-Wdefault " ],
90- )
91- env = { "UV_PROJECT_ENVIRONMENT" : session . virtualenv . location }
92- session . run ( "uv" , "tree" , "--frozen" , env = env )
93- session .run ("uv" , "lock " , "--refresh " , env = env )
98+ with preserve_lockfile ():
99+ _run_tests (
100+ session ,
101+ install_args = ["--resolution=lowest-direct " ],
102+ pytest_run_args = [ "-Wdefault" ],
103+ )
104+ env = { "UV_PROJECT_ENVIRONMENT" : session . virtualenv . location }
105+ session .run ("uv" , "tree " , "--frozen " , env = env )
94106
95107
96108@nox .session (reuse_venv = True , venv_backend = "uv" , python = PYTHON_ALL_VERSIONS )
0 commit comments