Переглянути джерело

Relocate local and manylinux under a build command

Valentin Niess 5 роки тому
батько
коміт
83ee9e5f0c

+ 3 - 1
.github/workflows/appimage.yml

@@ -26,7 +26,7 @@ jobs:
     - name: Build
       run: |
         # Build the AppImage
-        python -m python_appimage manylinux \
+        python -m python_appimage build manylinux \
           ${{ matrix.image }}_${{ matrix.arch }} \
           ${{ matrix.tag }}
 
@@ -43,6 +43,7 @@ jobs:
         echo "::set-env name=PYTHON_VERSION::${version}"
 
     - uses: actions/upload-artifact@v1
+      if: github.ref == 'refs/heads/master'
       with:
         name: python${{ env.PYTHON_VERSION }}-appimages
         path: ${{ env.PYTHON_APPIMAGE }}
@@ -50,6 +51,7 @@ jobs:
   Release:
     needs: Build
     runs-on: ubuntu-latest
+    if: github.ref == 'refs/heads/master'
     strategy:
       matrix:
         version: [2.7, 3.5, 3.6, 3.7, 3.8]

+ 3 - 1
.github/workflows/pypi.yml

@@ -23,12 +23,14 @@ jobs:
 
     - name: Test local builder
       run: |
-        python -m python_appimage local -p $(which python) -d test.AppImage
+        python -m python_appimage build local -p $(which python) \
+                                              -d test.AppImage
         test -e test.AppImage
 
   Publish:
     needs: Test
     runs-on: ubuntu-latest
+    if: github.ref == 'refs/heads/master'
 
     steps:
     - uses: actions/checkout@v2

+ 2 - 1
.gitignore

@@ -3,9 +3,10 @@
 *.pyo
 __pycache__
 AppDir
-build
+build/*
 dist
 python_appimage.egg-info
 python_appimage/bin
 python_appimage/data/excludelist
 python_appimage/version.py
+!python_appimage/commands/build

+ 20 - 12
python_appimage/__main__.py

@@ -15,13 +15,12 @@ def main():
     # Binary dependencies
     binaries = ('appimagetool', 'patchelf')
 
-
     # Parse arguments
     parser = argparse.ArgumentParser(
         prog='python-appimage',
         description='Bundle a Python installation into an AppImage')
     subparsers = parser.add_subparsers(title='command',
-                                       help='Build or install command',
+                                       help='Command to execute',
                                        dest='command')
 
     parser.add_argument('-q', '--quiet', help='disable logging',
@@ -34,21 +33,28 @@ def main():
     install_parser.add_argument('binary', nargs='+',
         choices=binaries, help='one or more binary name')
 
-    local_parser = subparsers.add_parser('local',
+    build_parser = subparsers.add_parser('build',
+        description='Build a Python appimage')
+    build_subparsers = build_parser.add_subparsers(
+                           title='type',
+                           help='Type of AppImage build',
+                           dest='sub_command')
+
+    build_local_parser = build_subparsers.add_parser('local',
         description='Bundle a local Python installation')
-    local_parser.add_argument('-d', '--destination',
+    build_local_parser.add_argument('-d', '--destination',
                               help='AppImage destination')
-    local_parser.add_argument('-p', '--python', help='python executable')
+    build_local_parser.add_argument('-p', '--python', help='python executable')
 
-    manylinux_parser = subparsers.add_parser('manylinux',
+    build_manylinux_parser = build_subparsers.add_parser('manylinux',
         description='Bundle a manylinux Python installation using docker')
-    manylinux_parser.add_argument('tag',
+    build_manylinux_parser.add_argument('tag',
         help='manylinux image tag (e.g. 2010_x86_64)')
-    manylinux_parser.add_argument('abi',
+    build_manylinux_parser.add_argument('abi',
         help='python ABI (e.g. cp37-cp37m)')
 
-    manylinux_parser.add_argument('--contained', help=argparse.SUPPRESS,
-                                  action='store_true', default=False)
+    build_manylinux_parser.add_argument('--contained', help=argparse.SUPPRESS,
+                                        action='store_true', default=False)
 
     which_parser = subparsers.add_parser('which',
         description='Locate a binary dependency')
@@ -62,8 +68,10 @@ def main():
         logging.getLogger().setLevel(args.verbosity)
 
     # Call the requested command
-    command = import_module('.commands.' +
-                            args.command, package=__package__)
+    module = '.commands.' + args.command
+    if args.sub_command:
+        module += '.' + args.sub_command
+    command = import_module(module, package=__package__)
     command.execute(*command._unpack_args(args))
 
 

+ 0 - 0
python_appimage/commands/build/__init__.py


+ 2 - 2
python_appimage/commands/local.py → python_appimage/commands/build/local.py

@@ -2,8 +2,8 @@ import glob
 import os
 import shutil
 
-from ..appimage import build_appimage, relocate_python
-from ..utils.tmp import TemporaryDirectory
+from ...appimage import build_appimage, relocate_python
+from ...utils.tmp import TemporaryDirectory
 
 
 __all__ = ['execute']

+ 5 - 5
python_appimage/commands/manylinux.py → python_appimage/commands/build/manylinux.py

@@ -4,10 +4,10 @@ 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
+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']
@@ -41,7 +41,7 @@ def execute(tag, abi, contained=False):
         python = '/opt/python/' + abi + '/bin/python'
 
         pwd = os.getcwd()
-        dirname = os.path.abspath(os.path.dirname(__file__) + '/..')
+        dirname = os.path.abspath(os.path.dirname(__file__) + '/../..')
         with TemporaryDirectory() as tmpdir:
             copy_tree(dirname, 'python_appimage')