From 65f0728c555f1dc4f3d00a2ac7847d23272e6555 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Thu, 29 Feb 2024 21:48:44 +0000 Subject: [PATCH] trust empty requires dist with modern metadata --- src/poetry/inspection/info.py | 10 ++++++++++ .../PKG-INFO | 11 ++++++++++ .../pyproject.toml | 19 ++++++++++++++++++ .../PKG-INFO | 10 ++++++++++ .../pyproject.toml | 19 ++++++++++++++++++ .../PKG-INFO | 8 ++++++++ .../SOURCES.txt | 8 ++++++++ .../dependency_links.txt | 1 + .../requires.txt | 2 ++ .../top_level.txt | 1 + tests/inspection/test_info.py | 20 +++++++++++++++++++ 11 files changed, 109 insertions(+) create mode 100644 tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/PKG-INFO create mode 100644 tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/pyproject.toml create mode 100644 tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/PKG-INFO create mode 100644 tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/pyproject.toml create mode 100644 tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/PKG-INFO create mode 100644 tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/SOURCES.txt create mode 100644 tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/dependency_links.txt create mode 100644 tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/requires.txt create mode 100644 tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/top_level.txt diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 30983008e9c..6b6b370d1ce 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -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 @@ -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(): diff --git a/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/PKG-INFO b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/PKG-INFO new file mode 100644 index 00000000000..325d14b3bf9 --- /dev/null +++ b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/PKG-INFO @@ -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 diff --git a/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/pyproject.toml b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/pyproject.toml new file mode 100644 index 00000000000..0f09fb96fc4 --- /dev/null +++ b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_dynamic/pyproject.toml @@ -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?$' diff --git a/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/PKG-INFO b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/PKG-INFO new file mode 100644 index 00000000000..276e07cea6c --- /dev/null +++ b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/PKG-INFO @@ -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 diff --git a/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/pyproject.toml b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/pyproject.toml new file mode 100644 index 00000000000..0f09fb96fc4 --- /dev/null +++ b/tests/fixtures/inspection/demo_no_setup_pkg_info_no_deps_for_sure/pyproject.toml @@ -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?$' diff --git a/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/PKG-INFO b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/PKG-INFO new file mode 100644 index 00000000000..aeec456af21 --- /dev/null +++ b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/PKG-INFO @@ -0,0 +1,8 @@ +Metadata-Version: 2.1 +Name: project-with-setup-calls-script +Version: 0.1.2 +Summary: Demo project. +Home-page: https://github.com/demo/demo +Author: Sébastien Eustace +Author-email: sebastien@eustace.io +License: MIT diff --git a/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/SOURCES.txt b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/SOURCES.txt new file mode 100644 index 00000000000..29195b422b3 --- /dev/null +++ b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/SOURCES.txt @@ -0,0 +1,8 @@ +pyproject.toml +setup.py +my_package/__init__.py +project_with_setup_calls_script.egg-info/PKG-INFO +project_with_setup_calls_script.egg-info/SOURCES.txt +project_with_setup_calls_script.egg-info/dependency_links.txt +project_with_setup_calls_script.egg-info/requires.txt +project_with_setup_calls_script.egg-info/top_level.txt \ No newline at end of file diff --git a/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/dependency_links.txt b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/dependency_links.txt new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/requires.txt b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/requires.txt new file mode 100644 index 00000000000..eeb0a4815ce --- /dev/null +++ b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/requires.txt @@ -0,0 +1,2 @@ +pendulum>=1.4.4 +cachy[msgpack]>=0.2.0 diff --git a/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/top_level.txt b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/top_level.txt new file mode 100644 index 00000000000..5d04b540bc9 --- /dev/null +++ b/tests/fixtures/project_with_setup_calls_script/project_with_setup_calls_script.egg-info/top_level.txt @@ -0,0 +1 @@ +my_package diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index ef94aee43db..5d065f0b650 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -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)