1
0

manylinux.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 _manylinux_tag(tag):
  16. '''Format Manylinux tag
  17. '''
  18. if tag.startswith('2_'):
  19. return 'manylinux_' + tag
  20. else:
  21. return 'manylinux' + tag
  22. def _get_appimage_name(abi, tag):
  23. '''Format the Python AppImage name using the ABI and OS tags
  24. '''
  25. # Read the Python version from the desktop file
  26. desktop = glob.glob('AppDir/python*.desktop')[0]
  27. fullversion = desktop[13:-8]
  28. # Finish building the AppImage on the host. See below.
  29. return 'python{:}-{:}-{:}.AppImage'.format(
  30. fullversion, abi, _manylinux_tag(tag))
  31. def execute(tag, abi, contained=False):
  32. '''Build a Python AppImage using a manylinux docker image
  33. '''
  34. if not contained:
  35. # Forward the build to a Docker image
  36. image = 'quay.io/pypa/' + _manylinux_tag(tag)
  37. python = '/opt/python/' + abi + '/bin/python'
  38. pwd = os.getcwd()
  39. dirname = os.path.abspath(os.path.dirname(__file__) + '/../..')
  40. with TemporaryDirectory() as tmpdir:
  41. copy_tree(dirname, 'python_appimage')
  42. argv = ' '.join(sys.argv[1:])
  43. if tag.startswith("1_"):
  44. # On manylinux1 tk is not installed
  45. script = [
  46. 'yum --disablerepo="*" --enablerepo=base install -q -y tk']
  47. else:
  48. # tk is already installed on other platforms
  49. script = []
  50. script += [
  51. python + ' -m python_appimage ' + argv + ' --contained',
  52. ''
  53. ]
  54. docker_run(image, script)
  55. appimage_name = _get_appimage_name(abi, tag)
  56. if tag.startswith('1_') or tag.startswith('2010_'):
  57. # appimagetool does not run on manylinux1 (CentOS 5) or
  58. # manylinux2010 (CentOS 6). Below is a patch for these specific
  59. # cases.
  60. arch = tag.split('_', 1)[-1]
  61. if arch == platform.machine():
  62. # Pack the image directly from the host
  63. build_appimage(destination=appimage_name)
  64. else:
  65. # Use a manylinux2014 Docker image (CentOS 7) in order to
  66. # pack the image.
  67. script = (
  68. 'python -m python_appimage ' + argv + ' --contained',
  69. ''
  70. )
  71. docker_run('quay.io/pypa/manylinux2014_' + arch, script)
  72. shutil.move(appimage_name, os.path.join(pwd, appimage_name))
  73. else:
  74. # We are running within a manylinux Docker image
  75. is_manylinux_old = tag.startswith('1_') or tag.startswith('2010_')
  76. if not os.path.exists('AppDir'):
  77. # Relocate the targeted manylinux Python installation
  78. relocate_python()
  79. else:
  80. # This is a second stage build. The Docker image has actually been
  81. # overriden (see above).
  82. is_manylinux_old = False
  83. if is_manylinux_old:
  84. # Build only the AppDir when running within a manylinux1 Docker
  85. # image because appimagetool does not support CentOS 5 or CentOS 6.
  86. pass
  87. else:
  88. build_appimage(destination=_get_appimage_name(abi, tag))