1
0

manylinux.py 3.0 KB

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