1
0

manylinux.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import os
  2. from pathlib import Path
  3. import tarfile
  4. from ...appimage import build_appimage
  5. from ...manylinux import ensure_image, PythonExtractor
  6. from ...utils.fs import copy_file, copy_tree
  7. from ...utils.log import log
  8. from ...utils.tmp import TemporaryDirectory
  9. __all__ = ['execute']
  10. def _unpack_args(args):
  11. '''Unpack command line arguments
  12. '''
  13. return args.tag, args.abi, args.bare, args.clean, args.no_packaging
  14. def execute(tag, abi, bare=False, clean=False, no_packaging=False):
  15. '''Build a Python AppImage using a Manylinux image
  16. '''
  17. image = ensure_image(tag, clean=clean)
  18. pwd = os.getcwd()
  19. with TemporaryDirectory() as tmpdir:
  20. python_extractor = PythonExtractor(
  21. arch = image.arch,
  22. prefix = image.path,
  23. tag = abi
  24. )
  25. appdir = Path(tmpdir) / 'AppDir'
  26. appify = not bare
  27. python_extractor.extract(appdir, appify=appify)
  28. fullname = '-'.join((
  29. f'{python_extractor.impl}{python_extractor.version.long()}',
  30. abi,
  31. f'{image.tag}_{image.arch}'
  32. ))
  33. if no_packaging:
  34. copy_tree(
  35. Path(tmpdir) / 'AppDir',
  36. Path(pwd) / fullname
  37. )
  38. elif bare:
  39. log('COMPRESS', fullname)
  40. destination = f'{fullname}.tar.gz'
  41. tar_path = Path(tmpdir) / destination
  42. with tarfile.open(tar_path, "w:gz") as tar:
  43. tar.add(appdir, arcname=fullname)
  44. copy_file(
  45. tar_path,
  46. Path(pwd) / destination
  47. )
  48. else:
  49. destination = f'{fullname}.AppImage'
  50. build_appimage(
  51. appdir = str(appdir),
  52. arch = str(image.arch),
  53. destination = destination
  54. )
  55. copy_file(
  56. Path(tmpdir) / destination,
  57. Path(pwd) / destination
  58. )