Automated Python Code Quality Assessment with Prospector
Prospector aggregates multiple Python static analysis tools—Pylint, PyFlakes, pycodestyle, pydocstyle, and McCabe complexity checker—into a unified interface for comprehensive code quality assessment.
Install via pip:
pip install prospector
Analyze individual files by specifying the path:
prospector module.py
For recursive project analysis:
prospector src/
Customize behavior using profiles and strictness levels:
prospector --profile ci.yaml --strictness veryhigh src/
The output format identifies specific locations and issue types:
module.py
Line: 4
F401: module imported but unused
E302: expected 2 blank lines, found 1
Line: 7
C0103: Function name "CalculateTotal" doesn't conform to snake_case naming style
Consider this problematic implementation:
# calculations.py
import json,math
def CalculateTotal(a,b):
return a+b
print(CalculateTotal(5,3))
Running Prospector reveals:
calculations.py
Line: 2
F401: json imported but unused
E231: missing whitespace after ','
Line: 4
E302: expected 2 blank lines, found 1
C0103: Function name "CalculateTotal" doesn't conform to snake_case naming style
E231: missing whitespace after ','
E225: missing whitespace around operator
Line: 6
W292: no newline at end of file
Addressing these violations produces cleaner code:
# calculations.py
import math
def calculate_total(first, second):
return first + second
if __name__ == "__main__":
print(calculate_total(5, 3))
Configuration files enable project-specific rules. Create .prospector.yaml to adjust thresholds:
strictness: high
ignore:
- tests/
- build/
pep8:
options:
max-line-length: 100
pylint:
disable:
- C0111
- R0903
This configuration excludes test directoreis, extends line length limits to 100 characters, and disables missing docsrting warnings while maintaining high strictness for other metrics.