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