(self, python_args)
| 664 | return self.execute_entry(parse_entry_point(self._pex_info.entry_point)) |
| 665 | |
| 666 | def execute_interpreter(self, python_args): |
| 667 | # type: (Sequence[str]) -> Any |
| 668 | |
| 669 | # A Python interpreter always inserts the CWD at the head of the sys.path. |
| 670 | # See https://docs.python.org/3/library/sys.html#sys.path |
| 671 | sys.path.insert(0, "") |
| 672 | |
| 673 | args = sys.argv[1:] |
| 674 | python_options = list(python_args) |
| 675 | called_with_python_options = False |
| 676 | for index, arg in enumerate(args): |
| 677 | # Check if the arg is an expected startup arg. |
| 678 | if arg.startswith("-") and arg not in ("-", "-c", "-m"): |
| 679 | # N.B.: In the face of short options that can be combined, this is a naive check. |
| 680 | if arg not in python_options: |
| 681 | python_options.append(arg) |
| 682 | called_with_python_options = True |
| 683 | else: |
| 684 | args = args[index:] |
| 685 | break |
| 686 | else: |
| 687 | # All the args were python options |
| 688 | args = [] |
| 689 | |
| 690 | if called_with_python_options: |
| 691 | return self.re_execute_with_options(python_options, args) |
| 692 | |
| 693 | if args: |
| 694 | # NB: We take care here to set up sys.argv to match how CPython does it for each case. |
| 695 | arg = args[0] |
| 696 | if arg == "-c": |
| 697 | content = args[1] |
| 698 | sys.argv = ["-c"] + args[2:] |
| 699 | return self.execute_content("-c <cmd>", content, argv0="-c") |
| 700 | elif arg == "-m": |
| 701 | module = args[1] |
| 702 | sys.argv = args[1:] |
| 703 | return self.execute_module(module) |
| 704 | else: |
| 705 | try: |
| 706 | if arg == "-": |
| 707 | content = sys.stdin.read() |
| 708 | else: |
| 709 | file_path = arg if os.path.isfile(arg) else os.path.join(arg, "__main__.py") |
| 710 | with open(file_path) as fp: |
| 711 | content = fp.read() |
| 712 | except IOError as e: |
| 713 | return "Could not open {} in the environment [{}]: {}".format( |
| 714 | arg, sys.argv[0], e |
| 715 | ) |
| 716 | sys.argv = args |
| 717 | return self.execute_content(arg, content) |
| 718 | else: |
| 719 | pex_repl = repl.create_pex_repl( |
| 720 | pex_info=self.pex_info(), |
| 721 | requirements=( |
| 722 | tuple( |
| 723 | OrderedSet( |
no test coverage detected