manylinux.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. from pathlib import Path
  3. import shutil
  4. from ...appimage import build_appimage
  5. from ...manylinux import Arch, Downloader, ImageExtractor, LinuxTag, \
  6. PythonExtractor
  7. from ...utils.tmp import TemporaryDirectory
  8. __all__ = ['execute']
  9. def _unpack_args(args):
  10. '''Unpack command line arguments
  11. '''
  12. return args.tag, args.abi
  13. def execute(tag, abi):
  14. '''Build a Python AppImage using a Manylinux image
  15. '''
  16. tag, arch = tag.split('_', 1)
  17. tag = LinuxTag.from_brief(tag)
  18. arch = Arch.from_str(arch)
  19. downloader = Downloader(tag=tag, arch=arch)
  20. downloader.download()
  21. image_extractor = ImageExtractor(downloader.default_destination())
  22. image_extractor.extract()
  23. pwd = os.getcwd()
  24. with TemporaryDirectory() as tmpdir:
  25. python_extractor = PythonExtractor(
  26. arch = arch,
  27. prefix = image_extractor.default_destination(),
  28. tag = abi
  29. )
  30. appdir = Path(tmpdir) / 'AppDir'
  31. python_extractor.extract(appdir, appify=True)
  32. fullname = '-'.join((
  33. f'{python_extractor.impl}{python_extractor.version.long()}',
  34. abi,
  35. f'{tag}_{arch}'
  36. ))
  37. destination = f'{fullname}.AppImage'
  38. build_appimage(
  39. appdir = str(appdir),
  40. destination = destination
  41. )
  42. shutil.move(
  43. Path(tmpdir) / destination,
  44. Path(pwd) / destination
  45. )