def test_pex_builder_from_requirements_pex(): # type: () -> None def build_from_req_pex(path, req_pex): # type: (str, str) -> PEXBuilder pb = PEXBuilder(path=path) pb.add_from_requirements_pex(req_pex) with open(os.path.join(path, "exe.py"), "w") as fp: fp.write(exe_main) pb.set_executable(os.path.join(path, "exe.py")) pb.freeze() return pb def verify(pb): # type: (PEXBuilder) -> None success_txt = os.path.join(pb.path(), "success.txt") PEX(pb.path(), interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == "success" # Build from pex dir. with temporary_dir() as td2: with temporary_dir() as td1, make_bdist("p1") as p1: pb1 = write_pex(td1, dists=[p1]) pb2 = build_from_req_pex(td2, pb1.path()) verify(pb2) # Build from .pex file. with temporary_dir() as td4: with temporary_dir() as td3, make_bdist("p1") as p1: pb3 = write_pex(td3, dists=[p1]) target = os.path.join(td3, "foo.pex") pb3.build(target) pb4 = build_from_req_pex(td4, target) verify(pb4)
def test_pex_builder(): # test w/ and w/o zipfile dists with nested(temporary_dir(), make_bdist('p1', zipped=True)) as (td, p1): write_pex(td, exe_main, dists=[p1]) success_txt = os.path.join(td, 'success.txt') PEX(td).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success' # test w/ and w/o zipfile dists with nested(temporary_dir(), temporary_dir(), make_bdist('p1', zipped=True)) as ( td1, td2, p1): target_egg_dir = os.path.join(td2, os.path.basename(p1.location)) safe_mkdir(target_egg_dir) with closing(zipfile.ZipFile(p1.location, 'r')) as zf: zf.extractall(target_egg_dir) p1 = DistributionHelper.distribution_from_path(target_egg_dir) write_pex(td1, exe_main, dists=[p1]) success_txt = os.path.join(td1, 'success.txt') PEX(td1).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success'
def test_pex_builder_from_requirements_pex(): def build_from_req_pex(path, req_pex): pb = PEXBuilder(path=path) pb.add_from_requirements_pex(req_pex) with open(os.path.join(path, 'exe.py'), 'w') as fp: fp.write(exe_main) pb.set_executable(os.path.join(path, 'exe.py')) pb.freeze() return pb def verify(pb): success_txt = os.path.join(pb.path(), 'success.txt') PEX(pb.path(), interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success' # Build from pex dir. with temporary_dir() as td2: with nested(temporary_dir(), make_bdist('p1')) as (td1, p1): pb1 = write_pex(td1, dists=[p1]) pb2 = build_from_req_pex(td2, pb1.path()) verify(pb2) # Build from .pex file. with temporary_dir() as td4: with nested(temporary_dir(), make_bdist('p1')) as (td3, p1): pb3 = write_pex(td3, dists=[p1]) target = os.path.join(td3, 'foo.pex') pb3.build(target) pb4 = build_from_req_pex(td4, target) verify(pb4)
def test_pex_builder_wheeldep(): """Repeat the pex_builder test, but this time include an import of something from a wheel that doesn't come in importable form. """ with nested(temporary_dir(), make_bdist('p1', zipped=True)) as (td, p1): pyparsing_path = "./tests/example_packages/pyparsing-2.1.10-py2.py3-none-any.whl" dist = DistributionHelper.distribution_from_path(pyparsing_path) write_pex(td, wheeldeps_exe_main, dists=[p1, dist]) success_txt = os.path.join(td, 'success.txt') PEX(td).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success'
def test_pex_builder_wheeldep(): """Repeat the pex_builder test, but this time include an import of something from a wheel that doesn't come in importable form.""" with nested(temporary_dir(), make_bdist("p1")) as (td, p1): pyparsing_path = "./tests/example_packages/pyparsing-2.1.10-py2.py3-none-any.whl" pb = write_pex(td, wheeldeps_exe_main, dists=[p1, pyparsing_path]) success_txt = os.path.join(td, "success.txt") PEX(td, interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == "success"
def test_pex_builder(): # test w/ and w/o zipfile dists with nested(temporary_dir(), make_bdist('p1')) as (td, p1): pb = write_pex(td, exe_main, dists=[p1]) success_txt = os.path.join(td, 'success.txt') PEX(td, interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success' # test w/ and w/o zipfile dists with nested(temporary_dir(), temporary_dir(), make_bdist('p1')) as (td1, td2, p1): pb = write_pex(td1, exe_main, dists=[p1]) success_txt = os.path.join(td1, 'success.txt') PEX(td1, interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success'
def test_pex_builder(): # type: () -> None # test w/ and w/o zipfile dists with temporary_dir() as td, make_bdist("p1") as p1: pb = write_pex(td, exe_main, dists=[p1]) success_txt = os.path.join(td, "success.txt") PEX(td, interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == "success" # test w/ and w/o zipfile dists with temporary_dir() as td1, temporary_dir() as td2, make_bdist("p1") as p1: pb = write_pex(td1, exe_main, dists=[p1]) success_txt = os.path.join(td1, "success.txt") PEX(td1, interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == "success"
def test_pex_builder_wheeldep(): """Repeat the pex_builder test, but this time include an import of something from a wheel that doesn't come in importable form. """ with nested(temporary_dir(), make_bdist('p1', zipped=True)) as (td, p1): pyparsing_path = "./tests/example_packages/pyparsing-2.1.10-py2.py3-none-any.whl" dist = DistributionHelper.distribution_from_path(pyparsing_path) pb = write_pex(td, wheeldeps_exe_main, dists=[p1, dist]) success_txt = os.path.join(td, 'success.txt') PEX(td, interpreter=pb.interpreter).run(args=[success_txt]) assert os.path.exists(success_txt) with open(success_txt) as fp: assert fp.read() == 'success'