Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 8682 #8692

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def _from_distribution(
else:
requires = Path(dist.filename) / "requires.txt"
if requires.exists():
with requires.open(encoding="utf-8") as f:
requirements = parse_requires(f.read())
text = requires.read_text(encoding="utf-8")
requirements = parse_requires(text)

info = cls(
name=dist.name,
Expand All @@ -274,16 +274,13 @@ def _from_sdist_file(cls, path: Path) -> PackageInfo:
"""
info = None

try:
info = cls._from_distribution(pkginfo.SDist(str(path)))
except ValueError:
# Unable to determine dependencies
# We pass and go deeper
pass
else:
if info.requires_dist is not None:
# we successfully retrieved dependencies from sdist metadata
return info
with contextlib.suppress(ValueError):
sdist = pkginfo.SDist(str(path))
info = cls._from_distribution(sdist)

if info is not None and info.requires_dist is not None:
# we successfully retrieved dependencies from sdist metadata
return info

# Still not dependencies found
# So, we unpack and introspect
Expand Down Expand Up @@ -313,6 +310,8 @@ def _from_sdist_file(cls, path: Path) -> PackageInfo:

# now this is an unpacked directory we know how to deal with
new_info = cls.from_directory(path=sdist_dir)
new_info._source_type = "file"
new_info._source_url = path.resolve().as_posix()

if not info:
return new_info
Expand Down Expand Up @@ -518,7 +517,8 @@ def from_wheel(cls, path: Path) -> PackageInfo:
:param path: Path to wheel.
"""
try:
return cls._from_distribution(pkginfo.Wheel(str(path)))
wheel = pkginfo.Wheel(str(path))
return cls._from_distribution(wheel)
except ValueError:
return PackageInfo()

Expand All @@ -529,14 +529,12 @@ def from_bdist(cls, path: Path) -> PackageInfo:

:param path: Path to bdist.
"""
if isinstance(path, (pkginfo.BDist, pkginfo.Wheel)):
cls._from_distribution(dist=path)

if path.suffix == ".whl":
return cls.from_wheel(path=path)

try:
return cls._from_distribution(pkginfo.BDist(str(path)))
bdist = pkginfo.BDist(str(path))
return cls._from_distribution(bdist)
except ValueError as e:
raise PackageInfoError(path, e)

Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,30 @@ def demo_check_info(info: PackageInfo, requires_dist: set[str] | None = None) ->
def test_info_from_sdist(demo_sdist: Path) -> None:
info = PackageInfo.from_sdist(demo_sdist)
demo_check_info(info)
assert info._source_type == "file"
assert info._source_url == demo_sdist.resolve().as_posix()


def test_info_from_sdist_no_pkg_info(fixture_dir: FixtureDirGetter) -> None:
path = fixture_dir("distributions") / "demo_no_pkg_info-0.1.0.tar.gz"
info = PackageInfo.from_sdist(path)
demo_check_info(info)
assert info._source_type == "file"
assert info._source_url == path.resolve().as_posix()


def test_info_from_wheel(demo_wheel: Path) -> None:
info = PackageInfo.from_wheel(demo_wheel)
demo_check_info(info)
assert info._source_type == "file"
assert info._source_url == demo_wheel.resolve().as_posix()


def test_info_from_bdist(demo_wheel: Path) -> None:
info = PackageInfo.from_bdist(demo_wheel)
demo_check_info(info)
assert info._source_type == "file"
assert info._source_url == demo_wheel.resolve().as_posix()


def test_info_from_poetry_directory(fixture_dir: FixtureDirGetter) -> None:
Expand Down