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

Fixup PEX.demote_bootstrap: fully unimport. #554

Merged
merged 2 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pex/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ def demote_bootstrap(cls):
TRACER.log('Un-importing third party bootstrap dependency %s from %s'
% (mod, bootstrap_path))
sys.modules.pop(mod)
submod_prefix = mod + '.'
for submod in [m for m in sys.modules.keys() if m.startswith(submod_prefix)]:
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
sys.modules.pop(submod)
sys.path.pop(bootstrap_path_index)
sys.path.append(bootstrap_path)

Expand Down
7 changes: 5 additions & 2 deletions pex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def make_bdist(name='my_project', version='0.0.0', installer_impl=EggInstaller,
"""


def write_simple_pex(td, exe_contents, dists=None, sources=None, coverage=False):
def write_simple_pex(td, exe_contents, dists=None, sources=None, coverage=False, interpreter=None):
"""Write a pex file that contains an executable entry point

:param td: temporary directory path
Expand All @@ -189,6 +189,7 @@ def write_simple_pex(td, exe_contents, dists=None, sources=None, coverage=False)
:param dists: distributions to include, typically sdists or bdists
:param sources: sources to include, as a list of pairs (env_filename, contents)
:param coverage: include coverage header
:param interpreter: a custom interpreter to use to build the pex
"""
dists = dists or []
sources = sources or []
Expand All @@ -198,7 +199,9 @@ def write_simple_pex(td, exe_contents, dists=None, sources=None, coverage=False)
with open(os.path.join(td, 'exe.py'), 'w') as fp:
fp.write(exe_contents)

pb = PEXBuilder(path=td, preamble=COVERAGE_PREAMBLE if coverage else None)
pb = PEXBuilder(path=td,
preamble=COVERAGE_PREAMBLE if coverage else None,
interpreter=interpreter)

for dist in dists:
pb.add_dist_location(dist.location)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pex.bin.pex import get_interpreter
from pex.compatibility import PY2, WINDOWS, nested, to_bytes
from pex.installer import EggInstaller, WheelInstaller
from pex.interpreter import PythonInterpreter
from pex.pex import PEX
from pex.pex_builder import PEXBuilder
from pex.pex_info import PexInfo
Expand Down Expand Up @@ -373,3 +374,29 @@ def test_pex_run_custom_setuptools_useable():
)
rc = PEX(pex.path()).run()
assert rc == 0


def test_pex_run_conflicting_custom_setuptools_useable():
# Here we use an older setuptools to build the pex which has a newer setuptools requirement.
jsirois marked this conversation as resolved.
Show resolved Hide resolved
# These setuptools dists have different pkg_resources APIs:
# $ diff \
# <(zipinfo -1 setuptools-20.3.1-py2.py3-none-any.whl | grep pkg_resources/ | sort) \
# <(zipinfo -1 setuptools-40.4.3-py2.py3-none-any.whl | grep pkg_resources/ | sort)
# 2a3,4
# > pkg_resources/py31compat.py
# > pkg_resources/_vendor/appdirs.py
with temporary_dir() as resolve_cache:
dists = resolve(['setuptools==20.3.1'], cache=resolve_cache)
interpreter = PythonInterpreter.from_binary(sys.executable,
path_extras=[dist.location for dist in dists],
include_site_extras=False)
dists = resolve(['setuptools==40.4.3'], cache=resolve_cache)
with temporary_dir() as temp_dir:
pex = write_simple_pex(
temp_dir,
'from pkg_resources import appdirs, py31compat',
dists=dists,
interpreter=interpreter
)
rc = PEX(pex.path()).run()
jsirois marked this conversation as resolved.
Show resolved Hide resolved
assert rc == 0