Skip to content

Commit

Permalink
Support .egg installations
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Sottile <[email protected]>
  • Loading branch information
asottile committed May 12, 2019
1 parent eb107b0 commit ef0ce71
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 39 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include *.py MANIFEST.in LICENSE README.rst
global-include *.txt *.rst *.ini *.cfg *.toml *.whl
global-include *.txt *.rst *.ini *.cfg *.toml *.whl *.egg
exclude .gitignore
prune build
prune .tox
30 changes: 0 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,6 @@ tools (or other conforming packages). It does not support:

- Packages in the stdlib.
- Packages installed without metadata.
- Packages installed as eggs.

Eggs
----

Not only does ``importlib_metadata`` not support loading metadata
from eggs, it will crash when it attempts to load metadata for
any package that's an egg.

``easy_install`` creates eggs when installing packages, which is why
you should use ``pip`` to install packages. ``pip`` never installs
eggs. There are some cases, however, where a project's usage
may not be able to avoid ``easy_install``. In particular, if a project
uses ``setup.py test``, any ``install_requires`` of that project that
aren't already installed will be installed using ``easy_install``.
Additionally, any project defining ``setup_requires`` may get those
dependencies installed as eggs if those dependencies aren't met before
setup.py is invoked (for any command).

Because ``importlib_metadata`` doesn't support loading metadata from
eggs and because ``importlib_metadata`` calls itself to get its own version,
simply importing ``importlib_metadata`` will fail if it is installed as an
egg. Any package that incorporates ``importlib_metadata`` (directly
or indirectly) should be prepared to guide its users to tools that avoid
installing eggs (such as `pip <https://pypi.org/project/pip>`_ and
`tox <https://pypi.org/project/tox>`_).

More detail and discussion can be found at
`issue 19 <https://gitlab.com/python-devs/importlib_metadata/issues/19>`_.


Project details
===============
Expand Down
2 changes: 1 addition & 1 deletion importlib_metadata/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MetadataPathFinder(NullFinder):
This finder supplies only a find_distributions() method for versions
of Python that do not have a PathFinder find_distributions().
"""
search_template = r'{pattern}(-.*)?\.(dist|egg)-info'
search_template = r'(?:{pattern}(-.*)?\.(dist|egg)-info|EGG-INFO)'

def find_distributions(self, name=None, path=None):
"""Return an iterable of all Distribution instances capable of
Expand Down
Binary file not shown.
24 changes: 19 additions & 5 deletions importlib_metadata/tests/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
from contextlib2 import ExitStack


class BespokeLoader:
archive = 'bespoke'


class TestZip(unittest.TestCase):
def setUp(self):
# Find the path to the example.*.whl so we can add it to the front of
# Find the path to the example-*.whl so we can add it to the front of
# sys.path, where we'll then try to find the metadata thereof.
self.resources = ExitStack()
self.addCleanup(self.resources.close)
Expand Down Expand Up @@ -48,3 +44,21 @@ def test_files(self):
for file in files('example'):
path = str(file.dist.locate_file(file))
assert '.whl/' in path, path


class TestEgg(TestZip):
def setUp(self):
# Find the path to the example-*.egg so we can add it to the front of
# sys.path, where we'll then try to find the metadata thereof.
self.resources = ExitStack()
self.addCleanup(self.resources.close)
egg = self.resources.enter_context(
path('importlib_metadata.tests.data',
'example-21.12-py3.6.egg'))
sys.path.insert(0, str(egg))
self.resources.callback(sys.path.pop, 0)

def test_files(self):
for file in files('example'):
path = str(file.dist.locate_file(file))
assert '.egg/' in path, path
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ packages = find:
importlib_metadata =
docs/*
docs/_static/*
importlib_metadata.tests.data03 =
namespace/*
importlib_metadata.tests.data =
*.egg
*.whl

[mypy]
ignore_missing_imports = True
Expand Down

0 comments on commit ef0ce71

Please sign in to comment.