Demote PEX bootstrap code to the end of `sys.path` and uninstall all PEX vendored code.
(disable_vendor_importer=True)
| 113 | |
| 114 | |
| 115 | def demote(disable_vendor_importer=True): |
| 116 | # type: (bool) -> None |
| 117 | """Demote PEX bootstrap code to the end of `sys.path` and uninstall all PEX vendored code.""" |
| 118 | |
| 119 | from . import third_party |
| 120 | from .tracer import TRACER |
| 121 | |
| 122 | TRACER.log("Bootstrap complete, performing final sys.path modifications...") |
| 123 | |
| 124 | should_log = {level: TRACER.should_log(V=level) for level in range(1, 10)} |
| 125 | |
| 126 | def log(msg, V=1): |
| 127 | if should_log.get(V, False): |
| 128 | print("pex: {}".format(msg), file=sys.stderr) |
| 129 | |
| 130 | # Remove the third party resources pex uses and demote pex bootstrap code to the end of |
| 131 | # sys.path for the duration of the run to allow conflicting versions supplied by user |
| 132 | # dependencies to win during the course of the execution of user code. |
| 133 | third_party.uninstall() |
| 134 | |
| 135 | bootstrap = Bootstrap.locate() |
| 136 | log("Demoting code from %s" % bootstrap, V=2) |
| 137 | for module in bootstrap.demote(disable_vendor_importer=disable_vendor_importer): |
| 138 | log("un-imported {}".format(module), V=9) |
| 139 | |
| 140 | import pex |
| 141 | |
| 142 | log("Re-imported pex from {}".format(pex.__path__), V=3) |
| 143 | |
| 144 | log("PYTHONPATH contains:") |
| 145 | for element in sys.path: |
| 146 | log(" %c %s" % (" " if os.path.exists(element) else "*", element)) |
| 147 | log(" * - paths that do not exist or will be imported via zipimport") |