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

pex shadows pkg_resources, which can break newer versions of setuptools #437

Closed
kwlzn opened this issue Dec 11, 2017 · 2 comments · Fixed by #542
Closed

pex shadows pkg_resources, which can break newer versions of setuptools #437

kwlzn opened this issue Dec 11, 2017 · 2 comments · Fixed by #542
Assignees
Labels

Comments

@kwlzn
Copy link
Contributor

kwlzn commented Dec 11, 2017

with a version of setuptools inside pex's allowed range:

[omerta pants (kwlzn/pantsd_bugfixes)]$ pex "setuptools<34"
Python 2.7.10 (default, Dec 16 2015, 14:09:45) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from setuptools.sandbox import run_setup
>>> 

with a newer one:

[omerta pants (kwlzn/pantsd_bugfixes)]$ pex setuptools==36.2.7
Python 2.7.10 (default, Dec 16 2015, 14:09:45) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from setuptools.sandbox import run_setup
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/private/var/folders/bb/msvj_4_s741g93nzgrj19twc0000gn/T/tmp1zkDfP/.deps/setuptools-36.2.7-py2.py3-none-any.whl/setuptools/sandbox.py", line 15, in <module>
    import pkg_resources.py31compat
ImportError: No module named py31compat
>>> 

because:

>>> import pkg_resources
>>> pkg_resources.__file__
'/private/var/folders/bb/msvj_4_s741g93nzgrj19twc0000gn/T/tmpsTSy8w/.bootstrap/pkg_resources/__init__.pyc'
>>> 

poc:

[omerta pants (kwlzn/pantsd_bugfixes)]$ pex setuptools==36.2.7
Python 2.7.10 (default, Dec 16 2015, 14:09:45) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import sys
>>> sys.path
['/private/var/folders/bb/msvj_4_s741g93nzgrj19twc0000gn/T/tmpCoO7yi/.bootstrap', '/var/folders/bb/msvj_4_s741g93nzgrj19twc0000gn/T/tmpCoO7yi', '/opt/ee/python/2.7/lib/python27.zip', '/opt/ee/python/2.7/lib/python2.7', '/opt/ee/python/2.7/lib/python2.7/plat-darwin', '/opt/ee/python/2.7/lib/python2.7/plat-mac', '/opt/ee/python/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/opt/ee/python/2.7/lib/python2.7/lib-tk', '/opt/ee/python/2.7/lib/python2.7/lib-old', '/opt/ee/python/2.7/lib/python2.7/lib-dynload', '/private/var/folders/bb/msvj_4_s741g93nzgrj19twc0000gn/T/tmpCoO7yi/.deps/setuptools-36.2.7-py2.py3-none-any.whl']
>>> sys.path.insert(0, sys.path[-1])
>>> del sys.modules['pkg_resources']
>>> from setuptools.sandbox import run_setup
>>> 
@kwlzn kwlzn added the bug label Dec 11, 2017
@jsirois
Copy link
Member

jsirois commented Aug 18, 2018

We probably need to vendor our .bootstrap/ code up to and including pex itself on the off chance a user wants to create a pex of their own code that uses pex as a library.

@jsirois
Copy link
Member

jsirois commented Aug 19, 2018

Or... delegate to the final picked runner in a contextmanager that removes .bootstrap from the sys.path and the re-adds it on exit so pex exit handlers - if any can run - which is the POC above. I'll try this first.

@jsirois jsirois self-assigned this Aug 19, 2018
jsirois added a commit to jsirois/pex that referenced this issue Aug 20, 2018
Previously we polluted the third party import space with any third
party dependencies of the pex bootstrap code (currently a subset of
setuptools). We now unimport all third_party code in bootstrap and
place bootstrap at the end of `sys.path` before handing off to user
code to allow their custom versions of overlapping third party code
to be imported.

Added a failing test that the demoted_bootstrap code now fixes.

Fixes pex-tool#437.
jsirois added a commit to jsirois/pex that referenced this issue Aug 24, 2018
Previously we polluted the third party import space with any third
party dependencies of the pex bootstrap code (currently a subset of
setuptools). We now unimport all third_party code in bootstrap and
place bootstrap at the end of `sys.path` before handing off to user
code to allow their custom versions of overlapping third party code
to be imported.

Added a failing test that the demoted_bootstrap code now fixes.

Fixes pex-tool#437.
@jsirois jsirois mentioned this issue Aug 24, 2018
jsirois added a commit to jsirois/pex that referenced this issue Aug 28, 2018
Previously we polluted the third party import space with any third
party dependencies of the pex bootstrap code (currently a subset of
setuptools). We now unimport all third_party code in bootstrap and
place bootstrap at the end of `sys.path` before handing off to user
code to allow their custom versions of overlapping third party code
to be imported.

Added a failing test that the demoted_bootstrap code now fixes.

Fixes pex-tool#437.
jsirois added a commit that referenced this issue Aug 29, 2018
* Cleanup bootstrap dependencies before handoff.

Previously we polluted the third party import space with any third
party dependencies of the pex bootstrap code (currently a subset of
setuptools). We now unimport all third_party code in bootstrap and
place bootstrap at the end of `sys.path` before handing off to user
code to allow their custom versions of overlapping third party code
to be imported.

Added a failing test that the demoted_bootstrap code now fixes.

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

Successfully merging a pull request may close this issue.

2 participants