Преглед на файлове

Patch some mistakes (according to flake8)

Valentin Niess преди 7 месеца
родител
ревизия
60aec8ba25

+ 4 - 6
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()

+ 6 - 5
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
     '''

+ 1 - 4
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)

+ 4 - 4
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)

+ 2 - 3
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'):

+ 1 - 18
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
     '''

+ 1 - 1
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))

+ 0 - 1
python_appimage/commands/which.py

@@ -1,7 +1,6 @@
 import os
 
 from ..utils import deps
-from ..utils.log import log
 
 
 __all__ = ['execute']

+ 0 - 1
python_appimage/manylinux/__init__.py

@@ -5,4 +5,3 @@ from .extract import ImageExtractor, PythonExtractor
 
 __all__ = ['Arch', 'Downloader', 'ImageExtractor', 'LinuxTag',
            'PythonExtractor', 'PythonImpl', 'PythonVersion']
-

+ 4 - 4
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)

+ 4 - 4
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)

+ 0 - 1
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')

+ 1 - 1
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)