def main(args): """Main entry point of the app""" destination = SchemeDictionaryDestination( dict( stdlib=str(args.stdlib_path), platstdlib=str(args.platstdlib_path), purelib=str(args.purelib_path), platlib=str(args.platlib_path), include=str(args.include_path), platinclude=str(args.platinclude_path), scripts=str(args.scripts_path), data=str(args.data_path), ), interpreter=str(args.interpreter), script_kind="posix", ) for wheel in args.wheel_path: with WheelFile.open(wheel) as source: install( source=source, destination=destination, # Additional metadata that is generated # by the installation tool. additional_metadata={ "INSTALLER": 'Machinekit-HAL Python wheel' f'installer {__version__}'.encode('utf-8'), }, ) print(f'Wheel {wheel} installed') print("All wheels were installed!")
def _common_wheel_editable_install( tmpdir_factory: pytest.TempPathFactory, common_wheels: Path, package: str ) -> Path: wheel_candidates = list(common_wheels.glob(f"{package}-*.whl")) assert len(wheel_candidates) == 1, wheel_candidates install_dir = tmpdir_factory.mktemp(package) / "install" lib_install_dir = install_dir / "lib" bin_install_dir = install_dir / "bin" with WheelFile.open(wheel_candidates[0]) as source: install( source, SchemeDictionaryDestination( { "purelib": os.fspath(lib_install_dir), "platlib": os.fspath(lib_install_dir), "scripts": os.fspath(bin_install_dir), }, interpreter=sys.executable, script_kind="posix", ), additional_metadata={}, ) # The scripts are not necessary for our use cases, and they would be installed with # the wrong interpreter, so remove them. # TODO consider a refactoring by adding a install_from_wheel(path) method # to the virtualenv fixture. if bin_install_dir.exists(): shutil.rmtree(bin_install_dir) return lib_install_dir
def test_provides_correct_contents(self, fancy_wheel): # Know the contents of the wheel files = {} with zipfile.ZipFile(fancy_wheel) as archive: for file in archive.namelist(): if file[-1:] == "/": continue files[file] = archive.read(file) expected_record_lines = ( files["fancy-1.0.0.dist-info/RECORD"].decode("utf-8").splitlines()) expected_records = list(parse_record_file(expected_record_lines)) # Check that the object's output is appropriate got_records = [] got_files = {} with WheelFile.open(fancy_wheel) as source: for record_elements, stream, is_executable in source.get_contents( ): got_records.append(record_elements) got_files[record_elements[0]] = stream.read() assert not is_executable assert sorted(got_records) == sorted(expected_records) assert got_files == files
def test_provides_correct_dist_info_filenames(self, fancy_wheel): with WheelFile.open(fancy_wheel) as source: assert sorted(source.dist_info_filenames) == [ "METADATA", "RECORD", "WHEEL", "entry_points.txt", "top_level.txt", ]
def test_rejects_not_okay_name(self, tmp_path): # Create an empty zipfile path = tmp_path / "not_a_valid_name.whl" with zipfile.ZipFile(str(path), "w"): pass with pytest.raises(ValueError, match="Not a valid wheel filename: .+"): with WheelFile.open(str(path)): pass
def main(): """Entry point for CLI.""" ap = argparse.ArgumentParser("python pyinstaller.py") ap.add_argument("wheel_file", help="Path to a .whl file to install") ap.add_argument("--interpreter", required=True, help="Interpreter path to be used in scripts") ap.add_argument( "--script-kind", required=True, choices=["posix", "win-ia32", "win-amd64", "win-arm", "win-arm64"], help="Kind of launcher to create for each script", ) dest_args = ap.add_argument_group("Destination directories") dest_args.add_argument( "--purelib", required=True, help="Directory for platform-independent Python modules", ) dest_args.add_argument( "--platlib", help="Directory for platform-dependent Python modules (same as purelib " "if not specified)", ) dest_args.add_argument("--headers", required=True, help="Directory for C header files") dest_args.add_argument("--scripts", required=True, help="Directory for executable scripts") dest_args.add_argument("--data", required=True, help="Directory for external data files") args = ap.parse_args() destination = SchemeDictionaryDestination( { "purelib": args.purelib, "platlib": args.platlib if args.platlib is not None else args.purelib, "headers": args.headers, "scripts": args.scripts, "data": args.data, }, interpreter=args.interpreter, script_kind=args.script_kind, ) with WheelFile.open(glob.glob(args.wheel_file)[0]) as source: install( source=source, destination=destination, additional_metadata={}, )
def test_correctly_reads_from_dist_info_files(self, fancy_wheel): files = {} with zipfile.ZipFile(fancy_wheel) as archive: for file in archive.namelist(): if ".dist-info" not in file: continue files[posixpath.basename(file)] = archive.read(file).decode( "utf-8") got_files = {} with WheelFile.open(fancy_wheel) as source: for file in files: got_files[file] = source.read_dist_info(file) assert got_files == files