提交 9357ec02 编写于 作者: F Frost Ming

fix(#1156): only trust parsing result when all are static

上级 0e395551
......@@ -412,14 +412,25 @@ class PreparedCandidate:
except ValueError:
termui.logger.warn("Failed to parse pyproject.toml")
else:
setup = Setup(
name=metadata.name,
version=metadata.version,
install_requires=metadata.dependencies or [],
extras_require=metadata.optional_dependencies or {},
python_requires=metadata.requires_python or None,
)
return SetupDistribution(setup)
dynamic_fields = metadata.dynamic or []
# Use the parse result only when all are static
if set(dynamic_fields).isdisjoint(
{
"name",
"version",
"dependencies",
"optional-dependencies",
"requires-python",
}
):
setup = Setup(
name=metadata.name,
version=metadata.version,
install_requires=metadata.dependencies or [],
extras_require=metadata.optional_dependencies or {},
python_requires=metadata.requires_python or None,
)
return SetupDistribution(setup)
# If all fail, try building the source to get the metadata
builder = EditableBuilder if self.req.editable else WheelBuilder
try:
......
[build-system]
requires = ["hatchling>=0.15.0"]
build-backend = "hatchling.build"
[project]
name = "test-hatch"
version = "0.1.0"
description = "Test hatch project"
readme = "README.md"
license = "MIT"
requires-python = ">=3.7"
authors = [{ name = "John", email = "john@example.org" }]
classifiers = [
"License :: OSI Approved :: MIT License",
]
dependencies = ["requests", "click"]
......@@ -334,3 +334,24 @@ def test_find_candidates_from_find_links(project):
]
candidates = list(repo.find_candidates(parse_requirement("demo")))
assert len(candidates) == 2
def test_parse_metadata_from_pep621(project, mocker):
builder = mocker.patch("pdm.builders.wheel.WheelBuilder.build")
req = parse_requirement(
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"]
builder.assert_not_called()
def test_parse_metadata_with_dynamic_fields(project, local_finder):
req = parse_requirement(
f"demo-package @ file://{FIXTURES.as_posix()}/projects/demo-src-package"
)
candidate = Candidate(req)
metadata = candidate.prepare(project.environment).metadata
assert not metadata.requires
assert metadata.version == "0.1.0"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册