~ubuntu-branches/ubuntu/trusty/pylint/trusty

« back to all changes in this revision

Viewing changes to checkers/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Thénault
  • Date: 2006-09-25 16:46:40 UTC
  • mfrom: (1.2.1 upstream) (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20060925164640-obkb6g34gqtyk20n
new uptream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2002-2004 LOGILAB S.A. (Paris, FRANCE).
 
1
# Copyright (c) 2003-2006 LOGILAB S.A. (Paris, FRANCE).
2
2
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify it under
14
14
# this program; if not, write to the Free Software Foundation, Inc.,
15
15
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
16
"""utilities methods and classes for checkers
 
17
 
 
18
Base id of standard checkers (used in msg and report ids):
 
19
01: base
 
20
02: classes
 
21
03: format
 
22
04: import
 
23
05: misc
 
24
06: variables
 
25
07: exceptions
 
26
08: similar
 
27
09: design_analysis
 
28
10: newstyle
 
29
11: typecheck
17
30
"""
18
31
 
19
 
__revision__ = "$Id: __init__.py,v 1.18 2005/01/04 15:28:19 syt Exp $"
 
32
__revision__ = "$Id: __init__.py,v 1.21 2005-11-21 23:08:11 syt Exp $"
20
33
 
21
34
import tokenize
22
35
from os import listdir
23
36
from os.path import dirname, join, isdir, splitext
24
37
 
25
 
from logilab.common.astng import ASTWalker
 
38
from logilab.astng.utils import ASTWalker
26
39
from logilab.common.configuration import OptionsProviderMixIn
27
40
 
28
 
from logilab.pylint.reporters import diff_string, EmptyReport
 
41
from pylint.reporters import diff_string, EmptyReport
29
42
 
30
43
def table_lines_from_stats(stats, old_stats, columns):
31
44
    """get values listed in <columns> from <stats> and <old_stats>,
63
76
        """
64
77
        ASTWalker.__init__(self, self)
65
78
        self.name = self.name.lower()
66
 
        if self.may_be_disabled:
67
 
            opt_name = 'enable-' + self.name
68
 
            self.options = (
69
 
                (opt_name,
70
 
                 {'type' : 'yn', 'default' : 1, 'metavar': '<y_or_n>',
71
 
                  'help' : "Enable / disable this checker"})
72
 
                ,) + self.options            
73
79
        OptionsProviderMixIn.__init__(self)
74
80
        self.linter = linter
75
81
        
80
86
    def is_enabled(self):
81
87
        """return true if the checker is enabled"""
82
88
        opt = 'enable_' + self.name
83
 
        return getattr(self.config, opt, 1)
 
89
        return getattr(self.config, opt, True)
84
90
 
85
91
    def enable(self, enable):
86
92
        """enable / disable this checker if true / false is given
87
93
 
88
94
        it false values has no effect if the checker can't be disabled
89
95
        """
90
 
        if self.may_be_disabled:
 
96
        if enable or self.may_be_disabled:
91
97
            setattr(self.config, 'enable_' + self.name, enable)
92
98
        
93
99
    def package_dir(self):
99
105
    
100
106
    def open(self):
101
107
        """called before visiting project (i.e set of modules)"""
102
 
        
 
108
    
103
109
    def close(self):
104
110
        """called after visiting project (i.e set of modules)"""
105
111
 
106
 
 
107
112
class BaseRawChecker(BaseChecker):
108
113
    """base class for raw checkers"""
109
114
    
117
122
        self.process_tokens(tokenize.generate_tokens(stream.readline))
118
123
    
119
124
    def process_tokens(self, tokens):
120
 
        """should be overiden by syb classes"""
 
125
        """should be overiden by subclasses"""
121
126
        raise NotImplementedError()
122
127
 
123
 
PYTHON_EXTENSIONS = ('.py', '.pyc', '.pyo', '.so')
 
128
 
 
129
PY_EXTS = ('.py', '.pyc', '.pyo', '.pyw', '.so', '.dll')
124
130
 
125
131
def initialize(linter):
126
132
    """initialize linter with checkers in this package """
134
140
    imported = {}
135
141
    for filename in listdir(directory):
136
142
        basename, extension = splitext(filename)
137
 
        if not imported.has_key(basename) and ((
138
 
            extension in PYTHON_EXTENSIONS and basename != '__init__') or (
139
 
            not extension and not basename == 'CVS' and
140
 
            isdir(join(directory, basename)))):
 
143
        if not imported.has_key(basename) and (
 
144
            (extension in PY_EXTS and basename != '__init__') or (
 
145
             not extension and not basename == 'CVS' and
 
146
             isdir(join(directory, basename)))):
141
147
            try:
142
148
                module = __import__(basename, globs, globs, None)
143
149
            except ValueError: