def test_reversion(tmp_path: Path) -> None: # Download an input whl. name_template = "virtualenv-{}-py2.py3-none-any.whl" input_name = name_template.format("15.1.0") url = ("https://files.pythonhosted.org/packages/6f/86/" "3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/{}". format(input_name)) input_whl_file = tmp_path / input_name with input_whl_file.open(mode="wb") as f: shutil.copyfileobj(requests.get(url, stream=True).raw, f) # Rewrite it. output_version = "9.1.9" output_name = name_template.format(output_version) output_whl_file = tmp_path / output_name reversion( whl_file=input_whl_file.as_posix(), dest_dir=tmp_path.as_posix(), target_version=output_version, ) assert output_whl_file.is_file() is True # Confirm that it can be consumed. output_pex_file = tmp_path / "out.pex" pex_main.main([ "--disable-cache", "-o", output_pex_file.as_posix(), output_whl_file.as_posix() ]) assert output_pex_file.is_file() is True
def test_reversion() -> None: with temporary_dir() as dest_dir: # Download an input whl. name_template = "virtualenv-{}-py2.py3-none-any.whl" input_name = name_template.format("15.1.0") url = ( "https://files.pythonhosted.org/packages/6f/86/" "3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/{}". format(input_name)) input_whl_file = os.path.join(dest_dir, input_name) with open(input_whl_file, "wb") as f: shutil.copyfileobj(requests.get(url, stream=True).raw, f) # Rewrite it. output_version = "9.1.9" output_name = name_template.format(output_version) output_whl_file = os.path.join(dest_dir, output_name) reversion(whl_file=input_whl_file, dest_dir=dest_dir, target_version=output_version) assert os.path.isfile(output_whl_file) is True # Confirm that it can be consumed. output_pex_file = os.path.join(dest_dir, "out.pex") pex_main.main( ["--disable-cache", "-o", output_pex_file, output_whl_file]) assert os.path.isfile(output_pex_file) is True
def test_run(self): with temporary_dir() as dest_dir: # Download an input whl. # TODO: Not happy about downloading things. Attempted to: # ./pants setup-py --run="bdist_wheel" $target # but was unable to locate the output whl in the context of a test (perhaps due to # mismatched cwd?) name_template = 'virtualenv-{}-py2.py3-none-any.whl' input_name = name_template.format('15.1.0') url = ( 'https://files.pythonhosted.org/packages/6f/86/' '3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/{}' .format(input_name)) input_whl_file = os.path.join(dest_dir, input_name) with open(input_whl_file, 'wb') as f: shutil.copyfileobj(requests.get(url, stream=True).raw, f) # Rewrite it. output_version = '9.1.9' output_name = name_template.format(output_version) output_whl_file = os.path.join(dest_dir, output_name) command = [ 'run', '-q', 'src/python/pants/releases:reversion', '--', input_whl_file, dest_dir, output_version, ] self.assert_success(self.run_pants(command)) self.assertTrue(os.path.isfile(output_whl_file)) # Confirm that it can be consumed. output_pex_file = os.path.join(dest_dir, 'out.pex') pex_main.main([ '--disable-cache', '-o', output_pex_file, output_whl_file, ]) self.assertTrue(os.path.isfile(output_pex_file))
def test_run(self): with temporary_dir() as dest_dir: # Download an input whl. # TODO: Not happy about downloading things. Attempted to: # ./pants setup-py --run="bdist_wheel" $target # but was unable to locate the output whl in the context of a test (perhaps due to # mismatched cwd?) name_template ='virtualenv-{}-py2.py3-none-any.whl' input_name = name_template.format('15.1.0') url = ( 'https://files.pythonhosted.org/packages/6f/86/' '3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/{}'.format(input_name) ) input_whl_file = os.path.join(dest_dir, input_name) with open(input_whl_file, 'wb') as f: shutil.copyfileobj(requests.get(url, stream=True).raw, f) # Rewrite it. output_version = '9.1.9' output_name = name_template.format(output_version) output_whl_file = os.path.join(dest_dir, output_name) command = [ 'run', '-q', 'src/python/pants/releases:reversion', '--', input_whl_file, dest_dir, output_version, ] self.assert_success(self.run_pants(command)) self.assertTrue(os.path.isfile(output_whl_file)) # Confirm that it can be consumed. output_pex_file = os.path.join(dest_dir, 'out.pex') pex_main.main([ '--disable-cache', '-o', output_pex_file, output_whl_file, ]) self.assertTrue(os.path.isfile(output_pex_file))
def run_pex_command(args, env=None): """Simulate running pex command for integration testing. This is different from run_simple_pex in that it calls the pex command rather than running a generated pex. This is useful for testing end to end runs with specific command line arguments or env options. """ args.insert(0, '-vvvvv') def logger_callback(_output): def mock_logger(msg, V=None): _output.append(msg) return mock_logger exception = None tb = None error_code = None output = [] pex_bin_pex.log.set_logger(logger_callback(output)) def update_env(target_env): if target_env: orig = os.environ.copy() os.environ.clear() os.environ.update(target_env) return orig restore_env = update_env(env) try: pex_bin_pex.main(args=args) except SystemExit as e: error_code = e.code except Exception as e: exception = e tb = traceback.format_exc() finally: update_env(restore_env) return IntegResults(output, error_code, exception, tb)
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). from __future__ import absolute_import from pex.bin import pex __name__ == "__main__" and pex.main()
if __name__ == '__main__': dest = join(BASE_PATH, 'bin') if not os.path.isdir(dest): os.makedirs(dest, ) os.chdir(dest) for path, setup in find_setups(BASE_PATH): pex_target = join(dest, '%s.%s.pex' % ( setup['name'], setup['version'], )) for f in os.listdir(path): if f.endswith('.egg-info'): ff = os.path.join(path, f) if os.path.isdir(ff): shutil.rmtree(ff) pex.main(args=[ '-v', '-e', 'hemail.entry', # TODO: does not make sense for all setups '--not-zip-safe', '--always-write-cache', '--disable-cache', # disable pex cache to make sure to really recent file with be in target '-o', pex_target, path, ])
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). from __future__ import absolute_import from pex.bin import pex __name__ == '__main__' and pex.main()