linkedin / shiv

shiv is a command line utility for building fully self contained Python zipapps as outlined in PEP 441, but with all their dependencies included.
BSD 2-Clause "Simplified" License
1.75k stars 98 forks source link

zope.event is not packaged properly when installed together with zope.interface #187

Open jankatins opened 3 years ago

jankatins commented 3 years ago

When I package a python package which has a dependency on both zope.event and zope.interface, zope.event is not importable. Example case:

[15:05:06] λ  shiv -o ~/bin/zope_event zope.event zope.interface --upgrade
Collecting zope.event
  Using cached zope.event-4.5.0-py2.py3-none-any.whl (6.8 kB)
Collecting zope.interface
  Using cached zope.interface-5.4.0-cp39-cp39-manylinux2010_x86_64.whl (255 kB)
Collecting setuptools
  Using cached setuptools-57.4.0-py3-none-any.whl (819 kB)
Installing collected packages: setuptools, zope.interface, zope.event
Successfully installed setuptools-57.4.0 zope.event-4.5.0 zope.interface-5.4.0

[15:05:18] λ  echo "import zope.event" | SHIV_INTERPRETER=1 python -S ~/bin/zope_event
Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> Traceback (most recent call last):
  File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'zope.event'
>>>
now exiting InteractiveConsole...

(my original case is packaging https://github.com/Fizzadar/pyinfra/ with shiv -c pyinfra -o ~/bin/pyinfra pyinfra, which has this dependency)

jankatins commented 3 years ago

A guess is here, that this has to do with this warning: WARNING: Target directory /tmp/tmp3upaegzz/zope already exists. Specify --upgrade to force replacement.

[15:40:03] λ  shiv -c pyinfra -o ~/bin/pyinfra pyinfra
[...]
Collecting zope.interface
  Using cached zope.interface-5.4.0-cp39-cp39-manylinux2010_x86_64.whl (255 kB)
[...]
Collecting zope.event
  Using cached zope.event-4.5.0-py2.py3-none-any.whl (6.8 kB)
[...]
Installing collected packages: pycparser, urllib3, idna, charset-normalizer, cffi, certifi, six, setuptools, requests, ntlm-auth, cryptography, zope.interface, zope.event, xmltodict, requests-ntlm, pynacl, MarkupSafe, greenlet, bcrypt, pywinrm, python-dateutil, paramiko, jinja2, gevent, distro, configparser, colorama, click, pyinfra
Successfully installed MarkupSafe-2.0.1 bcrypt-3.2.0 certifi-2021.5.30 cffi-1.14.6 charset-normalizer-2.0.4 click-8.0.1 colorama-0.4.4 configparser-5.0.2 cryptography-3.4.8 distro-1.5.0 gevent-21.8.0 greenlet-1.1.1 idna-3.2 jinja2-3.0.1 ntlm-auth-1.5.0 paramiko-2.7.2 pycparser-2.20 pyinfra-1.4.13 pynacl-1.4.0 python-dateutil-2.8.2 pywinrm-0.4.2 requests-2.26.0 requests-ntlm-1.1.0 setuptools-57.4.0 six-1.16.0 urllib3-1.26.6 xmltodict-0.12.0 zope.event-4.5.0 zope.interface-5.4.0
WARNING: Target directory /tmp/tmp3upaegzz/zope already exists. Specify --upgrade to force replacement.

~  🐍 v3.9.6 (venv:pyinfra) took 15s
[15:40:56] λ  echo "import pyinfra_cli.__main__" | SHIV_INTERPRETER=1 python -S ~/bin/pyinfra
Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/jan.katins/.shiv/pyinfra_f5baa2fed3c7a5873a999e938e17458ffe00447ca7f63a4d058f95d914ffc448/site-packages/pyinfra_cli/__init__.py", line 5, in <module>
    monkey.patch_all()  # noqa
  File "/home/jan.katins/.shiv/pyinfra_f5baa2fed3c7a5873a999e938e17458ffe00447ca7f63a4d058f95d914ffc448/site-packages/gevent/monkey.py", line 1235, in patch_all
    from gevent import events
  File "/home/jan.katins/.shiv/pyinfra_f5baa2fed3c7a5873a999e938e17458ffe00447ca7f63a4d058f95d914ffc448/site-packages/gevent/events.py", line 67, in <module>
    from zope.interface import Interface
ModuleNotFoundError: No module named 'zope.interface'
>>>
now exiting InteractiveConsole...
jankatins commented 3 years ago

Also reported to pip upstream: seems to have something to do with the --target argument: https://github.com/pypa/pip/issues/8505

lorencarvalho commented 3 years ago

Hi @jankatins

Similar to issue #191, I cannot reproduce this myself:

darwin ~ $ shiv -o ~/bin/zope_event zope.event zope.interface --upgrade
Collecting zope.event
  Downloading zope.event-4.5.0-py2.py3-none-any.whl (6.8 kB)
Collecting zope.interface
  Downloading zope.interface-5.4.0-cp38-cp38-macosx_10_14_x86_64.whl (208 kB)
Collecting setuptools
  Using cached setuptools-58.2.0-py3-none-any.whl (946 kB)
Installing collected packages: setuptools, zope.interface, zope.event
Successfully installed setuptools-58.2.0 zope.event-4.5.0 zope.interface-5.4.0

darwin ~ $ ~/bin/zope_event
Python 3.8.10 (default, Oct  5 2021, 13:23:42)
[Clang 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import zope.event
>>> zope.event
<module 'zope.event' from '/Users/lcarvalh/.shiv/zope_event_52cc148a961970319b751e95b87ddae97c96b84adbf6145a8509152011fad622/site-packages/zope/event/__init__.py'>

The warning about a tempdir already existing is very odd, I presume that's coming from pip itself. FWIW I'm using a pyz of shiv which includes pip-21.1.