[Git][reproducible-builds/diffoscope][master] Track and report on missing Python modules. (Closes: reproducible-builds/diffoscope#72)

Chris Lamb gitlab at salsa.debian.org
Fri Oct 11 18:42:46 UTC 2019



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
c54dd710 by Chris Lamb at 2019-10-11T18:34:48Z
Track and report on missing Python modules. (Closes: reproducible-builds/diffoscope#72)

This adds a "Missing-Python-Modules" entry to the output of
--list-missing-tools, for example:

```
  Missing-Python-Modules: PyPDF2, argcomplete, defusedxml, guestfs, jsondiff, progressbar, rpm
```

Signed-off-by: Chris Lamb <lamby at debian.org>

- - - - -


11 changed files:

- diffoscope/comparators/__init__.py
- diffoscope/comparators/binwalk.py
- diffoscope/comparators/deb.py
- diffoscope/comparators/directory.py
- diffoscope/comparators/fsimage.py
- diffoscope/comparators/json.py
- diffoscope/comparators/pdf.py
- diffoscope/comparators/xml.py
- diffoscope/main.py
- diffoscope/progress.py
- diffoscope/tools.py


Changes:

=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -24,6 +24,7 @@ import logging
 import importlib
 import traceback
 
+from ..tools import python_module_missing
 from ..logging import line_eraser
 
 
@@ -126,6 +127,10 @@ class ComparatorManager:
                     mod = importlib.import_module(
                         'diffoscope.comparators.{}'.format(package)
                     )
+                except ModuleNotFoundError as e:
+                    python_module_missing(e.name)
+                    errors.append((x, e))
+                    continue
                 except ImportError as e:
                     errors.append((x, e))
                     continue


=====================================
diffoscope/comparators/binwalk.py
=====================================
@@ -22,6 +22,7 @@ import re
 import glob
 import logging
 
+from diffoscope.tools import python_module_missing
 from diffoscope.tempfiles import get_temporary_directory
 
 from .utils.file import File
@@ -35,6 +36,7 @@ except ImportError:
 try:
     import binwalk
 except ImportError:
+    python_module_missing('rpm')
     binwalk = None
 else:
     # Disable binwalk's own user configuration for predictable results and to


=====================================
diffoscope/comparators/deb.py
=====================================
@@ -23,6 +23,7 @@ import logging
 
 from diffoscope.config import Config
 from diffoscope.difference import Difference
+from diffoscope.tools import python_module_missing
 
 from .tar import TarContainer
 from .utils.compare import compare_files
@@ -34,6 +35,7 @@ from .utils.specialize import specialize
 try:
     from debian import deb822
 except ImportError:
+    python_module_missing('debian')
     deb822 = None
 
 logger = logging.getLogger(__name__)


=====================================
diffoscope/comparators/directory.py
=====================================
@@ -25,7 +25,7 @@ import collections
 import itertools
 
 from diffoscope.exc import RequiredToolNotFound
-from diffoscope.tools import tool_required
+from diffoscope.tools import python_module_missing, tool_required
 from diffoscope.config import Config
 from diffoscope.progress import Progress
 from diffoscope.difference import Difference
@@ -120,6 +120,7 @@ def xattr(path1, path2):
     try:
         import xattr as xattr_
     except ImportError:
+        python_module_required('xattr')
         return None
 
     # Support the case where the python3-xattr package is installed but


=====================================
diffoscope/comparators/fsimage.py
=====================================
@@ -23,6 +23,7 @@ import os.path
 
 from diffoscope.difference import Difference
 from diffoscope.exc import ContainerExtractionError
+from diffoscope.tools import python_module_missing
 
 from .utils.file import File
 from .utils.archive import Archive
@@ -30,6 +31,7 @@ from .utils.archive import Archive
 try:
     import guestfs
 except ImportError:
+    python_module_missing('guestfs')
     guestfs = None
 
 logger = logging.getLogger(__name__)


=====================================
diffoscope/comparators/json.py
=====================================
@@ -21,12 +21,14 @@ import json
 import collections
 
 from diffoscope.difference import Difference
+from diffoscope.tools import python_module_missing
 
 from .utils.file import File
 
 try:
     import jsondiff
 except ImportError:  # noqa
+    python_module_missing('jsondiff')
     jsondiff = None
 
 


=====================================
diffoscope/comparators/pdf.py
=====================================
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope.tools import tool_required
+from diffoscope.tools import python_module_missing, tool_required
 from diffoscope.difference import Difference
 
 from .utils.file import File
@@ -28,6 +28,7 @@ from .utils.command import Command
 try:
     import PyPDF2
 except ImportError:  # noqa
+    python_module_missing('PyPDF2')
     PyPDF2 = None
 
 


=====================================
diffoscope/comparators/xml.py
=====================================
@@ -17,15 +17,18 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-
 from xml.parsers.expat import ExpatError
-from diffoscope.difference import Difference
+
 from diffoscope.comparators.utils.file import File
+from diffoscope.difference import Difference
+from diffoscope.tools import python_module_missing
+
 from .missing_file import MissingFile
 
 try:
     from defusedxml import minidom
 except ImportError:
+    python_module_missing('defusedxml')
     from xml.dom import minidom
 
 


=====================================
diffoscope/main.py
=====================================
@@ -35,6 +35,7 @@ from .path import set_path
 from .tools import (
     tool_check_installed,
     tool_prepend_prefix,
+    python_module_missing,
     tool_required,
     OS_NAMES,
     get_current_os,
@@ -59,11 +60,13 @@ logger = logging.getLogger(__name__)
 try:
     import tlsh
 except ImportError:
+    python_module_missing('tlsh')
     tlsh = None
 
 try:
     import argcomplete
 except ImportError:
+    python_module_missing('argcomplete')
     argcomplete = None
 
 
@@ -549,6 +552,9 @@ class ListToolsAction(argparse.Action):
                     pass
             print(', '.join(sorted(tools)))
 
+        print("Missing-Python-Modules: ", end='')
+        print(', '.join(sorted(python_module_missing.modules)))
+
         sys.exit(0)
 
 
@@ -707,6 +713,7 @@ def main(args=None):
         import libarchive
     except (ImportError, AttributeError):
         traceback.print_exc()
+        python_module_missing('libarchive')
         print(
             "\nMissing or incomplete libarchive module. Try installing your "
             "system's 'libarchive' package.",


=====================================
diffoscope/progress.py
=====================================
@@ -25,10 +25,17 @@ import signal
 import logging
 
 from .logging import line_eraser
+from .tools import python_module_missing
 
 
 logger = logging.getLogger(__name__)
 
+try:
+    import progressbar
+except ImportError:
+    python_module_missing('progressbar')
+    progressbar = None
+
 
 class ProgressLoggingHandler(logging.StreamHandler):
     def __init__(self, progressbar):
@@ -73,12 +80,13 @@ class ProgressManager:
 
         log_handler = None
         if show_progressbar():
-            try:
+            if progressbar is not None:
                 bar = ProgressBar()
                 self.register(bar)
                 log_handler = ProgressLoggingHandler(bar)
-            except ImportError:
+            else:
                 # User asked for bar, so show them an error
+
                 if parsed_args.progress:
                     logging.warning(
                         'Progress bar was requested but the "progressbar" module is unavailable.'
@@ -198,8 +206,6 @@ class Progress:
 
 class ProgressBar:
     def __init__(self):
-        import progressbar
-
         try:
             from progressbar.widgets import WidgetBase
         except ImportError:


=====================================
diffoscope/tools.py
=====================================
@@ -144,3 +144,10 @@ def get_package_provider(tool, os=None):
                 pass
 
     return None
+
+
+def python_module_missing(name):
+    python_module_missing.modules.add(name)
+
+
+python_module_missing.modules = set()



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/c54dd7105521f5b327337aaaf1df75ca092674d3

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/c54dd7105521f5b327337aaaf1df75ca092674d3
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/20191011/d974e8ca/attachment.html>


More information about the rb-commits mailing list