unpack.py 1016 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. from pathlib import Path
  3. from ..wheelfile import WheelFile
  4. def unpack(path: str, dest: str = ".") -> None:
  5. """Unpack a wheel.
  6. Wheel content will be unpacked to {dest}/{name}-{ver}, where {name}
  7. is the package name and {ver} its version.
  8. :param path: The path to the wheel.
  9. :param dest: Destination directory (default to current directory).
  10. """
  11. with WheelFile(path) as wf:
  12. namever = wf.parsed_filename.group("namever")
  13. destination = Path(dest) / namever
  14. print(f"Unpacking to: {destination}...", end="", flush=True)
  15. for zinfo in wf.filelist:
  16. target_path = Path(wf.extract(zinfo, destination))
  17. # Set permissions to the same values as they were set in the archive
  18. # We have to do this manually due to
  19. # https://github.com/python/cpython/issues/59999
  20. permissions = zinfo.external_attr >> 16 & 0o777
  21. target_path.chmod(permissions)
  22. print("OK")