Documentation/Source/eric6.DataViews.CodeMetrics.html

changeset 3673
e26d7d0c1088
child 4569
8ff785ae7ae6
equal deleted inserted replaced
3670:f0cb7579c0b4 3673:e26d7d0c1088
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.DataViews.CodeMetrics</title>
4 <meta charset="UTF-8">
5 <style>
6 body {
7 background: #EDECE6;
8 margin: 0em 1em 10em 1em;
9 color: black;
10 }
11
12 h1 { color: white; background: #85774A; }
13 h2 { color: white; background: #85774A; }
14 h3 { color: white; background: #9D936E; }
15 h4 { color: white; background: #9D936E; }
16
17 a { color: #BA6D36; }
18
19 </style>
20 </head>
21 <body><a NAME="top" ID="top"></a>
22 <h1>eric6.DataViews.CodeMetrics</h1>
23 <p>
24 Module implementing a simple Python code metrics analyzer.
25 </p><dl>
26 <dt>Raises <b>ValueError</b>:</dt>
27 <dd>
28 the tokenize module is too old
29 </dd>
30 </dl>
31 <h3>Global Attributes</h3>
32 <table>
33 <tr><td>COMMENT</td></tr><tr><td>DEDENT</td></tr><tr><td>EMPTY</td></tr><tr><td>INDENT</td></tr><tr><td>KEYWORD</td></tr><tr><td>NEWLINE</td></tr><tr><td>spacer</td></tr>
34 </table>
35 <h3>Classes</h3>
36 <table>
37 <tr>
38 <td><a href="#Parser">Parser</a></td>
39 <td>Class used to parse the source code of a Python file.</td>
40 </tr><tr>
41 <td><a href="#SourceStat">SourceStat</a></td>
42 <td>Class used to calculate and store the source code statistics.</td>
43 </tr><tr>
44 <td><a href="#Token">Token</a></td>
45 <td>Class to store the token related infos.</td>
46 </tr>
47 </table>
48 <h3>Functions</h3>
49 <table>
50 <tr>
51 <td><a href="#analyze">analyze</a></td>
52 <td>Module function used analyze the source of a Python file.</td>
53 </tr><tr>
54 <td><a href="#main">main</a></td>
55 <td>Module main function used when called as a script.</td>
56 </tr><tr>
57 <td><a href="#summarize">summarize</a></td>
58 <td>Module function used to collect overall statistics.</td>
59 </tr>
60 </table>
61 <hr /><hr />
62 <a NAME="Parser" ID="Parser"></a>
63 <h2>Parser</h2>
64 <p>
65 Class used to parse the source code of a Python file.
66 </p>
67 <h3>Derived from</h3>
68 object
69 <h3>Class Attributes</h3>
70 <table>
71 <tr><td>None</td></tr>
72 </table>
73 <h3>Class Methods</h3>
74 <table>
75 <tr><td>None</td></tr>
76 </table>
77 <h3>Methods</h3>
78 <table>
79 <tr>
80 <td><a href="#Parser.__addToken">__addToken</a></td>
81 <td>Private method used to add a token to our list of tokens.</td>
82 </tr><tr>
83 <td><a href="#Parser.parse">parse</a></td>
84 <td>Public method used to parse the source code.</td>
85 </tr>
86 </table>
87 <h3>Static Methods</h3>
88 <table>
89 <tr><td>None</td></tr>
90 </table>
91 <a NAME="Parser.__addToken" ID="Parser.__addToken"></a>
92 <h4>Parser.__addToken</h4>
93 <b>__addToken</b>(<i>toktype, toktext, srow, scol, line</i>)
94 <p>
95 Private method used to add a token to our list of tokens.
96 </p><dl>
97 <dt><i>toktype</i></dt>
98 <dd>
99 the type of the token (int)
100 </dd><dt><i>toktext</i></dt>
101 <dd>
102 the text of the token (string)
103 </dd><dt><i>srow</i></dt>
104 <dd>
105 starting row of the token (int)
106 </dd><dt><i>scol</i></dt>
107 <dd>
108 starting column of the token (int)
109 </dd><dt><i>line</i></dt>
110 <dd>
111 logical line the token was found (string)
112 </dd>
113 </dl><a NAME="Parser.parse" ID="Parser.parse"></a>
114 <h4>Parser.parse</h4>
115 <b>parse</b>(<i>text</i>)
116 <p>
117 Public method used to parse the source code.
118 </p><dl>
119 <dt><i>text</i></dt>
120 <dd>
121 the source code as read from a Python source file
122 </dd>
123 </dl>
124 <div align="right"><a href="#top">Up</a></div>
125 <hr /><hr />
126 <a NAME="SourceStat" ID="SourceStat"></a>
127 <h2>SourceStat</h2>
128 <p>
129 Class used to calculate and store the source code statistics.
130 </p>
131 <h3>Derived from</h3>
132 object
133 <h3>Class Attributes</h3>
134 <table>
135 <tr><td>None</td></tr>
136 </table>
137 <h3>Class Methods</h3>
138 <table>
139 <tr><td>None</td></tr>
140 </table>
141 <h3>Methods</h3>
142 <table>
143 <tr>
144 <td><a href="#SourceStat.__init__">SourceStat</a></td>
145 <td>Constructor</td>
146 </tr><tr>
147 <td><a href="#SourceStat.dedent">dedent</a></td>
148 <td>Public method used to decrement the indentation level.</td>
149 </tr><tr>
150 <td><a href="#SourceStat.dump">dump</a></td>
151 <td>Public method used to format and print the collected statistics.</td>
152 </tr><tr>
153 <td><a href="#SourceStat.getCounter">getCounter</a></td>
154 <td>Public method used to get a specific counter value.</td>
155 </tr><tr>
156 <td><a href="#SourceStat.inc">inc</a></td>
157 <td>Public method used to increment the value of a key.</td>
158 </tr><tr>
159 <td><a href="#SourceStat.indent">indent</a></td>
160 <td>Public method used to increment the indentation level.</td>
161 </tr><tr>
162 <td><a href="#SourceStat.push">push</a></td>
163 <td>Public method used to store an identifier.</td>
164 </tr>
165 </table>
166 <h3>Static Methods</h3>
167 <table>
168 <tr><td>None</td></tr>
169 </table>
170 <a NAME="SourceStat.__init__" ID="SourceStat.__init__"></a>
171 <h4>SourceStat (Constructor)</h4>
172 <b>SourceStat</b>(<i></i>)
173 <p>
174 Constructor
175 </p><a NAME="SourceStat.dedent" ID="SourceStat.dedent"></a>
176 <h4>SourceStat.dedent</h4>
177 <b>dedent</b>(<i>tok</i>)
178 <p>
179 Public method used to decrement the indentation level.
180 </p><dl>
181 <dt><i>tok</i></dt>
182 <dd>
183 the token to be processed (Token)
184 </dd>
185 </dl><dl>
186 <dt>Raises <b>ValueError</b>:</dt>
187 <dd>
188 raised to indicate an invalid indentation level
189 </dd>
190 </dl><a NAME="SourceStat.dump" ID="SourceStat.dump"></a>
191 <h4>SourceStat.dump</h4>
192 <b>dump</b>(<i></i>)
193 <p>
194 Public method used to format and print the collected statistics.
195 </p><a NAME="SourceStat.getCounter" ID="SourceStat.getCounter"></a>
196 <h4>SourceStat.getCounter</h4>
197 <b>getCounter</b>(<i>id, key</i>)
198 <p>
199 Public method used to get a specific counter value.
200 </p><dl>
201 <dt><i>id</i></dt>
202 <dd>
203 id of the counter (string)
204 </dd><dt><i>key</i></dt>
205 <dd>
206 key of the value to be retrieved (string)
207 </dd>
208 </dl><dl>
209 <dt>Returns:</dt>
210 <dd>
211 the value of the requested counter (int)
212 </dd>
213 </dl><a NAME="SourceStat.inc" ID="SourceStat.inc"></a>
214 <h4>SourceStat.inc</h4>
215 <b>inc</b>(<i>key, value=1</i>)
216 <p>
217 Public method used to increment the value of a key.
218 </p><dl>
219 <dt><i>key</i></dt>
220 <dd>
221 the key to be incremented
222 </dd><dt><i>value</i></dt>
223 <dd>
224 the increment (int)
225 </dd>
226 </dl><a NAME="SourceStat.indent" ID="SourceStat.indent"></a>
227 <h4>SourceStat.indent</h4>
228 <b>indent</b>(<i>tok</i>)
229 <p>
230 Public method used to increment the indentation level.
231 </p><dl>
232 <dt><i>tok</i></dt>
233 <dd>
234 a token (Token, ignored)
235 </dd>
236 </dl><a NAME="SourceStat.push" ID="SourceStat.push"></a>
237 <h4>SourceStat.push</h4>
238 <b>push</b>(<i>identifier, row</i>)
239 <p>
240 Public method used to store an identifier.
241 </p><dl>
242 <dt><i>identifier</i></dt>
243 <dd>
244 the identifier to be remembered (string)
245 </dd><dt><i>row</i></dt>
246 <dd>
247 the row, the identifier is defined in (int)
248 </dd>
249 </dl>
250 <div align="right"><a href="#top">Up</a></div>
251 <hr /><hr />
252 <a NAME="Token" ID="Token"></a>
253 <h2>Token</h2>
254 <p>
255 Class to store the token related infos.
256 </p>
257 <h3>Derived from</h3>
258 object
259 <h3>Class Attributes</h3>
260 <table>
261 <tr><td>None</td></tr>
262 </table>
263 <h3>Class Methods</h3>
264 <table>
265 <tr><td>None</td></tr>
266 </table>
267 <h3>Methods</h3>
268 <table>
269 <tr>
270 <td><a href="#Token.__init__">Token</a></td>
271 <td>Constructor</td>
272 </tr>
273 </table>
274 <h3>Static Methods</h3>
275 <table>
276 <tr><td>None</td></tr>
277 </table>
278 <a NAME="Token.__init__" ID="Token.__init__"></a>
279 <h4>Token (Constructor)</h4>
280 <b>Token</b>(<i>**kw</i>)
281 <p>
282 Constructor
283 </p><dl>
284 <dt><i>**kw=</i></dt>
285 <dd>
286 list of key, value pairs
287 </dd>
288 </dl>
289 <div align="right"><a href="#top">Up</a></div>
290 <hr /><hr />
291 <a NAME="analyze" ID="analyze"></a>
292 <h2>analyze</h2>
293 <b>analyze</b>(<i>filename, total</i>)
294 <p>
295 Module function used analyze the source of a Python file.
296 </p><dl>
297 <dt><i>filename</i></dt>
298 <dd>
299 name of the Python file to be analyzed (string)
300 </dd><dt><i>total</i></dt>
301 <dd>
302 dictionary receiving the overall code statistics
303 </dd>
304 </dl><dl>
305 <dt>Returns:</dt>
306 <dd>
307 a statistics object with the collected code statistics (SourceStat)
308 </dd>
309 </dl>
310 <div align="right"><a href="#top">Up</a></div>
311 <hr /><hr />
312 <a NAME="main" ID="main"></a>
313 <h2>main</h2>
314 <b>main</b>(<i></i>)
315 <p>
316 Module main function used when called as a script.
317 </p><p>
318 Loop over all files given on the command line and collect the individual
319 and overall source code statistics.
320 </p>
321 <div align="right"><a href="#top">Up</a></div>
322 <hr /><hr />
323 <a NAME="summarize" ID="summarize"></a>
324 <h2>summarize</h2>
325 <b>summarize</b>(<i>total, key, value</i>)
326 <p>
327 Module function used to collect overall statistics.
328 </p><dl>
329 <dt><i>total</i></dt>
330 <dd>
331 the dictionary for the overall statistics
332 </dd><dt><i>key</i></dt>
333 <dd>
334 the key to be summarize
335 </dd><dt><i>value</i></dt>
336 <dd>
337 the value to be added to the overall statistics
338 </dd>
339 </dl><dl>
340 <dt>Returns:</dt>
341 <dd>
342 the value added to the overall statistics
343 </dd>
344 </dl>
345 <div align="right"><a href="#top">Up</a></div>
346 <hr />
347 </body></html>

eric ide

mercurial