eric7.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

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 info.

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

None

Class Attributes

None

Class Methods

None

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

None

Parser.__addToken

__addToken(toktype, toktext, srow, scol, line)

Private method used to add a token to our list of tokens.

toktype (int)
the type of the token
toktext (str)
the text of the token
srow (int)
starting row of the token
scol (int)
starting column of the token
line (str)
logical line the token was found

Parser.parse

parse(text)

Public method used to parse the source code.

text (str)
source code as read from a Python source file
Up


SourceStat

Class used to calculate and store the source code statistics.

Derived from

None

Class Attributes

None

Class Methods

None

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

None

SourceStat (Constructor)

SourceStat()

Constructor

SourceStat.dedent

dedent(tok)

Public method used to decrement the indentation level.

tok (Token)
the token to be processed
Raises ValueError:
raised to indicate an invalid indentation level

SourceStat.getCounter

getCounter(counterId, key)

Public method used to get a specific counter value.

counterId (str)
id of the counter
key (str)
key of the value to be retrieved
Return:
the value of the requested counter
Return Type:
int

SourceStat.inc

inc(key, value=1)

Public method used to increment the value of a key.

key (str)
key to be incremented
value (int)
the increment

SourceStat.indent

indent()

Public method used to increment the indentation level.

SourceStat.push

push(identifier, row)

Public method used to store an identifier.

identifier (str)
the identifier to be remembered
row (int)
row, the identifier is defined in
Up


Token

Class to store the token related info.

Derived from

None

Class Attributes

col
line
row
text
type

Class Methods

None

Methods

None

Static Methods

None
Up


analyze

analyze(filename, total)

Module function used analyze the source of a Python file.

filename (str)
name of the Python file to be analyzed
total (dict)
dictionary receiving the overall code statistics
Return:
a statistics object with the collected code statistics
Return Type:
SourceStat
Up


summarize

summarize(total, key, value)

Module function used to collect overall statistics.

total (dict)
dictionary of overall statistics
key (str)
key to be summarized
value (int)
value to be added to the overall statistics
Return:
the value added to the overall statistics
Return Type:
int
Up