1
0

__init__.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from types import SimpleNamespace
  2. from .config import Arch, LinuxTag, PythonImpl, PythonVersion
  3. from .download import Downloader
  4. from .extract import ImageExtractor, PythonExtractor
  5. from .patch import Patcher
  6. __all__ = ['Arch', 'Downloader', 'ensure_image', 'ImageExtractor', 'LinuxTag',
  7. 'Patcher', 'PythonExtractor', 'PythonImpl', 'PythonVersion']
  8. def ensure_image(tag, *, clean=False, extract=True):
  9. '''Download a manylinux image to the cache'''
  10. try:
  11. tag, image_tag = tag.rsplit(':', 1)
  12. except ValueError:
  13. image_tag = 'latest'
  14. if tag.startswith('2_'):
  15. tag, arch = tag[2:].split('_', 1)
  16. tag = f'2_{tag}'
  17. else:
  18. tag, arch = tag.split('_', 1)
  19. tag = LinuxTag.from_brief(tag)
  20. arch = Arch.from_str(arch)
  21. downloader = Downloader(tag=tag, arch=arch)
  22. downloader.download(tag=image_tag)
  23. if extract:
  24. image_extractor = ImageExtractor(
  25. prefix = downloader.default_destination(),
  26. tag = image_tag
  27. )
  28. image_extractor.extract(clean=clean)
  29. patcher = Patcher(tag=tag, arch=arch)
  30. patcher.patch(destination = image_extractor.default_destination())
  31. return SimpleNamespace(
  32. arch = arch,
  33. tag = tag,
  34. path = image_extractor.default_destination(),
  35. )
  36. else:
  37. return SimpleNamespace(
  38. arch = arch,
  39. tag = tag,
  40. path = downloader.default_destination(),
  41. )