Don't squelch error reporting when comparators fail to load.

Explicitly check whether there is a fallback left to try, before raising
an exception in the main loop. This ensures the original traceback is
also shown.

Without this, the original cause is quite mysterious, and users need to
scrutinize the code in order to figure out how to figure out what was
actually failing to be imported.
parent 6eac9f69
......@@ -107,7 +107,7 @@ class ComparatorManager(object):
self.classes = []
for xs in self.COMPARATORS:
for x in xs:
for idx, x in enumerate(xs):
package, klass_name = x.rsplit('.', 1)
try:
......@@ -115,15 +115,16 @@ class ComparatorManager(object):
'diffoscope.comparators.{}'.format(package)
)
except ImportError:
continue
if idx < len(xs) - 1:
continue
raise ImportError("Could not import {}{}".format(
"any of" if len(xs) > 1 else '',
', '.join(xs)
))
self.classes.append(getattr(mod, klass_name))
break
else: # noqa
raise ImportError("Could not import {}{}".format(
"any of" if len(xs) > 1 else '',
', '.join(xs)
))
logger.debug("Loaded %d comparator classes", len(self.classes))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment