Skip to content

Commit

Permalink
Distribution.files: Only return files that actually exist
Browse files Browse the repository at this point in the history
Add an extra filter on the paths returned from Distribution.files, to
prevent paths that don't exist on the filesystem from being returned.

This attempts to solve the issue of .files returning incorrect
information based on the inaccuracies of SOURCES.txt.

As the code currently is organized, it is more complicated to write
this such that it only applies to the information read from SOURCES.txt
specifically, hence we apply it to _all_ of .files instead.

This fixes python#115, also in the case where there is no installed-files.txt
file available.

[1]: https://pip.pypa.io/en/stable/news/#v0-3
[2]: https://setuptools.pypa.io/en/latest/deprecated/python_eggs.html#sources-txt-source-files-manifest
  • Loading branch information
jherland committed Mar 11, 2023
1 parent 8026db2 commit 22d9ea5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,12 @@ def make_file(name, hash=None, size_str=None):

@pass_none
def make_files(lines):
return list(starmap(make_file, csv.reader(lines)))
return list(
filter(
lambda package_path: package_path.locate().exists(),
list(starmap(make_file, csv.reader(lines))),
)
)

return make_files(
self._read_files_distinfo()
Expand Down

0 comments on commit 22d9ea5

Please sign in to comment.