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