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