manylinux.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import glob
  2. import os
  3. from pathlib import Path
  4. import platform
  5. import shutil
  6. import sys
  7. from ...appimage import build_appimage, relocate_python
  8. from ...manylinux import Arch, Downloader, ImageExtractor, LinuxTag, \
  9. PythonExtractor
  10. from ...utils.docker import docker_run
  11. from ...utils.fs import copy_tree
  12. from ...utils.manylinux import format_appimage_name, format_tag
  13. from ...utils.tmp import TemporaryDirectory
  14. __all__ = ['execute']
  15. def _unpack_args(args):
  16. '''Unpack command line arguments
  17. '''
  18. return args.tag, args.abi
  19. def _get_appimage_name(abi, tag):
  20. '''Format the Python AppImage name using the ABI and OS tags
  21. '''
  22. # Read the Python version from the desktop file
  23. desktop = glob.glob('AppDir/python*.desktop')[0]
  24. fullversion = desktop[13:-8]
  25. # Finish building the AppImage on the host. See below.
  26. return format_appimage_name(abi, fullversion, tag)
  27. def execute(tag, abi):
  28. '''Build a Python AppImage using a Manylinux image
  29. '''
  30. tag, arch = tag.split('_', 1)
  31. tag = LinuxTag.from_brief(tag)
  32. arch = Arch.from_str(arch)
  33. downloader = Downloader(tag=tag, arch=arch)
  34. downloader.download()
  35. image_extractor = ImageExtractor(downloader.default_destination())
  36. image_extractor.extract()
  37. pwd = os.getcwd()
  38. with TemporaryDirectory() as tmpdir:
  39. python_extractor = PythonExtractor(
  40. arch = arch,
  41. prefix = image_extractor.default_destination(),
  42. tag = abi
  43. )
  44. appdir = Path(tmpdir) / 'AppDir'
  45. python_extractor.extract(appdir, appify=True)
  46. fullname = '-'.join((
  47. f'{python_extractor.impl}{python_extractor.version.long()}',
  48. abi,
  49. f'{tag}_{arch}'
  50. ))
  51. destination = f'{fullname}.AppImage'
  52. build_appimage(
  53. appdir = str(appdir),
  54. destination = destination
  55. )
  56. shutil.move(
  57. Path(tmpdir) / destination,
  58. Path(pwd) / destination
  59. )