Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/pylint/pyreverse/diadefslib.py

Issue 739393004: Revert "Revert "pylint: upgrade to 1.3.1"" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/pylint/lint.py ('k') | third_party/pylint/pyreverse/diagrams.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2000-2010 LOGILAB S.A. (Paris, FRANCE). 1 # Copyright (c) 2000-2013 LOGILAB S.A. (Paris, FRANCE).
2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr 2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 # 3 #
4 # This program is free software; you can redistribute it and/or modify it under 4 # This program is free software; you can redistribute it and/or modify it under
5 # the terms of the GNU General Public License as published by the Free Software 5 # the terms of the GNU General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option) any later 6 # Foundation; either version 2 of the License, or (at your option) any later
7 # version. 7 # version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT 9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License along with 13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 14 # this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 """handle diagram generation options for class diagram or default diagrams 16 """handle diagram generation options for class diagram or default diagrams
17 """ 17 """
18 18
19 from logilab.common.compat import builtins 19 from logilab.common.compat import builtins
20 BUILTINS_NAME = builtins.__name__ 20
21 from logilab import astng 21 import astroid
22 from logilab.astng.utils import LocalsVisitor 22 from astroid.utils import LocalsVisitor
23 23
24 from pylint.pyreverse.diagrams import PackageDiagram, ClassDiagram 24 from pylint.pyreverse.diagrams import PackageDiagram, ClassDiagram
25 25
26 BUILTINS_NAME = builtins.__name__
27
26 # diagram generators ########################################################## 28 # diagram generators ##########################################################
27 29
28 class DiaDefGenerator: 30 class DiaDefGenerator(object):
29 """handle diagram generation options 31 """handle diagram generation options"""
30 """ 32
31 def __init__(self, linker, handler): 33 def __init__(self, linker, handler):
32 """common Diagram Handler initialization""" 34 """common Diagram Handler initialization"""
33 self.config = handler.config 35 self.config = handler.config
34 self._set_default_options() 36 self._set_default_options()
35 self.linker = linker 37 self.linker = linker
36 self.classdiagram = None # defined by subclasses 38 self.classdiagram = None # defined by subclasses
37 39
38 def get_title(self, node): 40 def get_title(self, node):
39 """get title for objects""" 41 """get title for objects"""
40 title = node.name 42 title = node.name
41 if self.module_names: 43 if self.module_names:
42 title = '%s.%s' % (node.root().name, title) 44 title = '%s.%s' % (node.root().name, title)
43 return title 45 return title
44 46
45 def _set_option(self, option): 47 def _set_option(self, option):
46 """activate some options if not explicitly deactivated""" 48 """activate some options if not explicitly deactivated"""
47 # if we have a class diagram, we want more information by default; 49 # if we have a class diagram, we want more information by default;
48 # so if the option is None, we return True 50 # so if the option is None, we return True
49 if option is None: 51 if option is None:
50 if self.config.classes: 52 if self.config.classes:
51 return True 53 return True
52 else: 54 else:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 continue 95 continue
94 yield ancestor 96 yield ancestor
95 97
96 def get_associated(self, klass_node, level): 98 def get_associated(self, klass_node, level):
97 """return associated nodes of a class node""" 99 """return associated nodes of a class node"""
98 if level == 0: 100 if level == 0:
99 return 101 return
100 for ass_nodes in klass_node.instance_attrs_type.values() + \ 102 for ass_nodes in klass_node.instance_attrs_type.values() + \
101 klass_node.locals_type.values(): 103 klass_node.locals_type.values():
102 for ass_node in ass_nodes: 104 for ass_node in ass_nodes:
103 if isinstance(ass_node, astng.Instance): 105 if isinstance(ass_node, astroid.Instance):
104 ass_node = ass_node._proxied 106 ass_node = ass_node._proxied
105 if not (isinstance(ass_node, astng.Class) 107 if not (isinstance(ass_node, astroid.Class)
106 and self.show_node(ass_node)): 108 and self.show_node(ass_node)):
107 continue 109 continue
108 yield ass_node 110 yield ass_node
109 111
110 def extract_classes(self, klass_node, anc_level, ass_level): 112 def extract_classes(self, klass_node, anc_level, ass_level):
111 """extract recursively classes related to klass_node""" 113 """extract recursively classes related to klass_node"""
112 if self.classdiagram.has_node(klass_node) or not self.show_node(klass_no de): 114 if self.classdiagram.has_node(klass_node) or not self.show_node(klass_no de):
113 return 115 return
114 self.add_class(klass_node) 116 self.add_class(klass_node)
115 117
116 for ancestor in self.get_ancestors(klass_node, anc_level): 118 for ancestor in self.get_ancestors(klass_node, anc_level):
117 self.extract_classes(ancestor, anc_level-1, ass_level) 119 self.extract_classes(ancestor, anc_level-1, ass_level)
118 120
119 for ass_node in self.get_associated(klass_node, ass_level): 121 for ass_node in self.get_associated(klass_node, ass_level):
120 self.extract_classes(ass_node, anc_level, ass_level-1) 122 self.extract_classes(ass_node, anc_level, ass_level-1)
121 123
122 124
123 class DefaultDiadefGenerator(LocalsVisitor, DiaDefGenerator): 125 class DefaultDiadefGenerator(LocalsVisitor, DiaDefGenerator):
124 """generate minimum diagram definition for the project : 126 """generate minimum diagram definition for the project :
125 127
126 * a package diagram including project's modules 128 * a package diagram including project's modules
127 * a class diagram including project's classes 129 * a class diagram including project's classes
128 """ 130 """
129 131
130 def __init__(self, linker, handler): 132 def __init__(self, linker, handler):
131 DiaDefGenerator.__init__(self, linker, handler) 133 DiaDefGenerator.__init__(self, linker, handler)
132 LocalsVisitor.__init__(self) 134 LocalsVisitor.__init__(self)
133 135
134 def visit_project(self, node): 136 def visit_project(self, node):
135 """visit an astng.Project node 137 """visit an astroid.Project node
136 138
137 create a diagram definition for packages 139 create a diagram definition for packages
138 """ 140 """
139 mode = self.config.mode 141 mode = self.config.mode
140 if len(node.modules) > 1: 142 if len(node.modules) > 1:
141 self.pkgdiagram = PackageDiagram('packages %s' % node.name, mode) 143 self.pkgdiagram = PackageDiagram('packages %s' % node.name, mode)
142 else: 144 else:
143 self.pkgdiagram = None 145 self.pkgdiagram = None
144 self.classdiagram = ClassDiagram('classes %s' % node.name, mode) 146 self.classdiagram = ClassDiagram('classes %s' % node.name, mode)
145 147
146 def leave_project(self, node): 148 def leave_project(self, node):
147 """leave the astng.Project node 149 """leave the astroid.Project node
148 150
149 return the generated diagram definition 151 return the generated diagram definition
150 """ 152 """
151 if self.pkgdiagram: 153 if self.pkgdiagram:
152 return self.pkgdiagram, self.classdiagram 154 return self.pkgdiagram, self.classdiagram
153 return self.classdiagram, 155 return self.classdiagram,
154 156
155 def visit_module(self, node): 157 def visit_module(self, node):
156 """visit an astng.Module node 158 """visit an astroid.Module node
157 159
158 add this class to the package diagram definition 160 add this class to the package diagram definition
159 """ 161 """
160 if self.pkgdiagram: 162 if self.pkgdiagram:
161 self.linker.visit(node) 163 self.linker.visit(node)
162 self.pkgdiagram.add_object(node.name, node) 164 self.pkgdiagram.add_object(node.name, node)
163 165
164 def visit_class(self, node): 166 def visit_class(self, node):
165 """visit an astng.Class node 167 """visit an astroid.Class node
166 168
167 add this class to the class diagram definition 169 add this class to the class diagram definition
168 """ 170 """
169 anc_level, ass_level = self._get_levels() 171 anc_level, ass_level = self._get_levels()
170 self.extract_classes(node, anc_level, ass_level) 172 self.extract_classes(node, anc_level, ass_level)
171 173
172 def visit_from(self, node): 174 def visit_from(self, node):
173 """visit astng.From and catch modules for package diagram 175 """visit astroid.From and catch modules for package diagram
174 """ 176 """
175 if self.pkgdiagram: 177 if self.pkgdiagram:
176 self.pkgdiagram.add_from_depend(node, node.modname) 178 self.pkgdiagram.add_from_depend(node, node.modname)
177 179
178 180
179 class ClassDiadefGenerator(DiaDefGenerator): 181 class ClassDiadefGenerator(DiaDefGenerator):
180 """generate a class diagram definition including all classes related to a 182 """generate a class diagram definition including all classes related to a
181 given class 183 given class
182 """ 184 """
183 185
(...skipping 13 matching lines...) Expand all
197 module = project.modules[0] 199 module = project.modules[0]
198 klass = klass.split('.')[-1] 200 klass = klass.split('.')[-1]
199 klass = module.ilookup(klass).next() 201 klass = module.ilookup(klass).next()
200 202
201 anc_level, ass_level = self._get_levels() 203 anc_level, ass_level = self._get_levels()
202 self.extract_classes(klass, anc_level, ass_level) 204 self.extract_classes(klass, anc_level, ass_level)
203 return self.classdiagram 205 return self.classdiagram
204 206
205 # diagram handler ############################################################# 207 # diagram handler #############################################################
206 208
207 class DiadefsHandler: 209 class DiadefsHandler(object):
208 """handle diagram definitions : 210 """handle diagram definitions :
209 211
210 get it from user (i.e. xml files) or generate them 212 get it from user (i.e. xml files) or generate them
211 """ 213 """
212 214
213 def __init__(self, config): 215 def __init__(self, config):
214 self.config = config 216 self.config = config
215 217
216 def get_diadefs(self, project, linker): 218 def get_diadefs(self, project, linker):
217 """get the diagrams configuration data 219 """get the diagrams configuration data
218 :param linker: astng.inspector.Linker(IdGeneratorMixIn, LocalsVisitor) 220 :param linker: astroid.inspector.Linker(IdGeneratorMixIn, LocalsVisitor)
219 :param project: astng.manager.Project 221 :param project: astroid.manager.Project
220 """ 222 """
221 223
222 # read and interpret diagram definitions (Diadefs) 224 # read and interpret diagram definitions (Diadefs)
223 diagrams = [] 225 diagrams = []
224 generator = ClassDiadefGenerator(linker, self) 226 generator = ClassDiadefGenerator(linker, self)
225 for klass in self.config.classes: 227 for klass in self.config.classes:
226 diagrams.append(generator.class_diagram(project, klass)) 228 diagrams.append(generator.class_diagram(project, klass))
227 if not diagrams: 229 if not diagrams:
228 diagrams = DefaultDiadefGenerator(linker, self).visit(project) 230 diagrams = DefaultDiadefGenerator(linker, self).visit(project)
229 for diagram in diagrams: 231 for diagram in diagrams:
230 diagram.extract_relationships() 232 diagram.extract_relationships()
231 return diagrams 233 return diagrams
OLDNEW
« no previous file with comments | « third_party/pylint/lint.py ('k') | third_party/pylint/pyreverse/diagrams.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698