Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: infinite loop in uv mode #3220

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading