Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg_resources doesn't find entry_points when metadata is in zip folder #413

Closed
mrclary opened this issue Mar 25, 2022 · 4 comments
Closed

Comments

@mrclary
Copy link

mrclary commented Mar 25, 2022

I use py2app in the spyder-ide/spyder project to bundle its macOS application, and recently updated the use of py2app from 0.22 to 0.27. I now see that pkg_resources included in its application does not find entry points for packages included in the application bundle if the metadata (egg/dist-info) is located in the pythonXX.zip directory.

This may be a bug/feature of pkg_resources, since for 0.22 I copied the metadata to the pythonX.X directory after app bundle creation; I may have been inadvertently avoiding this issue.

@ronaldoussoren, now that py2app handles the metadata, what is the best way to resolve this issue?

For example, the entry points found for pkg_resources.iter_entry_points('console_scripts') are ['keyring', 'watchmedo']. However, after extracting the zip archive in the bundle app and renaming to pythonXX.zip (so not a real archive directory, but in sys.path), the found entry points are ['keyring', 'black', 'black-primer', 'blackd', 'coloredlogs', 'humanfriendly', 'iptest', 'iptest3', 'ipython', 'ipython3', 'jupyter-kernel', 'jupyter-kernelspec', 'jupyter-run', 'jupyter-dejavu', 'jupyter-nbconvert', 'pydocstyle', 'pylupdate5', 'pyrcc5', 'pyuic5', 'isort', 'isort-identify-imports', 'jupyter-trust', 'fonttools', 'pyftmerge', 'pyftsubset', 'ttx', 'jupyter', 'jupyter-migrate', 'jupyter-troubleshoot', 'sphinx-apidoc', 'sphinx-autogen', 'sphinx-build', 'sphinx-quickstart', 'jsonschema', 'flake8', 'chardetect', 'epylint', 'pylint', 'pyreverse', 'symilar', 'pygmentize', 'pybabel', 'pycodestyle', 'pyflakes', 'watchmedo', 'normalizer', 'f2py', 'f2py3', 'f2py3.9', 'isympy', 'cookiecutter', 'autopep8', 'qta-browser', 'yapf', 'yapf-diff', 'cygdb', 'cython', 'cythonize', 'jupyter-execute']

@ronaldoussoren
Copy link
Owner

The easiest way I found to reproduce this:

Add the following code before starting the runloop in examples/Tkinter/hello_tk/hello.py:

import humanfriendly
import pkg_resources
for ep in pkg_resources.iter_entry_points("console_scripts"):
    if ep.dist.project_name == "humanfriendly":
        break
else:
    raise RuntimeError("EP for humanfriendly not found")

This fails even though the required files are present in python310.zip:

% unzip -t dist/hello.app/Contents/Resources/lib/python310.zip| grep human                                                                                           (master)py2app
    testing: humanfriendly-10.0.dist-info/   OK
    testing: humanfriendly-10.0.dist-info/WHEEL   OK
    testing: humanfriendly-10.0.dist-info/entry_points.txt   OK
    testing: humanfriendly-10.0.dist-info/top_level.txt   OK
    testing: humanfriendly-10.0.dist-info/LICENSE.txt   OK
    testing: humanfriendly-10.0.dist-info/REQUESTED   OK
    testing: humanfriendly-10.0.dist-info/INSTALLER   OK
    testing: humanfriendly-10.0.dist-info/METADATA   OK
    testing: humanfriendly/           OK
    testing: humanfriendly/__init__.pyc   OK
    testing: humanfriendly/text.pyc   OK
    testing: humanfriendly/deprecation.pyc   OK
    testing: humanfriendly/compat.pyc   OK

@ronaldoussoren
Copy link
Owner

The problem is that pkg_resources isn't expecting to find a zipped-up folder with site-packages on sys.path, the initialiser for pkg_resources.WorkingSet calls find_distributions with True for the last argument and because of that the support code for zipimporter doesn't look metadata in the zipfile.

I've filed an issue with setuptools and am looking for a workaround on my side.

ronaldoussoren added a commit that referenced this issue Apr 3, 2022
This is a workaround for #413, hopefully this will get fixed
in setuptools.
@ronaldoussoren
Copy link
Owner

aa56a19 contains a workaround for this issue, it monkey patches pkg_resources to do the right thing for py2app's pythonXX.zip. I'll add a version check if this gets fixed in setuptools.

@ronaldoussoren
Copy link
Owner

Closing this issue because I have a workaround in py2app, I'll reconsider if/when this gets fixed in pkg_resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants