diff --git a/changelog.d/2489.change.rst b/changelog.d/2489.change.rst new file mode 100644 index 0000000000..40eddbe734 --- /dev/null +++ b/changelog.d/2489.change.rst @@ -0,0 +1,2 @@ +``pkg_resources`` behavior for zipimport now matches the regular behavior, and finds +``.egg-info`` (previoulsy would only find ``.dist-info``) -- by :user:`thatch` diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index b58f29375c..73f8545967 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1981,12 +1981,13 @@ def find_eggs_in_zip(importer, path_item, only=False): # don't yield nested distros return for subitem in metadata.resource_listdir(''): + lower = subitem.lower() if _is_egg_path(subitem): subpath = os.path.join(path_item, subitem) dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath) for dist in dists: yield dist - elif subitem.lower().endswith('.dist-info'): + elif subitem.lower().endswith(('.dist-info', '.egg-info')): subpath = os.path.join(path_item, subitem) submeta = EggMetadata(zipimport.zipimporter(subpath)) submeta.egg_info = subpath diff --git a/pkg_resources/tests/data/my-test-package-zip/my-test-package.zip b/pkg_resources/tests/data/my-test-package-zip/my-test-package.zip new file mode 100644 index 0000000000..81f9a0170f Binary files /dev/null and b/pkg_resources/tests/data/my-test-package-zip/my-test-package.zip differ diff --git a/pkg_resources/tests/test_find_distributions.py b/pkg_resources/tests/test_find_distributions.py index f9594422f2..b01b4827a7 100644 --- a/pkg_resources/tests/test_find_distributions.py +++ b/pkg_resources/tests/test_find_distributions.py @@ -32,3 +32,12 @@ def test_zipped_egg(self, target_dir): assert [dist.project_name for dist in dists] == ['my-test-package'] dists = pkg_resources.find_distributions(str(target_dir), only=True) assert not list(dists) + + def test_zipped_sdist_one_level_removed(self, target_dir): + (TESTS_DATA_DIR / 'my-test-package-zip').copy(target_dir) + dists = pkg_resources.find_distributions( + str(target_dir / "my-test-package.zip")) + assert [dist.project_name for dist in dists] == ['my-test-package'] + dists = pkg_resources.find_distributions( + str(target_dir / "my-test-package.zip"), only=True) + assert not list(dists)