Skip to content

Commit

Permalink
trust empty requires dist with modern metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Feb 29, 2024
1 parent 53bf89a commit 878d091
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import pkginfo

from poetry.core.constraints.version import Version
from poetry.core.factory import Factory
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
Expand Down Expand Up @@ -246,9 +247,18 @@ def _from_distribution(
:param dist: The distribution instance to parse information from.
"""
requirements = None
dynamic_metadata = False

if dist.metadata_version is not None:
metadata_version = Version.parse(dist.metadata_version)
dynamic_metadata_introduced = Version.parse("2.2")
dynamic_metadata = metadata_version >= dynamic_metadata_introduced

if dist.requires_dist:
requirements = list(dist.requires_dist)
elif dynamic_metadata and "Requires-Dist" not in dist.dynamic:
# We can trust the metadata when it says that requires_dist is empty.
requirements = []
else:
requires = Path(dist.filename) / "requires.txt"
if requires.exists():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Metadata-Version: 2.2
Name: demo
Version: 0.1.0
Summary: Demo project.
Home-page: https://github.com/demo/demo
Author: Sébastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
Dynamic: Requires-Dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# this was copied over and modified from orjson project's pyproject.toml
# https://github.com/ijl/orjson/blob/master/pyproject.toml
[project]
name = "demo"
repository = "https://github.com/demo/demo"

[build-system]
build-backend = "maturin"
requires = ["maturin>=0.8.1,<0.9"]

[tool.maturin]
manylinux = "off"
sdist-include = ["Cargo.lock", "json/**/*"]
strip = "on"

[tool.black]
line-length = 88
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Metadata-Version: 2.2
Name: demo
Version: 0.1.0
Summary: Demo project.
Home-page: https://github.com/demo/demo
Author: Sébastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# this was copied over and modified from orjson project's pyproject.toml
# https://github.com/ijl/orjson/blob/master/pyproject.toml
[project]
name = "demo"
repository = "https://github.com/demo/demo"

[build-system]
build-backend = "maturin"
requires = ["maturin>=0.8.1,<0.9"]

[tool.maturin]
manylinux = "off"
sdist-include = ["Cargo.lock", "json/**/*"]
strip = "on"

[tool.black]
line-length = 88
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
20 changes: 20 additions & 0 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ def test_info_no_setup_pkg_info_no_deps(fixture_dir: FixtureDirGetter) -> None:
assert info.requires_dist is None


def test_info_no_setup_pkg_info_no_deps_for_sure(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_directory(
fixture_dir("inspection") / "demo_no_setup_pkg_info_no_deps_for_sure",
disable_build=True,
)
assert info.name == "demo"
assert info.version == "0.1.0"
assert info.requires_dist == []


def test_info_no_setup_pkg_info_no_deps_dynamic(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_directory(
fixture_dir("inspection") / "demo_no_setup_pkg_info_no_deps_dynamic",
disable_build=True,
)
assert info.name == "demo"
assert info.version == "0.1.0"
assert info.requires_dist is None


def test_info_setup_simple(mocker: MockerFixture, demo_setup: Path) -> None:
spy = mocker.spy(VirtualEnv, "run")
info = PackageInfo.from_directory(demo_setup)
Expand Down

0 comments on commit 878d091

Please sign in to comment.