From 60aec8ba258c4625fe465708a32d1bc16c54107e Mon Sep 17 00:00:00 2001 From: Valentin Niess Date: Tue, 20 May 2025 23:27:20 +0200 Subject: [PATCH] Patch some mistakes (according to flake8) --- python_appimage/__main__.py | 10 ++++------ python_appimage/appimage/appify.py | 11 ++++++----- python_appimage/appimage/build.py | 5 +---- python_appimage/appimage/relocate.py | 8 ++++---- python_appimage/commands/build/app.py | 5 ++--- python_appimage/commands/build/manylinux.py | 19 +------------------ python_appimage/commands/install.py | 2 +- python_appimage/commands/which.py | 1 - python_appimage/manylinux/__init__.py | 1 - python_appimage/manylinux/download.py | 8 ++++---- python_appimage/manylinux/extract.py | 8 ++++---- python_appimage/utils/deps.py | 1 - python_appimage/utils/url.py | 2 +- 13 files changed, 28 insertions(+), 53 deletions(-) diff --git a/python_appimage/__main__.py b/python_appimage/__main__.py index fa45fc8..314e0bb 100644 --- a/python_appimage/__main__.py +++ b/python_appimage/__main__.py @@ -1,7 +1,6 @@ import argparse from importlib import import_module import os -import sys __all__ = ['main'] @@ -12,6 +11,7 @@ def exists(path): raise argparse.ArgumentTypeError("could not find: {}".format(path)) return os.path.abspath(path) + def main(): '''Entry point for the CLI ''' @@ -41,10 +41,8 @@ def main(): 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_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') @@ -124,5 +122,5 @@ def main(): command.execute(*command._unpack_args(args)) -if __name__ == "__main__": +if __name__ == '__main__': main() diff --git a/python_appimage/appimage/appify.py b/python_appimage/appimage/appify.py index 817f56d..401fd68 100644 --- a/python_appimage/appimage/appify.py +++ b/python_appimage/appimage/appify.py @@ -1,17 +1,17 @@ from dataclasses import dataclass import glob import os -import re -from typing import Optional, Tuple +from typing import Optional from ..utils.deps import PREFIX -from ..utils.fs import copy_file, copy_tree, make_tree, remove_file, remove_tree -from ..utils.log import debug, log +from ..utils.fs import copy_file, make_tree, remove_file +from ..utils.log import log from ..utils.template import copy_template, load_template @dataclass(frozen=True) class Appifier: + '''Helper class for bundling AppImage specific files''' '''Path to AppDir root.''' appdir: str @@ -34,8 +34,8 @@ class Appifier: '''Path to SSL certification file.''' cert_src: Optional[str]=None - def appify(self): + '''Bundle Appimage specific files''' python_x_y = f'python{self.version.short()}' pip_x_y = f'pip{self.version.short()}' @@ -227,6 +227,7 @@ export TKPATH="${{TK_LIBRARY}}"'''.format( else: return '' + def set_executable_patch(version, pkgpath, patch): '''Set a runtime patch for sys.executable name ''' diff --git a/python_appimage/appimage/build.py b/python_appimage/appimage/build.py index 7cc4f0a..1216d03 100644 --- a/python_appimage/appimage/build.py +++ b/python_appimage/appimage/build.py @@ -6,10 +6,7 @@ import sys from ..utils.compat import decode from ..utils.deps import ensure_appimagetool -from ..utils.docker import docker_run -from ..utils.fs import copy_tree from ..utils.log import debug, log -from ..utils.tmp import TemporaryDirectory __all__ = ['build_appimage'] @@ -36,7 +33,7 @@ def build_appimage(appdir=None, destination=None): appimage_pattern = re.compile('should be packaged as ([^ ]+[.]AppImage)') - stdout, appimage = [], None + stdout = [] while True: out = decode(p.stdout.readline()) stdout.append(out) diff --git a/python_appimage/appimage/relocate.py b/python_appimage/appimage/relocate.py index 9521296..b718771 100644 --- a/python_appimage/appimage/relocate.py +++ b/python_appimage/appimage/relocate.py @@ -6,10 +6,11 @@ import sys from .appify import Appifier from ..manylinux import PythonVersion -from ..utils.deps import EXCLUDELIST, PATCHELF, PREFIX, ensure_excludelist, \ +from ..utils.deps import EXCLUDELIST, PATCHELF, ensure_excludelist, \ ensure_patchelf -from ..utils.fs import copy_file, copy_tree, make_tree, remove_file, remove_tree -from ..utils.log import debug, log +from ..utils.fs import copy_file, copy_tree, make_tree, remove_file, \ + remove_tree +from ..utils.log import log from ..utils.system import ldd, system @@ -55,7 +56,6 @@ def patch_binary(path, libdir, recursive=True): continue target = libdir + '/' + name if not os.path.exists(target): - libname = os.path.basename(dep) copy_file(dep, target) if recursive: patch_binary(target, libdir, recursive=True) diff --git a/python_appimage/commands/build/app.py b/python_appimage/commands/build/app.py index 856c643..7869b8e 100644 --- a/python_appimage/commands/build/app.py +++ b/python_appimage/commands/build/app.py @@ -8,7 +8,7 @@ import stat import struct from ...appimage import build_appimage -from ...utils.compat import decode, find_spec +from ...utils.compat import find_spec from ...utils.deps import PREFIX from ...utils.fs import copy_file, copy_tree, make_tree, remove_file, remove_tree from ...utils.log import log @@ -33,6 +33,7 @@ def _unpack_args(args): _tag_pattern = re.compile('python([^-]+)[-]([^.]+)[.]AppImage') _linux_pattern = re.compile('manylinux([0-9]+)_' + platform.machine()) + def execute(appdir, name=None, python_version=None, linux_tag=None, python_tag=None, base_image=None, in_tree_build=False, extra_data=None): @@ -311,8 +312,6 @@ def execute(appdir, name=None, python_version=None, linux_tag=None, shebang = '#! /bin/bash' entrypoint = load_template(entrypoint_path, **dictionary) - python_pkg = 'AppDir/opt/python{0:}/lib/python{0:}'.format( - python_version) dictionary = {'entrypoint': entrypoint, 'shebang': shebang} if os.path.exists('AppDir/AppRun'): diff --git a/python_appimage/commands/build/manylinux.py b/python_appimage/commands/build/manylinux.py index 3245c3e..c655f94 100644 --- a/python_appimage/commands/build/manylinux.py +++ b/python_appimage/commands/build/manylinux.py @@ -1,16 +1,10 @@ -import glob import os from pathlib import Path -import platform import shutil -import sys -from ...appimage import build_appimage, relocate_python +from ...appimage import build_appimage 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 from ...utils.tmp import TemporaryDirectory @@ -23,17 +17,6 @@ def _unpack_args(args): return args.tag, args.abi -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 format_appimage_name(abi, fullversion, tag) - - def execute(tag, abi): '''Build a Python AppImage using a Manylinux image ''' diff --git a/python_appimage/commands/install.py b/python_appimage/commands/install.py index 4c16303..e719c2e 100644 --- a/python_appimage/commands/install.py +++ b/python_appimage/commands/install.py @@ -19,6 +19,6 @@ def execute(*args): bindir = os.path.dirname(deps.PATCHELF) for binary in args: installed = getattr(deps, 'ensure_' + binary)() - words = 'has been' if installed else 'already' + words = 'has been' if installed else 'already' log('INSTALL', '{:} {:} installed in {:}'.format(binary, words, bindir)) diff --git a/python_appimage/commands/which.py b/python_appimage/commands/which.py index a1c189b..617e7ed 100644 --- a/python_appimage/commands/which.py +++ b/python_appimage/commands/which.py @@ -1,7 +1,6 @@ import os from ..utils import deps -from ..utils.log import log __all__ = ['execute'] diff --git a/python_appimage/manylinux/__init__.py b/python_appimage/manylinux/__init__.py index 12c94ad..7dcda3a 100644 --- a/python_appimage/manylinux/__init__.py +++ b/python_appimage/manylinux/__init__.py @@ -5,4 +5,3 @@ from .extract import ImageExtractor, PythonExtractor __all__ = ['Arch', 'Downloader', 'ImageExtractor', 'LinuxTag', 'PythonExtractor', 'PythonImpl', 'PythonVersion'] - diff --git a/python_appimage/manylinux/download.py b/python_appimage/manylinux/download.py index cb8f3d4..33c798a 100644 --- a/python_appimage/manylinux/download.py +++ b/python_appimage/manylinux/download.py @@ -1,4 +1,3 @@ -import collections from dataclasses import dataclass, field import glob import hashlib @@ -7,7 +6,7 @@ from pathlib import Path import requests import shutil import tempfile -from typing import List, Optional +from typing import Optional from .config import Arch, LinuxTag from ..utils.deps import CACHE_DIR @@ -22,6 +21,7 @@ SUCCESS = 200 class DownloadError(Exception): pass + class TarError(Exception): pass @@ -135,7 +135,7 @@ class Downloader: hasher = hashlib.sha256() tmp = workdir / 'layer.tgz' with open(tmp, "wb") as f: - for chunk in r.iter_content(CHUNK_SIZE): + for chunk in r.iter_content(CHUNK_SIZE): if chunk: f.write(chunk) hasher.update(chunk) @@ -143,7 +143,7 @@ class Downloader: h = hasher.hexdigest() if h != hash_: raise DownloadError( - f'bad hash (expected {name}, found {h})' + f'bad hash (expected {hash_}, found {h})' ) layers_dir = destination / 'layers' layers_dir.mkdir(exist_ok=True, parents=True) diff --git a/python_appimage/manylinux/extract.py b/python_appimage/manylinux/extract.py index bb55de7..f9f316c 100644 --- a/python_appimage/manylinux/extract.py +++ b/python_appimage/manylinux/extract.py @@ -9,7 +9,7 @@ from pathlib import Path import shutil import stat import subprocess -from typing import Dict, List, NamedTuple, Optional, Union +from typing import Dict, List, Optional from .config import Arch, PythonImpl, PythonVersion from ..appimage import Appifier @@ -307,7 +307,7 @@ class PythonExtractor: if (match not in dependencies) and (match not in self.excluded): path = self.locate_library(match) dependencies[match] = path - subs = recurse(path) + recurse(path) recurse(target) return dependencies @@ -396,5 +396,5 @@ class ImageExtractor: f'tar -xzf {filename} -C {destination} && ', f'echo \'{layer}\' >> {extracted_file}' )) - process = subprocess.run(f'/bin/bash -c "{cmd}"', shell=True, - check=True, capture_output=True) + subprocess.run(f'/bin/bash -c "{cmd}"', shell=True, + check=True, capture_output=True) diff --git a/python_appimage/utils/deps.py b/python_appimage/utils/deps.py index 0469e80..ad6689f 100644 --- a/python_appimage/utils/deps.py +++ b/python_appimage/utils/deps.py @@ -41,7 +41,6 @@ def ensure_appimagetool(dry=False): appimagetool_name = 'appimagetool' else: appimagetool_name = 'appimagetool-' + APPIMAGETOOL_VERSION - appimagetool = os.path.join(APPIMAGETOOL_DIR, appimagetool_name) appdir_name = '.'.join(('', appimagetool_name, 'appdir', _ARCH)) appdir = os.path.join(APPIMAGETOOL_DIR, appdir_name) apprun = os.path.join(appdir, 'AppRun') diff --git a/python_appimage/utils/url.py b/python_appimage/utils/url.py index 5dc98fd..c2d7f2b 100644 --- a/python_appimage/utils/url.py +++ b/python_appimage/utils/url.py @@ -28,7 +28,7 @@ def urlretrieve(url, filename=None): ''' if filename is None: filename = os.path.basename(url) - debug('DOWNLOAD', '%s from %s', name, os.path.dirname(url)) + debug('DOWNLOAD', '%s from %s', filename, os.path.dirname(url)) else: debug('DOWNLOAD', '%s as %s', url, filename)