Skip to content

Commit

Permalink
Search weels for .dist-info directories
Browse files Browse the repository at this point in the history
Some wheels don't use canonicalized names for their .dist-info
directories, so search the wheel for them.

Fixes: pypa#134
  • Loading branch information
stefanor committed Dec 12, 2022
1 parent 49a3540 commit fd6d2ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/installer/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ def open(cls, path: "os.PathLike[str]") -> Iterator["WheelFile"]:
with zipfile.ZipFile(path) as f:
yield cls(f)

@property
def dist_info_dir(self) -> str:
"""Name of the dist-info directory."""
if not hasattr(self, "_dist_info_dir"):
top_level_directories = {
path.split("/", 1)[0] for path in self._zipfile.namelist()
}
dist_infos = [
name for name in top_level_directories if name.endswith(".dist-info")
]
assert (
len(dist_infos) == 1
), "Wheel doesn't contain exactly one .dist-info directory"
self._dist_info_dir = dist_infos[0]
return self._dist_info_dir

@property
def dist_info_filenames(self) -> List[str]:
"""Get names of all files in the dist-info directory."""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def test_provides_correct_contents(self, fancy_wheel):
assert sorted(got_records) == sorted(expected_records)
assert got_files == files

def test_finds_dist_info(self, fancy_wheel):
denorm = fancy_wheel.rename(fancy_wheel.parent / "Fancy-1.0.0-py3-none-any.whl")
with WheelFile.open(denorm) as source:
assert source.dist_info_filenames


def replace_file_in_zip(path: str, filename: str, content: "bytes | None") -> None:
"""Helper function for replacing a file in the zip.
Expand Down

0 comments on commit fd6d2ae

Please sign in to comment.