[diffoscope] 02/03: diffoscope/comparators: Move import_comparators into a "loading" module.

Chris Lamb chris at chris-lamb.co.uk
Wed Dec 28 12:55:48 CET 2016


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 114df3d6f1b7d88c923e97b2a3fe7a4da7c584d6
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Dec 27 19:22:53 2016 +0000

    diffoscope/comparators: Move import_comparators into a "loading" module.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/comparators/__init__.py      | 26 +-------------------
 diffoscope/comparators/utils/loading.py | 43 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index b850b0b..851adc6 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -23,7 +23,6 @@ import sys
 import magic
 import os.path
 import operator
-import importlib
 
 from diffoscope import logger, tool_required
 from diffoscope.config import Config
@@ -84,30 +83,6 @@ COMPARATORS = (
 )
 
 
-def import_comparators(comparators):
-    result = []
-
-    for xs in comparators:
-        for x in xs:
-            package, klass_name = x.rsplit('.', 1)
-
-            try:
-                mod = importlib.import_module(
-                    'diffoscope.comparators.{}'.format(package)
-                )
-            except ImportError:
-                continue
-
-            result.append(getattr(mod, klass_name))
-            break
-        else:
-            raise ImportError(
-                "Could not import any of {}".format(', '.join(xs))
-            )
-
-    return result
-
-
 def specialize(file):
     for cls in FILE_CLASSES:
         if isinstance(file, cls):
@@ -121,4 +96,5 @@ def specialize(file):
     logger.debug('Unidentified file. Magic says: %s', file.magic_file_type)
     return file
 
+from .utils.loading import import_comparators
 FILE_CLASSES = import_comparators(COMPARATORS)
diff --git a/diffoscope/comparators/utils/loading.py b/diffoscope/comparators/utils/loading.py
new file mode 100644
index 0000000..4c06222
--- /dev/null
+++ b/diffoscope/comparators/utils/loading.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import importlib
+
+def import_comparators(comparators):
+    result = []
+
+    for xs in comparators:
+        for x in xs:
+            package, klass_name = x.rsplit('.', 1)
+
+            try:
+                mod = importlib.import_module(
+                    'diffoscope.comparators.{}'.format(package)
+                )
+            except ImportError:
+                continue
+
+            result.append(getattr(mod, klass_name))
+            break
+        else:
+            raise ImportError(
+                "Could not import any of {}".format(', '.join(xs))
+            )
+
+    return result

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list