def test_clp_prereleases_resolver(): # type: () -> None with nested( built_wheel(name="prerelease-dep", version="1.2.3b1"), built_wheel(name="transitive-dep", install_reqs=["prerelease-dep"]), built_wheel(name="dep", install_reqs=["prerelease-dep>=1.2", "transitive-dep"]), temporary_dir(), temporary_dir(), ) as (prerelease_dep, transitive_dep, dep, dist_dir, cache_dir): for dist in (prerelease_dep, transitive_dep, dep): safe_copy(dist, os.path.join(dist_dir, os.path.basename(dist))) parser = configure_clp() options, reqs = parser.parse_args(args=[ "--no-index", "--find-links", dist_dir, "--cache-dir", cache_dir, # Avoid dangling {pex_root}. "--no-pre", "dep", ]) assert not options.allow_prereleases with pytest.raises( SystemExit, message="Should have failed to resolve prerelease dep"): build_pex(reqs, options) # When we specify `--pre`, allow_prereleases is True options, reqs = parser.parse_args(args=[ "--no-index", "--find-links", dist_dir, "--cache-dir", cache_dir, # Avoid dangling {pex_root}. "--pre", "dep", ]) assert options.allow_prereleases # Without a corresponding fix in pex.py, this test failed for a dependency requirement of # dep==1.2.3b1 from one package and just dep (any version accepted) from another package. # The failure was an exit from build_pex() with the message: # # Could not satisfy all requirements for dep==1.2.3b1: # dep==1.2.3b1, dep # # With a correct behavior the assert line is reached and pex_builder object created. pex_builder = build_pex(reqs, options) assert pex_builder is not None assert len( pex_builder.info.distributions) == 3, "Should have resolved deps"
def test_pex_script(project_name, zip_safe): with built_wheel(name=project_name, zip_safe=zip_safe) as bdist_path: env_copy = os.environ.copy() env_copy['PEX_SCRIPT'] = 'hello_world' so, rc = run_simple_pex_test('', env=env_copy) assert rc == 1, so.decode('utf-8') assert b"Could not find script 'hello_world'" in so so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist_path]) assert rc == 0, so.decode('utf-8') assert b'hello world' in so env_copy['PEX_SCRIPT'] = 'shell_script' so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist_path]) assert rc == 1, so.decode('utf-8') assert b'Unable to parse' in so
def test_pex_script(project_name, zip_safe): with built_wheel(name=project_name, zip_safe=zip_safe) as bdist_path: env_copy = os.environ.copy() env_copy["PEX_SCRIPT"] = "hello_world" so, rc = run_simple_pex_test("", env=env_copy) assert rc == 1, so.decode("utf-8") assert b"Could not find script 'hello_world'" in so so, rc = run_simple_pex_test("", env=env_copy, dists=[bdist_path]) assert rc == 0, so.decode("utf-8") assert b"hello world" in so env_copy["PEX_SCRIPT"] = "shell_script" so, rc = run_simple_pex_test("", env=env_copy, dists=[bdist_path]) assert rc == 1, so.decode("utf-8") assert b"Unable to parse" in so
def test_prex_builder_script_from_pex_path(tmpdir): # type: (Any) -> None pex_with_script = os.path.join(str(tmpdir), "script.pex") with built_wheel( name="my_project", entry_points={ "console_scripts": ["my_app = my_project.my_module:do_something"] }, ) as my_whl: pb = PEXBuilder() pb.add_dist_location(my_whl) pb.build(pex_with_script) pex_file = os.path.join(str(tmpdir), "app.pex") pb = PEXBuilder() pb.info.pex_path = pex_with_script pb.set_script("my_app") pb.build(pex_file) assert "hello world!\n" == subprocess.check_output( args=[pex_file]).decode("utf-8")
def build_wheel(**kwargs): # type: (**Any) -> str with built_wheel(**kwargs) as whl: return whl
def build_wheel(*args, **kwargs): with built_wheel(*args, **kwargs) as whl: return whl