Skip to content

Commit

Permalink
Trust the setup reader when it finds no requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and abn committed Feb 25, 2024
1 parent e6910f3 commit 5223b2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
11 changes: 2 additions & 9 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 20 additions & 2 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ 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:
setup = "from setuptools import setup; "
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"
Expand All @@ -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"
Expand Down

0 comments on commit 5223b2b

Please sign in to comment.