From 459ec54bacf3cf51b2198e80ab6a087a09ef3da8 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 25 Feb 2024 14:19:08 +0000 Subject: [PATCH] Trust the setup reader when it finds no requirements --- src/poetry/inspection/info.py | 11 ++--------- tests/inspection/test_info.py | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 1c432e29f9b..30983008e9c 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -369,17 +369,10 @@ def from_setup_files(cls, path: Path) -> PackageInfo: name=result.get("name"), version=result.get("version"), summary=result.get("description", ""), - requires_dist=requirements or None, + requires_dist=requirements, requires_python=python_requires, ) - if not (info.name and info.version) and not info.requires_dist: - # there is nothing useful here - raise PackageInfoError( - path, - "No core metadata (name, version, requires-dist) could be retrieved.", - ) - return info @staticmethod @@ -582,7 +575,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo: with contextlib.suppress(PackageInfoError): info = PackageInfo.from_setup_files(path) - if all([info.version, info.name, info.requires_dist]): + if all(x is not None for x in (info.version, info.name, info.requires_dist)): return info with ephemeral_environment( diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index a23e4879769..ef94aee43db 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -318,7 +318,7 @@ def test_info_setup_complex_calls_script(demo_setup_complex_calls_script: Path) @pytest.mark.network -@pytest.mark.parametrize("missing", ["version", "name", "install_requires"]) +@pytest.mark.parametrize("missing", ["version", "name"]) def test_info_setup_missing_mandatory_should_trigger_pep517( mocker: MockerFixture, source_dir: Path, missing: str ) -> None: @@ -326,7 +326,7 @@ def test_info_setup_missing_mandatory_should_trigger_pep517( setup += "setup(" setup += 'name="demo", ' if missing != "name" else "" setup += 'version="0.1.0", ' if missing != "version" else "" - setup += 'install_requires=["package"]' if missing != "install_requires" else "" + setup += 'install_requires=["package"]' setup += ")" setup_py = source_dir / "setup.py" @@ -337,6 +337,24 @@ def test_info_setup_missing_mandatory_should_trigger_pep517( assert spy.call_count == 1 +@pytest.mark.network +def test_info_setup_missing_install_requires_is_fine( + mocker: MockerFixture, source_dir: Path +) -> None: + setup = "from setuptools import setup; " + setup += "setup(" + setup += 'name="demo", ' + setup += 'version="0.1.0", ' + setup += ")" + + setup_py = source_dir / "setup.py" + setup_py.write_text(setup) + + spy = mocker.spy(VirtualEnv, "run") + _ = PackageInfo.from_directory(source_dir) + assert spy.call_count == 0 + + def test_info_prefer_poetry_config_over_egg_info(fixture_dir: FixtureDirGetter) -> None: info = PackageInfo.from_directory( fixture_dir("inspection") / "demo_with_obsolete_egg_info"