[BUG] pkg_resources does not use dist-info from site-packages.zip
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
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: https://github.com/ronaldoussoren/py2app/issues/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
setuptoolsandhumanfriendly - Clone the py2app repository (https://github.com/ronaldoussoren/py2app)
- Patch
py2app/recipes/setuptools.py: Remove the"prescripts"from the dict returned by thecheckfunction - instal py2appl:
pip install ./py2app - Change directory to
examples/Tkinter/hello_tk - Open
hello.pyand 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with pkg_resources.WorkingSet.add_entry and the find_apps_in_zip finder, focusing on how the only argument controls scanning of site-packages.zip. Reproduce the macOS py2app example using the provided humanfriendly console_scripts check. Done means pkg_resources.iter_entrypoints finds humanfriendly from the dist-info data inside the ZIP.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100