A fast and extensible static analysis tool for Python projects written in Go. This tool helps identify common structural issues in Python codebases.
-
Detect Orphaned Python Files
- Identifies
.pyfiles that are not imported anywhere else in the project - Outputs results to both the console and a file (
output/orphaned_files.txt)
- Identifies
-
Validate
__init__.pyFiles- Checks for empty or missing
__init__.pyfiles in packages - Can automatically fix issues with user confirmation or via command-line flags
- Checks for empty or missing
-
Find Bad Local Imports
- Detects
import xorfrom y import xstatements wherex.pyory.pydoes not exist - Verifies that
__init__.pyis present for package imports - Handles relative imports correctly
- Detects
- Written in Go for speed and concurrent processing
- Uses Go's concurrency features (goroutines) to speed up file scanning
- Respects
.gitignorefiles to avoid analyzing irrelevant files - Processes files in parallel using a worker pool model
# Clone the repository
git clone https://github.com/yourusername/py-analyzer.git
cd py-analyzer
# Build the tool
go build# Basic usage
./py-analyzer /path/to/python/project
# Automatically fix empty __init__.py files
./py-analyzer -fix-empty /path/to/python/project
# Automatically create missing __init__.py files
./py-analyzer -fix-missing /path/to/python/project
# Both auto-fixes together
./py-analyzer -fix-empty -fix-missing /path/to/python/project
# Display help information
./py-analyzer -helppy-analyzer/
│── main.go # Entry point
│── scanner/
│ │── orphaned.go # Detect orphaned Python files
│ │── init_check.go # Validate __init__.py files
│ │── imports.go # Find bad local imports
│ └── utils.go # Common utilities
│── output/
│ └── orphaned_files.txt # Output file (generated on run)
│── go.mod
│── go.sum
└── README.md
The tool is designed for performance:
- Uses concurrent file scanning for speed
- Employs worker pools to efficiently process files
- Minimizes redundant file reads
- Optimizes memory usage with stream processing
Potential improvements for future versions:
- Configuration file support for customizing behavior
- More detailed reporting options and formats (JSON, CSV)
- Additional analysis types (complexity, style checking)
- IDE integrations
- CI/CD pipeline integrations
MIT License