MCPcopy
hub / github.com/pex-tool/pex / bootstrap_pex

Function bootstrap_pex

pex/pex_bootstrapper.py:651–705  ·  view source on GitHub ↗
(
    entry_point,  # type: str
    execute=True,  # type: bool
    venv_dir=None,  # type: Optional[str]
    python_args=(),  # type: Sequence[str]
)

Source from the content-addressed store, hash-verified

649# NB: This helper is used by the PEX bootstrap __main__.py as well as the __pex__/__init__.py
650# import hook code.
651def bootstrap_pex(
652 entry_point, # type: str
653 execute=True, # type: bool
654 venv_dir=None, # type: Optional[str]
655 python_args=(), # type: Sequence[str]
656):
657 # type: (...) -> Any
658
659 pex_info = _bootstrap(entry_point)
660
661 # ENV.PEX_ROOT is consulted by PythonInterpreter and Platform so set that up as early as
662 # possible in the run.
663 with ENV.patch(PEX_ROOT=pex_info.pex_root):
664 cache_access.read_write()
665 if not execute:
666 for location in _activate_pex(entry_point, pex_info, venv_dir=venv_dir):
667 from pex.third_party import VendorImporter
668
669 VendorImporter.install(
670 uninstallable=False, prefix="__pex__", path_items=["."], root=location
671 )
672
673 from pex import bootstrap
674
675 # For inscrutable reasons, CPython 2.7 (not PyPy 2.7 and not any other CPython or PyPy
676 # version supported by Pex) cannot handle pex.third_party being un-imported at this
677 # stage; so we just skip that cleanup step for every interpreter to keep things simple.
678 # The main point here is that we've un-imported all "exposed" Pex vendored code, notably
679 # `attrs`.
680 bootstrap.demote(disable_vendor_importer=False)
681 return
682
683 interpreter_test = InterpreterTest(entry_point=entry_point, pex_info=pex_info)
684 if not (ENV.PEX_UNZIP or ENV.PEX_TOOLS) and pex_info.venv:
685 try:
686 target = find_compatible_interpreter(
687 interpreter_test=interpreter_test,
688 interpreter_selection_strategy=pex_info.interpreter_selection_strategy,
689 )
690 except UnsatisfiableInterpreterConstraintsError as e:
691 die(str(e))
692 venv_pex = _bootstrap_venv(entry_point, interpreter=target)
693 venv_pex.execv(python_args=python_args, additional_args=sys.argv[1:])
694 else:
695 maybe_reexec_pex(
696 interpreter_test=interpreter_test,
697 interpreter_selection_strategy=pex_info.interpreter_selection_strategy,
698 python_args=python_args,
699 )
700 from . import pex
701
702 try:
703 return pex.PEX(entry_point).execute(python_args=python_args)
704 except pex.PEX.Error as e:
705 return e
706
707
708def _activate_pex(

Callers 1

bootFunction · 0.90

Calls 13

dieFunction · 0.90
_bootstrapFunction · 0.85
_activate_pexFunction · 0.85
InterpreterTestClass · 0.85
_bootstrap_venvFunction · 0.85
maybe_reexec_pexFunction · 0.85
installMethod · 0.80
demoteMethod · 0.80
execvMethod · 0.80
PEXMethod · 0.80
patchMethod · 0.45

Tested by

no test coverage detected