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