diff options
| -rw-r--r-- | changelog.d/2075.breaking.rst | 1 | ||||
| -rw-r--r-- | pkg_resources/__init__.py | 30 | ||||
| -rw-r--r-- | pkg_resources/tests/test_pkg_resources.py | 8 |
3 files changed, 23 insertions, 16 deletions
diff --git a/changelog.d/2075.breaking.rst b/changelog.d/2075.breaking.rst new file mode 100644 index 00000000..8d88b33f --- /dev/null +++ b/changelog.d/2075.breaking.rst @@ -0,0 +1 @@ +Stop recognizing files ending with ``.dist-info`` as distribution metadata diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 15a4401a..4d15086f 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2056,33 +2056,31 @@ def find_on_path(importer, path_item, only=False): filtered = ( entry for entry in entries - if dist_factory(path_item, entry, only) + if dist_factory(entry, only) ) # scan for .egg and .egg-info in directory path_item_entries = _by_version_descending(filtered) for entry in path_item_entries: fullpath = os.path.join(path_item, entry) - factory = dist_factory(path_item, entry, only) + factory = dist_factory(entry, only) for dist in factory(fullpath): yield dist -def dist_factory(path_item, entry, only): - """ - Return a dist_factory for a path_item and entry - """ +def dist_factory(entry, only): + """Return a dist_factory for the given entry.""" lower = entry.lower() - is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info'))) - return ( - distributions_from_metadata - if is_meta else - find_distributions - if not only and _is_egg_path(entry) else - resolve_egg_link - if not only and lower.endswith('.egg-link') else - NoDists() - ) + if lower.endswith('.egg-info'): + return distributions_from_metadata + elif lower.endswith('.dist-info') and os.path.isdir(entry): + return distributions_from_metadata + elif not only and _is_egg_path(entry): + return find_distributions + elif not only and lower.endswith('.egg-link'): + return resolve_egg_link + else: + return NoDists() class NoDists: diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 78281869..1c66dec0 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -330,6 +330,14 @@ def test_distribution_version_missing_undetected_path(): assert msg == expected +@pytest.mark.parametrize('only', [False, True]) +def test_dist_info_is_not_dir(tmp_path, only): + """Test path containing a file with dist-info extension.""" + dist_info = tmp_path / 'foobar.dist-info' + dist_info.touch() + assert not pkg_resources.dist_factory(str(dist_info), only) + + class TestDeepVersionLookupDistutils: @pytest.fixture def env(self, tmpdir): |
