Skip to content

Commit 878d091

Browse files
committed
trust empty requires dist with modern metadata
1 parent 53bf89a commit 878d091

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

src/poetry/inspection/info.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import pkginfo
1616

17+
from poetry.core.constraints.version import Version
1718
from poetry.core.factory import Factory
1819
from poetry.core.packages.dependency import Dependency
1920
from poetry.core.packages.package import Package
@@ -246,9 +247,18 @@ def _from_distribution(
246247
:param dist: The distribution instance to parse information from.
247248
"""
248249
requirements = None
250+
dynamic_metadata = False
251+
252+
if dist.metadata_version is not None:
253+
metadata_version = Version.parse(dist.metadata_version)
254+
dynamic_metadata_introduced = Version.parse("2.2")
255+
dynamic_metadata = metadata_version >= dynamic_metadata_introduced
249256

250257
if dist.requires_dist:
251258
requirements = list(dist.requires_dist)
259+
elif dynamic_metadata and "Requires-Dist" not in dist.dynamic:
260+
# We can trust the metadata when it says that requires_dist is empty.
261+
requirements = []
252262
else:
253263
requires = Path(dist.filename) / "requires.txt"
254264
if requires.exists():
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Metadata-Version: 2.2
2+
Name: demo
3+
Version: 0.1.0
4+
Summary: Demo project.
5+
Home-page: https://github.com/demo/demo
6+
Author: Sébastien Eustace
7+
Author-email: [email protected]
8+
License: MIT
9+
Description: UNKNOWN
10+
Platform: UNKNOWN
11+
Dynamic: Requires-Dist
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# this was copied over and modified from orjson project's pyproject.toml
2+
# https://github.com/ijl/orjson/blob/master/pyproject.toml
3+
[project]
4+
name = "demo"
5+
repository = "https://github.com/demo/demo"
6+
7+
[build-system]
8+
build-backend = "maturin"
9+
requires = ["maturin>=0.8.1,<0.9"]
10+
11+
[tool.maturin]
12+
manylinux = "off"
13+
sdist-include = ["Cargo.lock", "json/**/*"]
14+
strip = "on"
15+
16+
[tool.black]
17+
line-length = 88
18+
target-version = ['py36', 'py37', 'py38']
19+
include = '\.pyi?$'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Metadata-Version: 2.2
2+
Name: demo
3+
Version: 0.1.0
4+
Summary: Demo project.
5+
Home-page: https://github.com/demo/demo
6+
Author: Sébastien Eustace
7+
Author-email: [email protected]
8+
License: MIT
9+
Description: UNKNOWN
10+
Platform: UNKNOWN
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# this was copied over and modified from orjson project's pyproject.toml
2+
# https://github.com/ijl/orjson/blob/master/pyproject.toml
3+
[project]
4+
name = "demo"
5+
repository = "https://github.com/demo/demo"
6+
7+
[build-system]
8+
build-backend = "maturin"
9+
requires = ["maturin>=0.8.1,<0.9"]
10+
11+
[tool.maturin]
12+
manylinux = "off"
13+
sdist-include = ["Cargo.lock", "json/**/*"]
14+
strip = "on"
15+
16+
[tool.black]
17+
line-length = 88
18+
target-version = ['py36', 'py37', 'py38']
19+
include = '\.pyi?$'

tests/inspection/test_info.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ def test_info_no_setup_pkg_info_no_deps(fixture_dir: FixtureDirGetter) -> None:
261261
assert info.requires_dist is None
262262

263263

264+
def test_info_no_setup_pkg_info_no_deps_for_sure(fixture_dir: FixtureDirGetter) -> None:
265+
info = PackageInfo.from_directory(
266+
fixture_dir("inspection") / "demo_no_setup_pkg_info_no_deps_for_sure",
267+
disable_build=True,
268+
)
269+
assert info.name == "demo"
270+
assert info.version == "0.1.0"
271+
assert info.requires_dist == []
272+
273+
274+
def test_info_no_setup_pkg_info_no_deps_dynamic(fixture_dir: FixtureDirGetter) -> None:
275+
info = PackageInfo.from_directory(
276+
fixture_dir("inspection") / "demo_no_setup_pkg_info_no_deps_dynamic",
277+
disable_build=True,
278+
)
279+
assert info.name == "demo"
280+
assert info.version == "0.1.0"
281+
assert info.requires_dist is None
282+
283+
264284
def test_info_setup_simple(mocker: MockerFixture, demo_setup: Path) -> None:
265285
spy = mocker.spy(VirtualEnv, "run")
266286
info = PackageInfo.from_directory(demo_setup)

0 commit comments

Comments
 (0)