eric3.UI.CodeMetrics
Module implementing a simple Python code metrics analyzer.
- Raises ValueError:
-
the tokenize module is too old
Classes
Parser |
Class used to parse the source code of a Python file. |
SourceStat |
Class used to calculate and store the source code statistics. |
Token |
Class to store the token related infos. |
Functions
analyze |
|
main |
Modules main function used when called as a script. |
summarize |
Module function used to collect overall statistics. |
Parser
Class used to parse the source code of a Python file.
Derived from
None
Methods
addToken |
Private method used to add a token to our list of tokens. |
parse |
Public method used to parse the source code. |
tokeneater |
Private method called by tokenize.tokenize. |
Parser.addToken
addToken(toktype, toktext, srow, scol, line)
Private method used to add a token to our list of tokens.
- line
-
logical line the token was found (string)
- scol
-
starting column of the token (int)
- srow
-
starting row of the token (int)
- toktext
-
the text of the token (string)
- toktype
-
the type of the token (int)
Parser.parse
parse(text)
Public method used to parse the source code.
- text
-
the source code as read from a Python source file
Parser.tokeneater
tokeneater(toktype, toktext, (srow, scol), (erow, ecol), line)
Private method called by tokenize.tokenize.
- ecol
-
ending column of the token (int)
- erow
-
ending row of the token (int)
- line
-
logical line the token was found (string)
- scol
-
starting column of the token (int)
- srow
-
starting row of the token (int)
- toktext
-
the text of the token (string)
- toktype
-
the type of the token (int)
SourceStat
Class used to calculate and store the source code statistics.
Derived from
None
Methods
SourceStat |
Constructor |
dedent |
Public method used to decrement the indentation level. |
dump |
Public method used to format and print the collected statistics. |
getCounter |
Public method used to get a specific counter value. |
inc |
Public method used to increment the value of a key. |
indent |
Public method used to increment the indentation level. |
push |
Public method used to store an identifier. |
SourceStat (Constructor)
SourceStat()
Constructor
SourceStat.dedent
dedent(tok)
Public method used to decrement the indentation level.
- tok
-
the token to be processed (Token)
SourceStat.dump
dump()
Public method used to format and print the collected statistics.
SourceStat.getCounter
getCounter(id, key)
Public method used to get a specific counter value.
- id
-
id of the counter (string)
- key
-
key of the value to be retrieved (string)
- Returns:
-
the value of the requested counter (int)
SourceStat.inc
inc(key, value=1)
Public method used to increment the value of a key.
- key
-
the key to be incremented
- value
-
the increment (int)
SourceStat.indent
indent(tok)
Public method used to increment the indentation level.
- tok
-
a token (Token, ignored)
SourceStat.push
push(identifier, row)
Public method used to store an identifier.
- identifier
-
the identifier to be remembered (string)
- row
-
the row, the identifier is defined in (int)
Token
Class to store the token related infos.
Derived from
None
Methods
Token (Constructor)
Token(**kw)
Constructor
- **kw
-
list of key, value pairs
analyze
analyze(filename, total)
Module function used analyze the source of a Python file.
- filename
-
name of the Python file to be analyzed (string)
- total
-
dictionary receiving the overall code statistics
- Returns:
-
a statistics object with the collected code statistics (SourceStat)
main
main()
Modules main function used when called as a script.
This function simply loops over all files given on the commandline
and collects the individual and overall source code statistics.
summarize
summarize(total, key, value)
Module function used to collect overall statistics.
- key
-
the key to be summarize
- total
-
the dictionary for the overall statistics
- value
-
the value to be added to the overall statistics
- Returns:
-
the value added to the overall statistics