[Git][reproducible-builds/diffoscope][master] 2 commits: Clarify that we are generating presenter formats in a debug message.

Chris Lamb gitlab at salsa.debian.org
Sat Jun 27 15:44:05 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
7b814f8c by Chris Lamb at 2020-06-27T16:27:38+01:00
Clarify that we are generating presenter formats in a debug message.

- - - - -
14dd8d1c by Chris Lamb at 2020-06-27T16:40:28+01:00
Split out formatting of class names into a common method that supports stripping.

- - - - -


5 changed files:

- diffoscope/comparators/utils/file.py
- diffoscope/comparators/utils/specialize.py
- diffoscope/presenters/formats.py
- diffoscope/profiling.py
- diffoscope/utils.py


Changes:

=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -30,7 +30,7 @@ from diffoscope.exc import (
     ContainerExtractionError,
 )
 from diffoscope.tools import tool_required
-from diffoscope.utils import format_cmdline
+from diffoscope.utils import format_cmdline, format_class
 from diffoscope.config import Config
 from diffoscope.profiling import profile
 from diffoscope.difference import Difference
@@ -237,9 +237,6 @@ class File(metaclass=abc.ABCMeta):
                 return self._other_file.__class__.CONTAINER_CLASSES[0](self)
             return None
 
-        def type_name(klass):
-            return "{}.{}".format(klass.__module__, klass.__name__)
-
         if hasattr(self, "_as_container"):
             return self._as_container
 
@@ -248,20 +245,24 @@ class File(metaclass=abc.ABCMeta):
         # Try each container class in turn, returning the first one that
         # instantiates without error.
         for klass in klasses:
+            formatted_class = format_class(
+                klass, strip="diffoscope.comparators."
+            )
+
             logger.debug(
-                "Instantiating a %s for %s", type_name(klass), self.name,
+                "Instantiating a %s for %s", formatted_class, self.name,
             )
             try:
                 self._as_container = klass(self)
 
                 logger.debug(
-                    "Returning a %s for %s", type_name(klass), self.name,
+                    "Returning a %s for %s", formatted_class, self.name,
                 )
                 return self._as_container
             except RequiredToolNotFound as exc:
                 logger.debug(
                     "Cannot instantiate a %s; missing tool %s",
-                    type_name(klass),
+                    formatted_class,
                     exc.command,
                 )
                 try:


=====================================
diffoscope/comparators/utils/specialize.py
=====================================
@@ -21,6 +21,8 @@ import logging
 
 from diffoscope.profiling import profile
 
+from ...utils import format_class
+
 from .. import ComparatorManager
 
 logger = logging.getLogger(__name__)
@@ -37,7 +39,11 @@ def try_recognize(file, cls, recognizes):
             return False
 
     # Found a match; perform type magic
-    logger.debug("Using %s.%s for %s", cls.__module__, cls.__name__, file.name)
+    logger.debug(
+        "Using %s for %s",
+        format_class(cls, strip="diffoscope.comparators."),
+        file.name,
+    )
     new_cls = type(cls.__name__, (cls, type(file)), {})
     file.__class__ = new_cls
 


=====================================
diffoscope/presenters/formats.py
=====================================
@@ -80,7 +80,7 @@ class PresenterManager:
             self.config["text"] = FORMATS["text"]
 
         logger.debug(
-            "Will generate the following formats: %s",
+            "Will generate the following presenter formats: %s",
             ", ".join(self.config.keys()),
         )
 


=====================================
diffoscope/profiling.py
=====================================
@@ -22,6 +22,8 @@ import time
 import contextlib
 import collections
 
+from .utils import format_class
+
 _ENABLED = False
 
 
@@ -53,9 +55,7 @@ class ProfileManager:
 
     def increment(self, start, namespace, key):
         if not isinstance(key, str):
-            key = "{}.{}".format(
-                key.__class__.__module__, key.__class__.__name__
-            )
+            key = format_class(key.__class__)
 
         self.data[namespace][key]["time"] += time.time() - start
         self.data[namespace][key]["count"] += 1


=====================================
diffoscope/utils.py
=====================================
@@ -63,3 +63,12 @@ def bail_if_non_existing(*paths):
                     "%s: %s: No such file or directory\n" % (sys.argv[0], path)
                 )
         sys.exit(2)
+
+
+def format_class(klass, strip=""):
+    val = "{}.{}".format(klass.__module__, klass.__name__)
+
+    if val.startswith(strip):
+        val = val[len(strip) :]
+
+    return val



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/d284b58a7bbab7c126ed631e3d4fc805af4a2217...14dd8d1c1f8a8bf35e2972234f2d0dadd2fc4f34

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/d284b58a7bbab7c126ed631e3d4fc805af4a2217...14dd8d1c1f8a8bf35e2972234f2d0dadd2fc4f34
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/20200627/f10d25c6/attachment.htm>


More information about the rb-commits mailing list