# eric4.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.
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

object

### Class Attributes

None

### Class Methods

None

### Methods

__addToken | Private method used to add a token to our list of tokens.
__tokeneater | Private method called by tokenize.tokenize.
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
  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.__tokeneater

__tokeneater(toktype, toktext, (srow, scol), (erow, ecol), line)

Private method called by tokenize.tokenize.

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)
erow
  ending row of the token (int)
ecol
  ending 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

Up

## SourceStat

Class used to calculate and store the source code statistics.

### Derived from

object

### Class Attributes

None

### Class Methods

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.

### Static Methods

None

#### 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)

Up

## Token

Class to store the token related infos.

### Derived from

object

### Class Attributes

None

### Class Methods

None

### Methods

Token | Constructor

### Static Methods

None

#### Token (Constructor)

Token(**kw)

Constructor

**kw
  list of key, value pairs

Up

## 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)

Up

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

Up

## 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

Up