summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2020-04-24 22:34:10 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2020-04-24 22:39:54 +0700
commitd11428b1cc059ff6aa0ddec0bd8354a1df68d752 (patch)
treee5d7a2d4b3c09934f749f6cea8336513a177507b /pkg_resources
parent92ca9eab30e1aececf4243d9a928cfe63f7dcfc9 (diff)
downloadpython-setuptools-git-d11428b1cc059ff6aa0ddec0bd8354a1df68d752.tar.gz
Stop recognizing files ending with .dist-info as dist
As proposed in PEP 376, dist-info distributions must be directories.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py30
-rw-r--r--pkg_resources/tests/test_pkg_resources.py8
2 files changed, 22 insertions, 16 deletions
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):