diff --git a/news/1274.bugfix.md b/news/1274.bugfix.md new file mode 100644 index 0000000000000000000000000000000000000000..354d2f4a40796ee1006eacde44b70f2db796b493 --- /dev/null +++ b/news/1274.bugfix.md @@ -0,0 +1 @@ +For packages that are only available as source distribution, the `summary` field in `pdm.lock` contains the `description` from the package's `pyproject.toml`. diff --git a/pdm/models/candidates.py b/pdm/models/candidates.py index 77ced6cab21f1fbd7e6118b80ca822ca49e5c95a..4a52350f98f5e500c002c3d4789beff36722080e 100644 --- a/pdm/models/candidates.py +++ b/pdm/models/candidates.py @@ -443,6 +443,7 @@ class PreparedCandidate: ): setup = Setup( name=metadata.name, + summary=metadata.description, version=metadata.version, install_requires=metadata.dependencies or [], extras_require=metadata.optional_dependencies or {}, diff --git a/pdm/models/setup.py b/pdm/models/setup.py index 1f1bda6cb3a1c962a4dad0a90485dad0b2dd4c12..00da7cb59f87f65b7acf6348fdb964ef3bb38054 100644 --- a/pdm/models/setup.py +++ b/pdm/models/setup.py @@ -1,6 +1,6 @@ import ast from configparser import ConfigParser -from dataclasses import asdict, dataclass, field +from dataclasses import asdict, dataclass, field, fields from pathlib import Path from typing import Any, Dict, Iterable, List, Optional, Tuple, no_type_check @@ -16,18 +16,13 @@ class Setup: install_requires: List[str] = field(default_factory=list) extras_require: Dict[str, List[str]] = field(default_factory=dict) python_requires: Optional[str] = None + summary: Optional[str] = None def update(self, other: "Setup") -> None: - if other.name: - self.name = other.name - if other.version: - self.version = other.version - if other.install_requires: - self.install_requires = other.install_requires - if other.extras_require: - self.extras_require = other.extras_require - if other.python_requires: - self.python_requires = other.python_requires + for f in fields(self): + other_field = getattr(other, f.name) + if other_field: + setattr(self, f.name, other_field) def as_dict(self) -> Dict[str, Any]: return asdict(self) diff --git a/pdm/project/metadata.py b/pdm/project/metadata.py index 5fa1d1f17c532fe0bb2a5dae3dcd66e0f49cb233..65cb87107aae1a8f1083db822ca06b28cafba389 100644 --- a/pdm/project/metadata.py +++ b/pdm/project/metadata.py @@ -76,7 +76,7 @@ class SetupDistribution(Distribution): return { "Name": self._data.name, "Version": self._data.version, - "Summary": "UNKNOWN", + "Summary": self._data.summary, "Requires-Python": self._data.python_requires, } diff --git a/tests/models/test_candidates.py b/tests/models/test_candidates.py index 3e1f3ab011342b65a6240b83ea80bbedde48d203..1fa0d93c46228ed06ca6c85fdd9fdb034a909bc0 100644 --- a/tests/models/test_candidates.py +++ b/tests/models/test_candidates.py @@ -342,8 +342,9 @@ def test_parse_metadata_from_pep621(project, mocker): f"test-hatch @ file://{FIXTURES.as_posix()}/projects/test-hatch-static" ) candidate = Candidate(req) - metadata = candidate.prepare(project.environment).metadata - assert sorted(metadata.requires) == ["click", "requests"] + distribution = candidate.prepare(project.environment).metadata + assert sorted(distribution.requires) == ["click", "requests"] + assert distribution.metadata["Summary"] == "Test hatch project" builder.assert_not_called()