diff --git a/src/pdm/formats/uv.py b/src/pdm/formats/uv.py index e2164d68e6..b85173ab6a 100644 --- a/src/pdm/formats/uv.py +++ b/src/pdm/formats/uv.py @@ -65,7 +65,11 @@ def build_pyproject_toml(self) -> Path: def _enter_path(self, path: Path) -> Path: if path.exists(): backup = path.rename(path.with_name(f"{path.name}.bak")) - self.stack.callback(backup.rename, path) + + @self.stack.callback + def restore() -> None: + path.unlink(True) + backup.rename(path) else: self.stack.callback(path.unlink, True) return path diff --git a/tests/resolver/test_uv_resolver.py b/tests/resolver/test_uv_resolver.py index a28543f1fe..dd6812d1b3 100644 --- a/tests/resolver/test_uv_resolver.py +++ b/tests/resolver/test_uv_resolver.py @@ -44,11 +44,11 @@ def test_resolve_vcs_requirement(project): def test_resolve_with_python_requires(project): requirements = ["urllib3<2; python_version<'3.10'", "urllib3>=2; python_version>='3.10'"] - - resolution = resolve(project.environment, requirements, EnvSpec.from_spec(">=3.10")) - packages = list(resolution.packages) - assert len(packages) == 1 - assert packages[0].candidate.version.startswith("2.") + if project.python.version_tuple >= (3, 10): + resolution = resolve(project.environment, requirements, EnvSpec.from_spec(">=3.10")) + packages = list(resolution.packages) + assert len(packages) == 1 + assert packages[0].candidate.version.startswith("2.") resolution = resolve(project.environment, requirements, EnvSpec.from_spec(">=3.8")) packages = list(resolution.packages)