use load_module_from_file rather than relative import broken in python 3.3. Closes #110213

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset9ee22d817eda
branchdefault
phasepublic
hiddenno
parent revision#07f199a99d3b redefine cmp under py3k. Closes #120635
child revision#4af14e854aeb give [deprecated-lambda] when a map/filter of a lambda could be a comprehension. Closes #120657
files modified by this revision
ChangeLog
checkers/__init__.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1361545804 -3600
# Fri Feb 22 16:10:04 2013 +0100
# Node ID 9ee22d817eda42874cbb99e995e1cf4a66a3d0d8
# Parent 07f199a99d3bb63f74cb7425e4a69a1740392cc9
use load_module_from_file rather than relative import broken in python 3.3. Closes #110213

diff --git a/ChangeLog b/ChangeLog
@@ -16,23 +16,30 @@
1 
2      * #105327: add support for --disable=all option and deprecate the
3        'disable-all' inline directive in favour of 'skip-file' (patch by
4        A.Fayolle)
5 
6 -    * #110840: Add messages I0020 and I0021 for reporting of suppressed messages
7 +    * #110840: add messages I0020 and I0021 for reporting of suppressed messages
8        and useless suppression pragmas. (patch by Torsten Marek)
9 
10 -    * #112728: Add warning E0604 for non-string objects in __all__
11 +    * #112728: add warning E0604 for non-string objects in __all__
12        (patch by Torsten Marek)
13 
14      * #113231: logging checker now looks at instances of Logger classes
15        in addition to the base logging module. (patch by Mike Bryant)
16 
17      * #111799: don't warn about octal escape sequence, warn about \o
18        which is not octal in Python (patch by Martin Pool)
19 
20  --
21 +    * Python 3 related changes:
22 +
23 +      * #110213: fix import of checkers broken with python 3.3, causing
24 +        "No such message id W0704" breakage
25 +
26 +      * #120635: redefine cmp function used in pylint.reporters
27 +
28      * #115580: fix erroneous W0212 (access to protected member) on super call
29        (patch by Martin Pool)
30 
31      * #110853: fix a crash when an __init__ method in a base class has been
32        created by assignment rather than direct function definition (patch by
diff --git a/checkers/__init__.py b/checkers/__init__.py
@@ -1,6 +1,6 @@
33 -# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
34 +# Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
35  # http://www.logilab.fr/ -- mailto:contact@logilab.fr
36  #
37  # This program is free software; you can redistribute it and/or modify it under
38  # the terms of the GNU General Public License as published by the Free Software
39  # Foundation; either version 2 of the License, or (at your option) any later
@@ -41,10 +41,11 @@
40  import tokenize
41  from os import listdir
42  from os.path import dirname, join, isdir, splitext
43 
44  from logilab.astng.utils import ASTWalker
45 +from logilab.common.modutils import load_module_from_file
46  from logilab.common.configuration import OptionsProviderMixIn
47 
48  from pylint.reporters import diff_string, EmptyReport
49 
50  def table_lines_from_stats(stats, old_stats, columns):
@@ -99,19 +100,19 @@
51 
52      def package_dir(self):
53          """return the base directory for the analysed package"""
54          return dirname(self.linter.base_file)
55 
56 -
57      # dummy methods implementing the IChecker interface
58 
59      def open(self):
60          """called before visiting project (i.e set of modules)"""
61 
62      def close(self):
63          """called after visiting project (i.e set of modules)"""
64 
65 +
66  class BaseRawChecker(BaseChecker):
67      """base class for raw checkers"""
68 
69      def process_module(self, node):
70          """process a module
@@ -137,21 +138,19 @@
71 
72  def package_load(linter, directory):
73      """load all module and package in the given directory, looking for a
74      'register' function in each one, used to register pylint checkers
75      """
76 -    globs = globals()
77      imported = {}
78      for filename in listdir(directory):
79          basename, extension = splitext(filename)
80          if basename in imported or basename == '__pycache__':
81              continue
82          if extension in PY_EXTS and basename != '__init__' or (
83 -             not extension and basename != 'CVS' and
84 -             isdir(join(directory, basename))):
85 +             not extension and isdir(join(directory, basename))):
86              try:
87 -                module = __import__(basename, globs, globs, None)
88 +                module = load_module_from_file(join(directory, filename))
89              except ValueError:
90                  # empty module name (usually emacs auto-save files)
91                  continue
92              except ImportError, exc:
93                  import sys