Write a pex file that optionally contains an executable entry point. :param td: temporary directory path :param exe_contents: entry point python file :param dists: distributions to include, typically sdists or bdists :param sources: sources to include, as a list of pairs (env_filena
(
td, # type: str
exe_contents=None, # type: Optional[str]
dists=None, # type: Optional[Iterable[Distribution]]
sources=None, # type: Optional[Iterable[Tuple[str, str]]]
coverage=False, # type: bool
interpreter=None, # type: Optional[PythonInterpreter]
pex_info=None, # type: Optional[PexInfo]
)
| 343 | |
| 344 | |
| 345 | def write_simple_pex( |
| 346 | td, # type: str |
| 347 | exe_contents=None, # type: Optional[str] |
| 348 | dists=None, # type: Optional[Iterable[Distribution]] |
| 349 | sources=None, # type: Optional[Iterable[Tuple[str, str]]] |
| 350 | coverage=False, # type: bool |
| 351 | interpreter=None, # type: Optional[PythonInterpreter] |
| 352 | pex_info=None, # type: Optional[PexInfo] |
| 353 | ): |
| 354 | # type: (...) -> PEXBuilder |
| 355 | """Write a pex file that optionally contains an executable entry point. |
| 356 | |
| 357 | :param td: temporary directory path |
| 358 | :param exe_contents: entry point python file |
| 359 | :param dists: distributions to include, typically sdists or bdists |
| 360 | :param sources: sources to include, as a list of pairs (env_filename, contents) |
| 361 | :param coverage: include coverage header |
| 362 | :param interpreter: a custom interpreter to use to build the pex |
| 363 | :param pex_info: a custom PexInfo to use to build the pex. |
| 364 | """ |
| 365 | dists = dists or [] |
| 366 | sources = sources or [] |
| 367 | |
| 368 | safe_mkdir(td) |
| 369 | |
| 370 | pb = PEXBuilder( |
| 371 | path=td, |
| 372 | preamble=COVERAGE_PREAMBLE if coverage else None, |
| 373 | interpreter=interpreter, |
| 374 | pex_info=pex_info, |
| 375 | ) |
| 376 | |
| 377 | for dist in dists: |
| 378 | pb.add_dist_location(dist.location if isinstance(dist, Distribution) else dist) |
| 379 | |
| 380 | for env_filename, contents in sources: |
| 381 | src_path = os.path.join(td, env_filename) |
| 382 | safe_mkdir(os.path.dirname(src_path)) |
| 383 | with open(src_path, "w") as fp: |
| 384 | fp.write(contents) |
| 385 | pb.add_source(src_path, env_filename) |
| 386 | |
| 387 | if exe_contents: |
| 388 | with open(os.path.join(td, "exe.py"), "w") as fp: |
| 389 | fp.write(exe_contents) |
| 390 | pb.set_executable(os.path.join(td, "exe.py")) |
| 391 | |
| 392 | pb.freeze() |
| 393 | |
| 394 | return pb |
| 395 | |
| 396 | |
| 397 | def re_exact(text): |