manylinux.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import glob
  2. import os
  3. import platform
  4. import shutil
  5. import sys
  6. from ..appimage import build_appimage, relocate_python
  7. from ..utils.docker import docker_run
  8. from ..utils.fs import copy_tree
  9. from ..utils.tmp import TemporaryDirectory
  10. __all__ = ['execute']
  11. def _unpack_args(args):
  12. '''Unpack command line arguments
  13. '''
  14. return args.tag, args.abi, args.contained
  15. def _get_appimage_name(abi, tag):
  16. '''Format the Python AppImage name using the ABI and OS tags
  17. '''
  18. # Read the Python version from the desktop file
  19. desktop = glob.glob('AppDir/python*.desktop')[0]
  20. fullversion = desktop[13:-8]
  21. # Finish building the AppImage on the host. See below.
  22. return 'python{:}-{:}-manylinux{:}.AppImage'.format(
  23. fullversion, abi, tag)
  24. def execute(tag, abi, contained=False):
  25. '''Build a Python AppImage using a manylinux docker image
  26. '''
  27. if not contained:
  28. # Forward the build to a Docker image
  29. image = 'quay.io/pypa/manylinux' + tag
  30. python = '/opt/python/' + abi + '/bin/python'
  31. pwd = os.getcwd()
  32. dirname = os.path.abspath(os.path.dirname(__file__) + '/..')
  33. with TemporaryDirectory() as tmpdir:
  34. copy_tree(dirname, 'python_appimage')
  35. argv = ' '.join(sys.argv[1:])
  36. script = (
  37. 'yum --disablerepo="*" --enablerepo=base install -q -y tk',
  38. python + ' -m python_appimage ' + argv + ' --contained',
  39. ''
  40. )
  41. docker_run(image, script)
  42. appimage_name = _get_appimage_name(abi, tag)
  43. if tag.startswith('1_'):
  44. # appimagetool does not run on manylinux1 (CentOS 5). Below is
  45. # a patch for this specific case.
  46. arch = tag.split('_', 1)[-1]
  47. if arch == platform.machine():
  48. # Pack the image directly from the host
  49. build_appimage(destination=appimage_name)
  50. else:
  51. # Use a manylinux2010 Docker image (CentOS 6) in order to
  52. # pack the image.
  53. script = (
  54. python + ' -m python_appimage ' + argv + ' --contained',
  55. ''
  56. )
  57. docker_run('quay.io/pypa/manylinux2010_' + arch, script)
  58. shutil.move(appimage_name, os.path.join(pwd, appimage_name))
  59. else:
  60. # We are running within a manylinux Docker image
  61. is_manylinux1 = tag.startswith('1_')
  62. if not os.path.exists('AppDir'):
  63. # Relocate the targeted manylinux Python installation
  64. relocate_python()
  65. else:
  66. # This is a second stage build. The Docker image has actually been
  67. # overriden (see above).
  68. is_manylinux1 = False
  69. if is_manylinux1:
  70. # Build only the AppDir when running within a manylinux1 Docker
  71. # image because appimagetool does not support CentOS 5.
  72. pass
  73. else:
  74. build_appimage(destination=_get_appimage_name(abi, tag))