Permalink
Browse files

Merge branch 'master' of github.com:yumike/djangolint

  • Loading branch information...
2 parents 0f3124c + 93d700f commit b9774748914b05d601433a2f35bd5be54145f6a0 @nyumatova nyumatova committed Jul 31, 2011
@@ -1,12 +0,0 @@
-from .formtools import FormToolsAnalyzer
-from .generic_views import GenericViewsAnalyzer
-from .render_to_response import RenderToResponseAnalyzer
-from .syntax_error import SyntaxErrorAnalyzer
-
-
-registry = [
- FormToolsAnalyzer,
- GenericViewsAnalyzer,
- RenderToResponseAnalyzer,
- SyntaxErrorAnalyzer,
-]
@@ -0,0 +1,35 @@
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.utils.importlib import import_module
+from django.utils.functional import memoize
+
+
+_analyzers_cache = {}
+
+
+def clear_analyzers_cache():
+ global _analyzers_cache
+ _analyzers_cache.clear()
+
+
+def load_analyzer(analyzer_name):
+ module_name, attr = analyzer_name.rsplit('.', 1)
+ try:
+ module = import_module(module_name)
+ except ImportError, e:
+ raise ImproperlyConfigured(
+ 'Error importing analyzer %s: "%s"' % (analyzer_name, e))
+ try:
+ analyzer = getattr(module, attr)
+ except AttributeError, e:
+ raise ImproperlyConfigured(
+ 'Error importing analyzer %s: "%s"' % (analyzer_name, e))
+ return analyzer
+
+
+def get_analyzers():
+ analyzers = []
+ for analyzer_name in getattr(settings, 'LINT_ANALYZERS', ()):
+ analyzers.append(load_analyzer(analyzer_name))
+ return analyzers
+get_analyzers = memoize(get_analyzers, _analyzers_cache, 0)
View
@@ -6,7 +6,7 @@
from django.conf import settings
from django.utils import simplejson as json
-from .analyzers import registry
+from .analyzers.loader import get_analyzers
from .models import Fix
from .parsers import Parser
@@ -28,7 +28,7 @@ def parse(path):
def analyze(code, path):
results = []
- for analyzer in registry:
+ for analyzer in get_analyzers():
results.extend(analyzer(code, path).analyze())
return results
@@ -1,7 +1,7 @@
import os
from django.test import TestCase
-from ..analyzers import FormToolsAnalyzer
+from ..analyzers.formtools import FormToolsAnalyzer
from ..parsers import Parser
from .base import TESTS_ROOT
@@ -1,7 +1,7 @@
import os
from django.test import TestCase
-from ..analyzers import GenericViewsAnalyzer
+from ..analyzers.generic_views import GenericViewsAnalyzer
from ..parsers import Parser
from .base import TESTS_ROOT
@@ -1,7 +1,7 @@
import os
from django.test import TestCase
-from ..analyzers import RenderToResponseAnalyzer
+from ..analyzers.render_to_response import RenderToResponseAnalyzer
from ..parsers import Parser
from .base import TESTS_ROOT
@@ -159,6 +159,13 @@
'compressor.filters.cssmin.CSSMinFilter',
)
+LINT_ANALYZERS = (
+ 'lint.analyzers.formtools.FormToolsAnalyzer',
+ 'lint.analyzers.generic_views.GenericViewsAnalyzer',
+ 'lint.analyzers.render_to_response.RenderToResponseAnalyzer',
+ 'lint.analyzers.syntax_error.SyntaxErrorAnalyzer',
+)
+
import djcelery
djcelery.setup_loader()

0 comments on commit b977474

Please sign in to comment.