未验证 提交 b89e2bed 编写于 作者: S Simon Leiner 提交者: GitHub

fix: Use description field from PEP 621 as summary (#1275)

* fix: Use description field from PEP 621 as summary

The "description" field corresponds to the core metadata "Summary"
field.

This fixes issue #1274.

See:
https://peps.python.org/pep-0621/#description
https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#description

* Setup.update(): Do not hardcode all fields
上级 6e00a5a4
For packages that are only available as source distribution, the `summary` field in `pdm.lock` contains the `description` from the package's `pyproject.toml`.
...@@ -443,6 +443,7 @@ class PreparedCandidate: ...@@ -443,6 +443,7 @@ class PreparedCandidate:
): ):
setup = Setup( setup = Setup(
name=metadata.name, name=metadata.name,
summary=metadata.description,
version=metadata.version, version=metadata.version,
install_requires=metadata.dependencies or [], install_requires=metadata.dependencies or [],
extras_require=metadata.optional_dependencies or {}, extras_require=metadata.optional_dependencies or {},
......
import ast import ast
from configparser import ConfigParser from configparser import ConfigParser
from dataclasses import asdict, dataclass, field from dataclasses import asdict, dataclass, field, fields
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Tuple, no_type_check from typing import Any, Dict, Iterable, List, Optional, Tuple, no_type_check
...@@ -16,18 +16,13 @@ class Setup: ...@@ -16,18 +16,13 @@ class Setup:
install_requires: List[str] = field(default_factory=list) install_requires: List[str] = field(default_factory=list)
extras_require: Dict[str, List[str]] = field(default_factory=dict) extras_require: Dict[str, List[str]] = field(default_factory=dict)
python_requires: Optional[str] = None python_requires: Optional[str] = None
summary: Optional[str] = None
def update(self, other: "Setup") -> None: def update(self, other: "Setup") -> None:
if other.name: for f in fields(self):
self.name = other.name other_field = getattr(other, f.name)
if other.version: if other_field:
self.version = other.version setattr(self, f.name, other_field)
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
def as_dict(self) -> Dict[str, Any]: def as_dict(self) -> Dict[str, Any]:
return asdict(self) return asdict(self)
......
...@@ -76,7 +76,7 @@ class SetupDistribution(Distribution): ...@@ -76,7 +76,7 @@ class SetupDistribution(Distribution):
return { return {
"Name": self._data.name, "Name": self._data.name,
"Version": self._data.version, "Version": self._data.version,
"Summary": "UNKNOWN", "Summary": self._data.summary,
"Requires-Python": self._data.python_requires, "Requires-Python": self._data.python_requires,
} }
......
...@@ -342,8 +342,9 @@ def test_parse_metadata_from_pep621(project, mocker): ...@@ -342,8 +342,9 @@ def test_parse_metadata_from_pep621(project, mocker):
f"test-hatch @ file://{FIXTURES.as_posix()}/projects/test-hatch-static" f"test-hatch @ file://{FIXTURES.as_posix()}/projects/test-hatch-static"
) )
candidate = Candidate(req) candidate = Candidate(req)
metadata = candidate.prepare(project.environment).metadata distribution = candidate.prepare(project.environment).metadata
assert sorted(metadata.requires) == ["click", "requests"] assert sorted(distribution.requires) == ["click", "requests"]
assert distribution.metadata["Summary"] == "Test hatch project"
builder.assert_not_called() builder.assert_not_called()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册