[Git][reproducible-builds/diffoscope][master] 3 commits: Tidy inline imports in diffoscope.logging.

Chris Lamb gitlab at salsa.debian.org
Wed Jul 15 11:16:53 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
065a7e4e by Chris Lamb at 2020-07-15T11:47:49+01:00
Tidy inline imports in diffoscope.logging.

- - - - -
5f41afe4 by Chris Lamb at 2020-07-15T11:54:36+01:00
Replace some simple usages of str.format with f-strings.

- - - - -
cd9e526b by Chris Lamb at 2020-07-15T11:55:37+01:00
In the RData comparator, always explicitly return a None value in the failure cases as we return a non-None value in the "success" one.

- - - - -


9 changed files:

- diffoscope/comparators/__init__.py
- diffoscope/comparators/apk.py
- diffoscope/comparators/elf.py
- diffoscope/comparators/json.py
- diffoscope/comparators/macho.py
- diffoscope/comparators/pdf.py
- diffoscope/comparators/rdata.py
- diffoscope/comparators/zip.py
- diffoscope/logging.py


Changes:

=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -130,7 +130,7 @@ class ComparatorManager:
 
                 try:
                     mod = importlib.import_module(
-                        "diffoscope.comparators.{}".format(package)
+                        f"diffoscope.comparators.{package}",
                     )
                 except ModuleNotFoundError as e:
                     python_module_missing(e.name)


=====================================
diffoscope/comparators/apk.py
=====================================
@@ -86,7 +86,7 @@ class ApkContainer(Archive):
                         "-d",
                         self._unpacked,
                         self.source.path,
-                        "classes{}.dex".format(x),
+                        f"classes{x}.dex",
                     ),
                     stderr=subprocess.PIPE,
                     stdout=subprocess.PIPE,


=====================================
diffoscope/comparators/elf.py
=====================================
@@ -156,7 +156,7 @@ class ReadelfDebugDump(Readelf):
 
 READELF_DEBUG_DUMP_COMMANDS = [
     type(
-        "ReadelfDebugDump_{}".format(x),
+        f"ReadelfDebugDump_{x}",
         (ReadelfDebugDump,),
         {"_debug_section_group": x},
     )


=====================================
diffoscope/comparators/json.py
=====================================
@@ -92,7 +92,7 @@ class JSONFile(File):
 
         similarity = jsondiff.similarity(a, b)
         if similarity:
-            difference.add_comment("Similarity: {}%".format(similarity))
+            difference.add_comment(f"Similarity: {similarity}%")
 
         difference.add_comment(
             "Differences: {}".format(


=====================================
diffoscope/comparators/macho.py
=====================================
@@ -43,7 +43,7 @@ class Otool(Command):
 
     def filter(self, line):
         # Strip filename
-        prefix = "{}:".format(self._path)
+        prefix = f"{self._path}:"
         if line.decode("utf-8", "ignore").startswith(prefix):
             return line[len(prefix) :].strip()
         return line


=====================================
diffoscope/comparators/pdf.py
=====================================
@@ -82,7 +82,7 @@ class PdfFile(File):
             pdf = PyPDF2.PdfFileReader(file.path)
             document_info = pdf.getDocumentInfo()
         except PyPDF2.utils.PdfReadError as e:
-            return "(Could not extract metadata: {})".format(e)
+            return f"(Could not extract metadata: {e})"
 
         if document_info is None:
             return ""


=====================================
diffoscope/comparators/rdata.py
=====================================
@@ -90,7 +90,7 @@ def get_module_path_for_rdb(rdb):
     # If we are not in a container, we will never be able to locate the
     # corresponding .rdx
     if rdb.container is None:
-        return
+        return None
 
     # Calculate location of parallel .rdx file
     rdx_name = "{}.rdx".format(os.path.splitext(rdb.name)[0])
@@ -105,14 +105,14 @@ def get_module_path_for_rdb(rdb):
 
     if not os.path.exists(rdx.path):
         # Corresponding .rdx does not exist
-        return
+        return None
 
     temp_dir = get_temporary_directory().name
     prefix = os.path.join(temp_dir, "temp")
 
     logger.debug("Copying %s and %s to %s", rdx.path, rdb.path, temp_dir)
-    shutil.copy(rdb.path, "{}.rdb".format(prefix))
-    shutil.copy(rdx.path, "{}.rdx".format(prefix))
+    shutil.copy(rdb.path, f"{prefix}.rdb")
+    shutil.copy(rdx.path, f"{prefix}.rdx")
 
     # Return the "module" path, ie. without an extension
     return os.path.join(temp_dir, "temp")


=====================================
diffoscope/comparators/zip.py
=====================================
@@ -107,7 +107,7 @@ class Zipnote(Command):
         if line.startswith(b"@ "):
             filename = line[2:-1].decode()
             self.flag = True
-            return "Filename: {}\nComment: ".format(filename).encode()
+            return f"Filename: {filename}\nComment: ".encode()
 
         return line[:-1] if self.flag else b""
 


=====================================
diffoscope/logging.py
=====================================
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2020 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,24 +17,24 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import sys
 import contextlib
+import curses
 import logging
+import shutil
+import sys
 
 
 def line_eraser(fd=sys.stderr) -> bytes:
     eraser = b""  # avoid None to avoid 'NoneType + str/bytes' failures
     if fd.isatty():
-        from curses import tigetstr, setupterm
 
-        setupterm(fd=fd.fileno())
-        eraser = tigetstr("el")
+        curses.setupterm(fd=fd.fileno())
+        eraser = curses.tigetstr("el")
 
     if not eraser and fd.isatty():
         # is a tty, but doesn't support the proper escape code, so let's fake it
-        from shutil import get_terminal_size
 
-        width = get_terminal_size().columns
+        width = shutil.get_terminal_size().columns
         eraser = b"\r" + (b" " * width) + b"\r"
 
     return eraser



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/d9ff65b029b301c31fe21abc42c0330a301c9894...cd9e526bcb3e566269c01833f2b0dc7eeb2dd457

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/d9ff65b029b301c31fe21abc42c0330a301c9894...cd9e526bcb3e566269c01833f2b0dc7eeb2dd457
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200715/b4fcb72d/attachment.htm>


More information about the rb-commits mailing list