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

[BUG] pkg_resources does not use dist-info from site-packages.zip #3241

Open
ronaldoussoren opened this issue Apr 3, 2022 · 1 comment
Open
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.

Comments

@ronaldoussoren
Copy link
Contributor

ronaldoussoren commented Apr 3, 2022

setuptools version

setuptools==60.10.0

Python version

Python 3.10

OS

macOS

Additional environment information

The context for this is py2app: Py2app bundles an application on macOS into a ".app" bundle.

Description

As part of the bundling of an application into an .app by py2app the python modules/packages used by the script are copied into a ZIP file that's added on sys.path.

The class pkg_resources.WorkingSet does not use the dist-info information that's included in that zipfile because pkg_resources.WorkingSet.add_entry asks the Finder (in this case find_apps_in_zip) to not look for subitems (the only argument is set to True).

Because of that pkg_resources.iter_entrypoints does not find the entry points of distributions copied into the zipfile.

Related issue in py2app: ronaldoussoren/py2app#413

Expected behavior

I'd expect that the dist-info information that's included in the zipfile is used by pkg_resources.

How to Reproduce

On a macOS system:

  • Create a venv and activate it
  • Install setuptools and humanfriendly
  • Clone the py2app repository (https://github.com/ronaldoussoren/py2app)
  • Patch py2app/recipes/setuptools.py: Remove the "prescripts" from the dict returned by the check function
  • instal py2appl: pip install ./py2app
  • Change directory to examples/Tkinter/hello_tk
  • Open hello.py and replace the last two lines (creating the app object and running the mainloop) by the code below
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")
  • Build the app bundle using python setup.py py2app
  • Start the application using dist/hello.app/Contents/MacOS/hello

What you'll see:

  • The app fails to launch and prints in the Terminal that the EP for humanfriendly is not found.

Expected behaviour:

  • Application starts and immediately stops

Output

See description in the previous step.

@ronaldoussoren ronaldoussoren added bug Needs Triage Issues that need to be evaluated for severity and status. labels Apr 3, 2022
@ronaldoussoren
Copy link
Contributor Author

One way to fix this is to patch find_eggs_in_zip:

  • Don't check for only before the call to metadata.resource_listdir
  • Do check for only before checking if the subitem is an egg, e.g. if not only and _is_egg_path(subitem):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

No branches or pull requests

1 participant