Skip to content

Commit 4eb7011

Browse files
committed
Add install command & reorganize
1 parent ca80dd8 commit 4eb7011

9 files changed

Lines changed: 60 additions & 19 deletions

File tree

‎python_appimage/__main__.py‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,34 @@
1111
def main():
1212
# Parse arguments
1313
parser = argparse.ArgumentParser(
14-
description='Bundle a Python install into an AppImage')
15-
subparsers = parser.add_subparsers(title='builder',
16-
help='Appimage builder',
17-
dest='builder')
14+
prog='python-appimage',
15+
description='Bundle a Python installation into an AppImage')
16+
subparsers = parser.add_subparsers(title='command',
17+
help='Build or install command',
18+
dest='command')
1819

1920
parser.add_argument('-q', '--quiet', help='disable logging',
2021
dest='verbosity', action='store_const', const=logging.ERROR)
2122
parser.add_argument('-v', '--verbose', help='print extra information',
2223
dest='verbosity', action='store_const', const=logging.DEBUG)
2324

24-
local_parser = subparsers.add_parser('local')
25+
install_parser = subparsers.add_parser('install',
26+
description='Install binary dependencies')
27+
install_parser.add_argument('binary', nargs='+',
28+
choices=('appimagetool', 'patchelf'), help='one or more binary name')
29+
30+
local_parser = subparsers.add_parser('local',
31+
description='Bundle a local Python installation')
2532
local_parser.add_argument('-d', '--destination',
2633
help='AppImage destination')
2734
local_parser.add_argument('-p', '--python', help='python executable')
2835

29-
manylinux_parser = subparsers.add_parser('manylinux')
30-
manylinux_parser.add_argument('tag', help='manylinux image tag')
31-
manylinux_parser.add_argument('abi', help='python ABI')
36+
manylinux_parser = subparsers.add_parser('manylinux',
37+
description='Bundle a manylinux Python installation using docker')
38+
manylinux_parser.add_argument('tag',
39+
help='manylinux image tag (e.g. 2010_x86_64)')
40+
manylinux_parser.add_argument('abi',
41+
help='python ABI (e.g. cp37-cp37m)')
3242

3343
manylinux_parser.add_argument('--contained', help=argparse.SUPPRESS,
3444
action='store_true', default=False)
@@ -39,9 +49,10 @@ def main():
3949
if args.verbosity:
4050
logging.getLogger().setLevel(args.verbosity)
4151

42-
# Call the AppImage builder
43-
builder = import_module('.builders.' + args.builder, package=__package__)
44-
builder.build(*builder._unpack_args(args))
52+
# Call the requested command
53+
command = import_module('.commands.' +
54+
args.command, package=__package__)
55+
command.execute(*command._unpack_args(args))
4556

4657

4758
if __name__ == "__main__":
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
from ..utils import deps
4+
from ..utils.log import log
5+
6+
7+
8+
9+
__all__ = ['execute']
10+
11+
12+
def _unpack_args(args):
13+
'''Unpack command line arguments
14+
'''
15+
return args.binary
16+
17+
18+
def execute(*args):
19+
'''Install the requested dependencies
20+
'''
21+
bindir = os.path.dirname(deps.PATCHELF)
22+
for binary in args:
23+
installed = getattr(deps, 'ensure_' + binary)()
24+
words = 'has been' if installed else 'already'
25+
log('INSTALL',
26+
'{:} {:} installed in {:}'.format(binary, words, bindir))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import os
33
import shutil
44

5-
from ..actions import build_appimage, relocate_python
5+
from ..appimage import build_appimage, relocate_python
66
from ..utils.tmp import TemporaryDirectory
77

88

9-
__all__ = ['build']
9+
__all__ = ['execute']
1010

1111

1212
def _unpack_args(args):
@@ -15,7 +15,7 @@ def _unpack_args(args):
1515
return args.python, args.destination
1616

1717

18-
def build(python=None, destination=None):
18+
def execute(python=None, destination=None):
1919
'''Build a Python AppImage using a local installation
2020
'''
2121
pwd = os.getcwd()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import shutil
55
import sys
66

7-
from ..actions import build_appimage, relocate_python
7+
from ..appimage import build_appimage, relocate_python
88
from ..utils.docker import docker_run
99
from ..utils.fs import copy_tree
1010
from ..utils.tmp import TemporaryDirectory
1111

1212

13-
__all__ = ['build']
13+
__all__ = ['execute']
1414

1515

1616
def _unpack_args(args):
@@ -31,7 +31,7 @@ def _get_appimage_name(abi, tag):
3131
fullversion, abi, tag)
3232

3333

34-
def build(tag, abi, contained=False):
34+
def execute(tag, abi, contained=False):
3535
'''Build a Python AppImage using a manylinux docker image
3636
'''
3737

‎python_appimage/utils/deps.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def ensure_appimagetool():
3333
'''Fetch appimagetool from the web if not available locally
3434
'''
3535
if os.path.exists(APPIMAGETOOL):
36-
return
36+
return False
3737

3838
appimage = 'appimagetool-{0:}.AppImage'.format(_ARCH)
3939
baseurl = 'https://github.com/AppImage/AppImageKit/releases/' \
@@ -53,6 +53,8 @@ def ensure_appimagetool():
5353
if not os.path.exists(APPIMAGETOOL):
5454
os.symlink(appdir_name + '/AppRun', APPIMAGETOOL)
5555

56+
return True
57+
5658

5759
# Installers for dependencies
5860
def ensure_excludelist():
@@ -72,7 +74,7 @@ def ensure_patchelf():
7274
'''Fetch PatchELF from the web if not available locally
7375
'''
7476
if os.path.exists(PATCHELF):
75-
return
77+
return False
7678

7779
iarch = 'i386' if _ARCH == 'i686' else _ARCH
7880
appimage = 'patchelf-{0:}.AppImage'.format(iarch)
@@ -88,3 +90,5 @@ def ensure_patchelf():
8890
system('./' + appimage, '--appimage-extract')
8991
copy_file('squashfs-root/usr/bin/patchelf', patchelf)
9092
os.chmod(patchelf, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
93+
94+
return True

0 commit comments

Comments
 (0)