diff babel/messages/catalog.py @ 252:2398fc97675b

Soften dependency on setuptools. Extraction methods can now be referenced using a special section in the mapping configuration, mapping short names to fully-qualified function references.
author cmlenz
date Mon, 13 Aug 2007 22:29:03 +0000
parents 194f927d8c5a
children 3308e9971fab
line wrap: on
line diff
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -539,22 +539,28 @@
         ``(message, errors)`` tuple, where ``message`` is the `Message` object
         and ``errors`` is a sequence of `TranslationError` objects.
 
+        :note: this feature requires ``setuptools``/``pkg_resources`` to be
+               installed; if it is not, this method will simply return an empty
+               iterator
         :rtype: ``iterator``
         """
         checkers = []
-        from pkg_resources import working_set
-        for entry_point in working_set.iter_entry_points('babel.checkers'):
-            checkers.append(entry_point.load())
-
-        for message in self._messages.values():
-            errors = []
-            for checker in checkers:
-                try:
-                    checker(self, message)
-                except TranslationError, e:
-                    errors.append(e)
-            if errors:
-                yield message, errors
+        try:
+            from pkg_resources import working_set
+        except ImportError:
+            return
+        else:
+            for entry_point in working_set.iter_entry_points('babel.checkers'):
+                checkers.append(entry_point.load())
+            for message in self._messages.values():
+                errors = []
+                for checker in checkers:
+                    try:
+                        checker(self, message)
+                    except TranslationError, e:
+                        errors.append(e)
+                if errors:
+                    yield message, errors
 
     def update(self, template, no_fuzzy_matching=False):
         """Update the catalog based on the given template catalog.
Copyright (C) 2012-2017 Edgewall Software