Skip to content

Commit

Permalink
fix: infinite loop in uv mode (#3220)
Browse files Browse the repository at this point in the history
* fix: infinite loop in uv mode
Fixes #3207

Signed-off-by: Frost Ming <[email protected]>

* fix: uv install include self

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Oct 18, 2024
1 parent 368ccbe commit 21c5aa9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions news/3207.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the infinite loop when running in uv mode if the current project has dynamic metadata.
17 changes: 11 additions & 6 deletions src/pdm/formats/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def restore() -> None:
self.stack.callback(path.unlink, True)
return path

def build_uv_lock(self) -> Path:
def build_uv_lock(self, include_self: bool = False) -> Path:
locked_repo = self.locked_repository
packages: list[dict[str, Any]] = []
for key in locked_repo.packages:
Expand All @@ -89,13 +89,16 @@ def build_uv_lock(self) -> Path:
packages.append(self._build_lock_entry(related_packages))
if name := self.project.name:
version = self.project.pyproject.metadata.get("version", "0.0.0")
this_package = {"name": normalize_name(name), "version": version, "source": {"editable": "."}}
this_package = {
"name": normalize_name(name),
"version": version,
"source": {"editable" if include_self else "virtual": "."},
}
dependencies: list[dict[str, Any]] = []
optional_dependencies: dict[str, list[dict[str, Any]]] = {}
this_candidate = self.project.make_self_candidate(True)
for req in self.requirements:
group = req.groups[0]
if (dep := self._make_dependency(this_candidate, req)) is None:
if (dep := self._make_dependency(None, req)) is None:
continue
if group == "default":
dependencies.append(dep)
Expand Down Expand Up @@ -189,9 +192,11 @@ def _build_lock_entry(self, packages: list[Package]) -> dict[str, Any]:
result["optional-dependencies"] = optional_dependencies
return result

def _make_dependency(self, candidate: Candidate, req: Requirement) -> dict[str, Any] | None:
def _make_dependency(self, parent: Candidate | None, req: Requirement) -> dict[str, Any] | None:
locked_repo = self.locked_repository
parent_marker = (req.marker or get_marker("")) & (candidate.req.marker or get_marker(""))
parent_marker = req.marker or get_marker("")
if parent is not None:
parent_marker &= parent.req.marker or get_marker("")
matching_entries = [e for k, e in locked_repo.packages.items() if k[0] == req.key]

def marker_match(marker: Marker | None) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/installers/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def synchronize(self) -> None:
self.environment.project, str(self.environment.python_requires), self.requirements, self.locked_repo
) as builder:
builder.build_pyproject_toml()
builder.build_uv_lock()
builder.build_uv_lock(include_self=self.install_self)
cmd = self._get_sync_command()
self.environment.project.core.ui.echo(f"Running uv sync command: {cmd}", verbosity=Verbosity.DETAIL)
subprocess.run(cmd, check=True, cwd=self.environment.project.root)
Expand Down

0 comments on commit 21c5aa9

Please sign in to comment.