On 06 octobre 16:09, Marc-Antoine Ruel wrote:
> This patch has a bad side effect since it registers the module in
> sys.modules which I don't want, e.g.
> 
> /..
> config/master.cfg
> scripts/master/utils.py
> 
> PYTHONPATH=scripts pylint config/master.cfg
> 
> will register master.cfg as sys.modules['master'] so scripts/master will be
> aliased. I'm not sure what is the right fix for that beside renaming the
> directory or the file.

Following patches on astng / pylint seems to do the trick nicely. Tell me if it
works for you:

[...@scorpius astng]$ hg diff
diff --git a/manager.py b/manager.py
--- a/manager.py
+++ b/manager.py
@@ -123,15 +123,18 @@
         directory = abspath(directory)
         return Package(directory, modname, self)
 
-    def astng_from_file(self, filepath, modname=None, fallback=True):
+    def astng_from_file(self, filepath, modname=None, fallback=True, 
source=False):
         """given a module name, return the astng object"""
         try:
             filepath = get_source_file(filepath, include_no_ext=True)
             source = True
         except NoSourceFile:
-            source = False
+            pass
         if modname is None:
-            modname = '.'.join(modpath_from_file(filepath))
+            try:
+                modname = '.'.join(modpath_from_file(filepath))
+            except ImportError:
+                modname = filepath


[...@scorpius pylint]$ hg dif
diff --git a/lint.py b/lint.py
--- a/lint.py
+++ b/lint.py
@@ -531,16 +531,17 @@
     def get_astng(self, filepath, modname):
         """return a astng representation for a module"""
         try:
-            return MANAGER.astng_from_file(filepath, modname)
+            return MANAGER.astng_from_file(filepath, modname, source=True)
         except SyntaxError, ex:
             self.add_message('E0001', line=ex.lineno, args=ex.msg)
         except KeyboardInterrupt:

-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org

_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to