(
dest_dir, # type: str
entry_points, # type: EntryPoints
interpreter=None, # type: Optional[PythonInterpreter]
overwrite=True, # type: bool
hermetic_scripts=False, # type: bool
)
| 21 | |
| 22 | |
| 23 | def install_scripts( |
| 24 | dest_dir, # type: str |
| 25 | entry_points, # type: EntryPoints |
| 26 | interpreter=None, # type: Optional[PythonInterpreter] |
| 27 | overwrite=True, # type: bool |
| 28 | hermetic_scripts=False, # type: bool |
| 29 | ): |
| 30 | # type: (...) -> Iterator[Tuple[Text, Text]] |
| 31 | |
| 32 | if not entry_points: |
| 33 | return |
| 34 | |
| 35 | if entry_points.source is None: |
| 36 | raise AssertionError(reportable_unexpected_error_msg()) |
| 37 | |
| 38 | script_src = entry_points.source |
| 39 | if interpreter: |
| 40 | shebang = interpreter.shebang(args=interpreter.hermetic_args if hermetic_scripts else None) |
| 41 | else: |
| 42 | shebang = "#!python" |
| 43 | for named_entry_point, gui in itertools.chain.from_iterable( |
| 44 | ((value, gui) for value in entry_points.get(key, {}).values()) |
| 45 | for key, gui in (("console_scripts", False), ("gui_scripts", True)) |
| 46 | ): |
| 47 | entry_point = named_entry_point.entry_point |
| 48 | if isinstance(entry_point, CallableEntryPoint): |
| 49 | script = dedent( |
| 50 | """\ |
| 51 | {shebang} |
| 52 | # -*- coding: utf-8 -*- |
| 53 | import importlib |
| 54 | import sys |
| 55 | |
| 56 | entry_point = importlib.import_module({modname!r}) |
| 57 | for attr in {attrs!r}: |
| 58 | entry_point = getattr(entry_point, attr) |
| 59 | |
| 60 | if __name__ == "__main__": |
| 61 | import os |
| 62 | pex_root_fallback = os.environ.get("_PEX_ROOT_FALLBACK") |
| 63 | if pex_root_fallback: |
| 64 | import atexit |
| 65 | import shutil |
| 66 | |
| 67 | atexit.register(shutil.rmtree, pex_root_fallback, True) |
| 68 | |
| 69 | sys.exit(entry_point()) |
| 70 | """ |
| 71 | ).format(shebang=shebang, modname=entry_point.module, attrs=entry_point.attrs) |
| 72 | else: |
| 73 | script = dedent( |
| 74 | """\ |
| 75 | {shebang} |
| 76 | # -*- coding: utf-8 -*- |
| 77 | import runpy |
| 78 | import sys |
| 79 | |
| 80 | if __name__ == "__main__": |
no test coverage detected