Execute the PEX. This function makes assumptions that it is the last function called by the interpreter.
(self, python_args=())
| 570 | return self._pex |
| 571 | |
| 572 | def execute(self, python_args=()): |
| 573 | # type: (Sequence[str]) -> Any |
| 574 | """Execute the PEX. |
| 575 | |
| 576 | This function makes assumptions that it is the last function called by the interpreter. |
| 577 | """ |
| 578 | pex_file = self._vars.PEX |
| 579 | if self._vars.PEX_TOOLS: |
| 580 | if not self._pex_info.includes_tools: |
| 581 | die( |
| 582 | "The PEX_TOOLS environment variable was set, but this PEX was not built " |
| 583 | "with tools (Re-build the PEX file with `pex --include-tools ...`)" |
| 584 | ) |
| 585 | |
| 586 | from pex.tools import main as tools |
| 587 | |
| 588 | sys.exit(tools.main(pex=PEX(pex_file or sys.argv[0]))) |
| 589 | |
| 590 | self.activate() |
| 591 | |
| 592 | if pex_file: |
| 593 | try: |
| 594 | from setproctitle import setproctitle # type: ignore[import] |
| 595 | |
| 596 | setproctitle( |
| 597 | "{python} {pex_file} {args}".format( |
| 598 | python=sys.executable, |
| 599 | pex_file=pex_file, |
| 600 | args=" ".join(sys.argv[1:]), |
| 601 | ) |
| 602 | ) |
| 603 | except ImportError: |
| 604 | TRACER.log( |
| 605 | "Not setting process title since setproctitle is not available in " |
| 606 | "{pex_file}".format(pex_file=pex_file), |
| 607 | V=3, |
| 608 | ) |
| 609 | |
| 610 | result = self._wrap_coverage(self._wrap_profiling, self._execute, python_args) |
| 611 | if "PYTHONINSPECT" not in os.environ: |
| 612 | sys.exit(0 if isinstance(result, Globals) else result) |
| 613 | else: |
| 614 | return result |
| 615 | |
| 616 | def _execute(self, python_args): |
| 617 | # type: (Sequence[str]) -> Any |