Hi,

I have been trying to use Pylint with some Django and Google App
Engine projects. The problem I have is that the Django and Google
modules are always in the PYTHONPATH, but are through code when run
using a manage.py or other script. I would rather not change my
enviroment to suit Pylint, so I created an option for Pylint called
ignored-modules which is a csv list of top level modules to not
attempt to import. For example, in my .pylintrc, I have the following
line:

ignored-modules=django,google

Then any "from django.core import foo" and "from google.api import
bar" will be skipped. My patch just includes the code to do this. I
don't have any tests or docs, because I am not sure how to test this
or where to put the docs for this? If this is something that looks
worthwhile to be added to Pylint, I would be happy to add tests and
docs with some guidance.

Thanks,
John


diff -r c8030f0a6bf8 checkers/imports.py
--- a/checkers/imports.py       Thu Aug 06 10:55:33 2009 +0200
+++ b/checkers/imports.py       Mon Aug 10 22:00:45 2009 -0500
@@ -192,7 +192,13 @@
                  'help' : 'Create a graph of internal dependencies in the \
 given file (report R0402 must not be disabled)'}
                 ),
-
+                ('ignored-modules', {
+                    'default' : (),
+                    'type' : 'csv',
+                    'metavar' : '<modules>',
+                    'help' : 'List of modules to skip when testing imports.'
+                    }
+                ),
                )

     def __init__(self, linter=None):
@@ -264,6 +270,11 @@

     def _module_not_exists(self, node, modname):
         """check if module exists and possibly add message"""
+
+        # check if modules is to be ignored
+        top_module = modname.split('.')[0]
+        if top_module in self.config.ignored_modules:
+            return True
         errors = expand_modules([modname], [])[1]
         if not errors or is_relative(modname, node.root().file):
             return False
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to