未验证 提交 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:
):
setup = Setup(
name=metadata.name,
summary=metadata.description,
version=metadata.version,
install_requires=metadata.dependencies or [],
extras_require=metadata.optional_dependencies or {},
......
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)
......
......@@ -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,
}
......
......@@ -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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册