mirror of
https://github.com/niess/python-appimage.git
synced 2026-03-14 04:10:15 +01:00
Add install command & reorganize
This commit is contained in:
0
python_appimage/commands/__init__.py
Normal file
0
python_appimage/commands/__init__.py
Normal file
26
python_appimage/commands/install.py
Normal file
26
python_appimage/commands/install.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
from ..utils import deps
|
||||
from ..utils.log import log
|
||||
|
||||
|
||||
|
||||
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return args.binary
|
||||
|
||||
|
||||
def execute(*args):
|
||||
'''Install the requested dependencies
|
||||
'''
|
||||
bindir = os.path.dirname(deps.PATCHELF)
|
||||
for binary in args:
|
||||
installed = getattr(deps, 'ensure_' + binary)()
|
||||
words = 'has been' if installed else 'already'
|
||||
log('INSTALL',
|
||||
'{:} {:} installed in {:}'.format(binary, words, bindir))
|
||||
39
python_appimage/commands/local.py
Normal file
39
python_appimage/commands/local.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from ..appimage import build_appimage, relocate_python
|
||||
from ..utils.tmp import TemporaryDirectory
|
||||
|
||||
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return args.python, args.destination
|
||||
|
||||
|
||||
def execute(python=None, destination=None):
|
||||
'''Build a Python AppImage using a local installation
|
||||
'''
|
||||
pwd = os.getcwd()
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
relocate_python(python)
|
||||
|
||||
dirname, pattern = None, None
|
||||
if destination is not None:
|
||||
dirname, destination = os.path.split(destination)
|
||||
pattern = destination
|
||||
if pattern is None:
|
||||
pattern = 'python*.AppImage'
|
||||
build_appimage(destination=destination)
|
||||
appimage = glob.glob(pattern)[0]
|
||||
if dirname is None:
|
||||
dirname = pwd
|
||||
else:
|
||||
os.chdir(pwd)
|
||||
dirname = os.path.abspath(dirname)
|
||||
os.chdir(tmpdir)
|
||||
shutil.move(appimage, os.path.join(dirname, appimage))
|
||||
93
python_appimage/commands/manylinux.py
Normal file
93
python_appimage/commands/manylinux.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import glob
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from ..appimage import build_appimage, relocate_python
|
||||
from ..utils.docker import docker_run
|
||||
from ..utils.fs import copy_tree
|
||||
from ..utils.tmp import TemporaryDirectory
|
||||
|
||||
|
||||
__all__ = ['execute']
|
||||
|
||||
|
||||
def _unpack_args(args):
|
||||
'''Unpack command line arguments
|
||||
'''
|
||||
return args.tag, args.abi, args.contained
|
||||
|
||||
|
||||
def _get_appimage_name(abi, tag):
|
||||
'''Format the Python AppImage name using the ABI and OS tags
|
||||
'''
|
||||
# Read the Python version from the desktop file
|
||||
desktop = glob.glob('AppDir/python*.desktop')[0]
|
||||
fullversion = desktop[13:-8]
|
||||
|
||||
# Finish building the AppImage on the host. See below.
|
||||
return 'python{:}-{:}-manylinux{:}.AppImage'.format(
|
||||
fullversion, abi, tag)
|
||||
|
||||
|
||||
def execute(tag, abi, contained=False):
|
||||
'''Build a Python AppImage using a manylinux docker image
|
||||
'''
|
||||
|
||||
if not contained:
|
||||
# Forward the build to a Docker image
|
||||
image = 'quay.io/pypa/manylinux' + tag
|
||||
python = '/opt/python/' + abi + '/bin/python'
|
||||
|
||||
pwd = os.getcwd()
|
||||
dirname = os.path.abspath(os.path.dirname(__file__) + '/..')
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
copy_tree(dirname, 'python_appimage')
|
||||
|
||||
argv = ' '.join(sys.argv[1:])
|
||||
script = (
|
||||
'yum --disablerepo="*" --enablerepo=base install -q -y tk',
|
||||
python + ' -m python_appimage ' + argv + ' --contained',
|
||||
''
|
||||
)
|
||||
docker_run(image, script)
|
||||
|
||||
appimage_name = _get_appimage_name(abi, tag)
|
||||
|
||||
if tag.startswith('1_'):
|
||||
# appimagetool does not run on manylinux1 (CentOS 5). Below is
|
||||
# a patch for this specific case.
|
||||
arch = tag.split('_', 1)[-1]
|
||||
if arch == platform.machine():
|
||||
# Pack the image directly from the host
|
||||
build_appimage(destination=appimage_name)
|
||||
else:
|
||||
# Use a manylinux2010 Docker image (CentOS 6) in order to
|
||||
# pack the image.
|
||||
script = (
|
||||
python + ' -m python_appimage ' + argv + ' --contained',
|
||||
''
|
||||
)
|
||||
docker_run('quay.io/pypa/manylinux2010_' + arch, script)
|
||||
|
||||
shutil.move(appimage_name, os.path.join(pwd, appimage_name))
|
||||
|
||||
else:
|
||||
# We are running within a manylinux Docker image
|
||||
is_manylinux1 = tag.startswith('1_')
|
||||
|
||||
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_manylinux1 = False
|
||||
|
||||
if is_manylinux1:
|
||||
# Build only the AppDir when running within a manylinux1 Docker
|
||||
# image because appimagetool does not support CentOS 5.
|
||||
pass
|
||||
else:
|
||||
build_appimage(destination=_get_appimage_name(abi, tag))
|
||||
Reference in New Issue
Block a user