1
0

__init__.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. __all__ = ['Arch', 'Downloader', 'ensure_image', 'ImageExtractor', 'LinuxTag',
  6. 'PythonExtractor', 'PythonImpl', 'PythonVersion']
  7. def ensure_image(tag, *, clean=False, extract=True):
  8. '''Download a manylinux image to the cache'''
  9. try:
  10. tag, image_tag = tag.rsplit(':', 1)
  11. except ValueError:
  12. image_tag = 'latest'
  13. tag, arch = tag.split('_', 1)
  14. tag = LinuxTag.from_brief(tag)
  15. arch = Arch.from_str(arch)
  16. downloader = Downloader(tag=tag, arch=arch)
  17. downloader.download(tag=image_tag)
  18. if extract:
  19. image_extractor = ImageExtractor(
  20. prefix = downloader.default_destination(),
  21. tag = image_tag
  22. )
  23. image_extractor.extract(clean=clean)
  24. return SimpleNamespace(
  25. arch = arch,
  26. tag = tag,
  27. path = image_extractor.default_destination(),
  28. )
  29. else:
  30. return SimpleNamespace(
  31. arch = arch,
  32. tag = tag,
  33. path = downloader.default_destination(),
  34. )