From 5cf73a59d62ab3c4b2f32a75ba3fd4c13eb375ec Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Thu, 22 May 2025 09:55:15 +0200 Subject: [PATCH] Build bare tarball --- python_appimage/__main__.py | 4 ++- python_appimage/commands/build/manylinux.py | 38 ++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/python_appimage/__main__.py b/python_appimage/__main__.py index eb9cb76..65d8ae2 100644 --- a/python_appimage/__main__.py +++ b/python_appimage/__main__.py @@ -79,7 +79,9 @@ def main(): build_manylinux_parser.add_argument('abi', help='python ABI (e.g. cp37-cp37m)') build_manylinux_parser.add_argument('-c', '--clean', - help='compress the image after extraction', action='store_true') + help='clean the cache after extraction', action='store_true') + build_manylinux_parser.add_argument('-t', '--tarball', + help='build a bare tarball instead of an AppImage', action='store_true') build_app_parser = build_subparsers.add_parser('app', description='Build a Python application using a base AppImage') diff --git a/python_appimage/commands/build/manylinux.py b/python_appimage/commands/build/manylinux.py index 4102a2e..08a8570 100644 --- a/python_appimage/commands/build/manylinux.py +++ b/python_appimage/commands/build/manylinux.py @@ -1,9 +1,11 @@ import os from pathlib import Path +import tarfile import shutil from ...appimage import build_appimage from ...manylinux import ensure_image, PythonExtractor +from ...utils.log import log from ...utils.tmp import TemporaryDirectory @@ -13,10 +15,10 @@ __all__ = ['execute'] def _unpack_args(args): '''Unpack command line arguments ''' - return args.tag, args.abi, args.clean + return args.tag, args.abi, args.clean, args.tarball -def execute(tag, abi, clean): +def execute(tag, abi, clean, tarball): '''Build a Python AppImage using a Manylinux image ''' @@ -30,7 +32,8 @@ def execute(tag, abi, clean): tag = abi ) appdir = Path(tmpdir) / 'AppDir' - python_extractor.extract(appdir, appify=True) + appify = not tarball + python_extractor.extract(appdir, appify=appify) fullname = '-'.join(( f'{python_extractor.impl}{python_extractor.version.long()}', @@ -38,12 +41,23 @@ def execute(tag, abi, clean): f'{image.tag}_{image.arch}' )) - destination = f'{fullname}.AppImage' - build_appimage( - appdir = str(appdir), - destination = destination - ) - shutil.copy( - Path(tmpdir) / destination, - Path(pwd) / destination - ) + if tarball: + log('COMPRESS', fullname) + destination = f'{fullname}.tgz' + tar_path = Path(tmpdir) / destination + with tarfile.open(tar_path, "w:gz") as tar: + tar.add(appdir, arcname=fullname) + shutil.copy( + tar_path, + Path(pwd) / destination + ) + else: + destination = f'{fullname}.AppImage' + build_appimage( + appdir = str(appdir), + destination = destination + ) + shutil.copy( + Path(tmpdir) / destination, + Path(pwd) / destination + )