[Git][reproducible-builds/diffoscope][master] 2 commits: Factor out generating a human-readable comment when missing a Python module.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Mon May 1 20:04:27 UTC 2023



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
55742394 by Chris Lamb at 2023-05-01T13:03:25-07:00
Factor out generating a human-readable comment when missing a Python module.

- - - - -
45ac81ba by Chris Lamb at 2023-05-01T13:04:17-07:00
If binwalk is not available, ensure the user knows they may be missing more info.

- - - - -


3 changed files:

- diffoscope/comparators/binwalk.py
- diffoscope/comparators/fsimage.py
- diffoscope/tools.py


Changes:

=====================================
diffoscope/comparators/binwalk.py
=====================================
@@ -21,7 +21,10 @@ import re
 import glob
 import logging
 
-from diffoscope.tools import python_module_missing
+from diffoscope.tools import (
+    python_module_missing,
+    get_comment_for_missing_python_module,
+)
 from diffoscope.tempfiles import get_temporary_directory
 
 from .utils.file import File
@@ -70,10 +73,11 @@ class BinwalkFile(File):
 
     @classmethod
     def recognizes(cls, file):
-        if binwalk is None:
+        if not super().recognizes(file):
             return False
 
-        if not super().recognizes(file):
+        if binwalk is None:
+            file.add_comment(get_comment_for_missing_python_module("binwalk"))
             return False
 
         # RPM files are .cpio, but let's always leave it to the RPM comparator.


=====================================
diffoscope/comparators/fsimage.py
=====================================
@@ -24,7 +24,7 @@ import os.path
 from diffoscope.difference import Difference
 from diffoscope.tools import python_module_missing
 from diffoscope.profiling import profile
-from diffoscope.tools import get_package_provider
+from diffoscope.tools import get_comment_for_missing_python_module
 
 from .utils.file import File
 from .utils.archive import Archive
@@ -129,9 +129,5 @@ class FsImageFile(File):
                 )
             )
         if not guestfs:
-            pkg = get_package_provider("guestfs")
-            infix = f" from the '{pkg}' package " if pkg else " "
-            self.add_comment(
-                f"Installing the 'guestfs' Python module{infix}may produce a better output."
-            )
+            self.add_comment(get_comment_for_missing_python_module("guestfs"))
         return differences


=====================================
diffoscope/tools.py
=====================================
@@ -191,4 +191,11 @@ def python_module_missing(name):
     python_module_missing.modules.add(name)
 
 
+def get_comment_for_missing_python_module(name):
+    pkg = get_package_provider(name)
+    infix = f" from the '{pkg}' package " if pkg else " "
+
+    return f"Installing the '{name}' Python module{infix}may produce a better output."
+
+
 python_module_missing.modules = set()



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/7998aa035ddd6a989358e52f5c022cacf3b06c0b...45ac81bad59fc1b651e405339fa588026bbeffc2

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/7998aa035ddd6a989358e52f5c022cacf3b06c0b...45ac81bad59fc1b651e405339fa588026bbeffc2
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/20230501/491fe860/attachment.htm>


More information about the rb-commits mailing list