(tmpdir)
| 502 | ), |
| 503 | ) |
| 504 | def test_relocatable_venv(tmpdir): |
| 505 | # type: (Any) -> None |
| 506 | |
| 507 | pex_file = os.path.join(str(tmpdir), "relocatable.pex") |
| 508 | src = os.path.join(str(tmpdir), "src") |
| 509 | with safe_open(os.path.join(src, "main.py"), "w") as fp: |
| 510 | fp.write( |
| 511 | dedent( |
| 512 | """\ |
| 513 | import sys |
| 514 | from colors import blue |
| 515 | |
| 516 | |
| 517 | print(blue(sys.executable)) |
| 518 | """ |
| 519 | ) |
| 520 | ) |
| 521 | result = run_pex_command( |
| 522 | args=["-D", src, "ansicolors==1.1.8", "-m", "main", "--include-tools", "-o", pex_file] |
| 523 | ) |
| 524 | result.assert_success() |
| 525 | |
| 526 | venv = os.path.join(str(tmpdir), "relocatable.venv") |
| 527 | subprocess.check_call(args=[pex_file, "venv", venv], env=make_env(PEX_TOOLS=1)) |
| 528 | subprocess.check_call(args=[os.path.join(venv, "pex")]) |
| 529 | |
| 530 | relocated_relpath = "relocated.venv" |
| 531 | relocated_venv = os.path.join(str(tmpdir), relocated_relpath) |
| 532 | |
| 533 | # Since the venv pex script contains a shebang with an absolute path to the venv python |
| 534 | # interpreter, a move of the venv makes the script un-runnable directly. |
| 535 | shutil.move(venv, relocated_venv) |
| 536 | with pytest.raises(OSError) as exec_info: |
| 537 | subprocess.check_call(args=[os.path.join(relocated_venv, "pex")]) |
| 538 | assert errno.ENOENT == exec_info.value.errno |
| 539 | |
| 540 | # But we should be able to run the script using the moved venv's interpreter. |
| 541 | subprocess.check_call( |
| 542 | args=[ |
| 543 | os.path.join(relocated_relpath, "bin", "python"), |
| 544 | os.path.join(relocated_relpath, "pex"), |
| 545 | ], |
| 546 | cwd=str(tmpdir), |
| 547 | ) |
| 548 | |
| 549 | |
| 550 | def test_compile(tmpdir): |
nothing calls this directly
no test coverage detected