eric6.DataViews.CodeMetrics
Module implementing a simple Python code metrics analyzer.
- Raises ValueError:
-
the tokenize module is too old
Global Attributes
COMMENT |
DEDENT |
EMPTY |
INDENT |
KEYWORD |
NEWLINE |
spacer |
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 |
Module function used analyze the source of a Python file. |
summarize |
Module function used to collect overall statistics. |
Parser
Class used to parse the source code of a Python file.
Derived from
object
Class Attributes
Class Methods
Methods
__addToken |
Private method used to add a token to our list of tokens. |
parse |
Public method used to parse the source code. |
Static Methods
Parser.__addToken
__addToken(toktype, toktext, srow, scol, line)
Private method used to add a token to our list of tokens.
- toktype
-
the type of the token (int)
- toktext
-
the text of the token (string)
- srow
-
starting row of the token (int)
- scol
-
starting column of the token (int)
- line
-
logical line the token was found (string)
Parser.parse
parse(text)
Public method used to parse the source code.
- text
-
the source code as read from a Python source file
SourceStat
Class used to calculate and store the source code statistics.
Derived from
object
Class Attributes
Class Methods
Methods
SourceStat |
Constructor |
dedent |
Public method used to decrement the indentation level. |
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. |
Static Methods
SourceStat (Constructor)
SourceStat()
Constructor
SourceStat.dedent
dedent(tok)
Public method used to decrement the indentation level.
- tok
-
the token to be processed (Token)
- Raises ValueError:
-
raised to indicate an invalid indentation level
SourceStat.getCounter
getCounter(counterId, key)
Public method used to get a specific counter value.
- counterId
-
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
object
Class Attributes
Class Methods
Methods
Static 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)
summarize
summarize(total, key, value)
Module function used to collect overall statistics.
- total
-
the dictionary for the overall statistics
- key
-
the key to be summarize
- value
-
the value to be added to the overall statistics
- Returns:
-
the value added to the overall statistics