Skip to content

garyld1962/py-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Project Static Analyzer

A fast and extensible static analysis tool for Python projects written in Go. This tool helps identify common structural issues in Python codebases.

Core Features

  1. Detect Orphaned Python Files

    • Identifies .py files that are not imported anywhere else in the project
    • Outputs results to both the console and a file (output/orphaned_files.txt)
  2. Validate __init__.py Files

    • Checks for empty or missing __init__.py files in packages
    • Can automatically fix issues with user confirmation or via command-line flags
  3. Find Bad Local Imports

    • Detects import x or from y import x statements where x.py or y.py does not exist
    • Verifies that __init__.py is present for package imports
    • Handles relative imports correctly

Implementation Details

  • Written in Go for speed and concurrent processing
  • Uses Go's concurrency features (goroutines) to speed up file scanning
  • Respects .gitignore files to avoid analyzing irrelevant files
  • Processes files in parallel using a worker pool model

Installation

# Clone the repository
git clone https://github.com/yourusername/py-analyzer.git
cd py-analyzer

# Build the tool
go build

Usage

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

Project Structure

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

Performance

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

Future Enhancements

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

License

MIT License

About

Python code analyzer tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages