mirror of
https://github.com/niess/python-appimage.git
synced 2026-03-14 04:10:15 +01:00
Update manylinux CLI
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import glob
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from ...appimage import build_appimage, relocate_python
|
||||
from ...manylinux import Arch, Downloader, ImageExtractor, LinuxTag, \
|
||||
PythonExtractor
|
||||
from ...utils.docker import docker_run
|
||||
from ...utils.fs import copy_tree
|
||||
from ...utils.manylinux import format_appimage_name, format_tag
|
||||
@@ -17,7 +20,7 @@ __all__ = ['execute']
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return args.tag, args.abi, args.contained
|
||||
return args.tag, args.abi
|
||||
|
||||
|
||||
def _get_appimage_name(abi, tag):
|
||||
@@ -31,74 +34,35 @@ def _get_appimage_name(abi, tag):
|
||||
return format_appimage_name(abi, fullversion, tag)
|
||||
|
||||
|
||||
def execute(tag, abi, contained=False):
|
||||
'''Build a Python AppImage using a manylinux docker image
|
||||
def execute(tag, abi):
|
||||
'''Build a Python AppImage using a Manylinux image
|
||||
'''
|
||||
|
||||
if not contained:
|
||||
# Forward the build to a Docker image
|
||||
image = 'quay.io/pypa/' + format_tag(tag)
|
||||
python = '/opt/python/' + abi + '/bin/python'
|
||||
tag, arch = tag.split('_', 1)
|
||||
tag = LinuxTag.from_brief(tag)
|
||||
arch = Arch.from_str(arch)
|
||||
|
||||
pwd = os.getcwd()
|
||||
dirname = os.path.abspath(os.path.dirname(__file__) + '/../..')
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
copy_tree(dirname, 'python_appimage')
|
||||
downloader = Downloader(tag=tag, arch=arch)
|
||||
downloader.download()
|
||||
|
||||
argv = sys.argv[1:]
|
||||
if argv:
|
||||
argv = ' '.join(argv)
|
||||
else:
|
||||
argv = 'build manylinux {:} {:}'.format(tag, abi)
|
||||
if tag.startswith("1_"):
|
||||
# On manylinux1 tk is not installed
|
||||
script = [
|
||||
'yum --disablerepo="*" --enablerepo=base install -q -y tk']
|
||||
else:
|
||||
# tk is already installed on other platforms
|
||||
script = []
|
||||
script += [
|
||||
python + ' -m python_appimage ' + argv + ' --contained',
|
||||
''
|
||||
]
|
||||
docker_run(image, script)
|
||||
image_extractor = ImageExtractor(downloader.default_destination())
|
||||
image_extractor.extract()
|
||||
|
||||
appimage_name = _get_appimage_name(abi, tag)
|
||||
pwd = os.getcwd()
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
python_extractor = PythonExtractor(
|
||||
arch = arch,
|
||||
prefix = image_extractor.default_destination(),
|
||||
tag = abi
|
||||
)
|
||||
appdir = Path(tmpdir) / 'AppDir'
|
||||
python_extractor.extract(appdir)
|
||||
|
||||
if tag.startswith('1_') or tag.startswith('2010_'):
|
||||
# appimagetool does not run on manylinux1 (CentOS 5) or
|
||||
# manylinux2010 (CentOS 6). Below is a patch for these specific
|
||||
# cases.
|
||||
arch = tag.split('_', 1)[-1]
|
||||
if arch == platform.machine():
|
||||
# Pack the image directly from the host
|
||||
build_appimage(destination=appimage_name)
|
||||
else:
|
||||
# Use a manylinux2014 Docker image (CentOS 7) in order to
|
||||
# pack the image.
|
||||
script = (
|
||||
'python -m python_appimage ' + argv + ' --contained',
|
||||
''
|
||||
)
|
||||
docker_run('quay.io/pypa/manylinux2014_' + arch, script)
|
||||
fullname = '-'.join((
|
||||
f'{python_extractor.impl}{python_extractor.version.long()}',
|
||||
abi,
|
||||
f'{tag}_{arch}'
|
||||
))
|
||||
shutil.move(appdir, os.path.join(pwd, fullname))
|
||||
|
||||
shutil.move(appimage_name, os.path.join(pwd, appimage_name))
|
||||
|
||||
else:
|
||||
# We are running within a manylinux Docker image
|
||||
is_manylinux_old = tag.startswith('1_') or tag.startswith('2010_')
|
||||
|
||||
if not os.path.exists('AppDir'):
|
||||
# Relocate the targeted manylinux Python installation
|
||||
relocate_python()
|
||||
else:
|
||||
# This is a second stage build. The Docker image has actually been
|
||||
# overriden (see above).
|
||||
is_manylinux_old = False
|
||||
|
||||
if is_manylinux_old:
|
||||
# Build only the AppDir when running within a manylinux1 Docker
|
||||
# image because appimagetool does not support CentOS 5 or CentOS 6.
|
||||
pass
|
||||
else:
|
||||
build_appimage(destination=_get_appimage_name(abi, tag))
|
||||
# XXX build_appimage(destination=_get_appimage_name(abi, tag))
|
||||
|
||||
Reference in New Issue
Block a user