Python Code Reachability Analyzer
Project description
PyReachX
PyReachX is a static code analysis tool that helps identify unreachable code in Python projects. It analyzes your Python codebase to find functions and methods that are never called or accessed.
Features
- Identifies unreachable functions and methods
- Generates HTML and JSON reports
- Configurable exclusion patterns
- Support for class method analysis
- Command-line interface
- Confidence scoring for identified unreachable code
Installation
pip install pyreachx
Usage
Command Line
# Basic usage
pyreachx /path/to/your/project
# Specify entry point
pyreachx /path/to/your/project -e module.main
# Custom configuration file
pyreachx /path/to/your/project -c config.yml
# Custom output file
pyreachx /path/to/your/project -o report.html
Configuration
Create a pyreachx.yml
file to customize the analysis:
exclude_patterns:
- "**/test_*.py"
- "**/__init__.py"
ignore_decorators:
- "@property"
- "@staticmethod"
confidence_threshold: 0.8
Python API
from pyreachx import CodeAnalyzer, AnalyzerConfig
# Create configuration
config = AnalyzerConfig.from_file("pyreachx.yml")
# Initialize analyzer
analyzer = CodeAnalyzer(config)
# Run analysis
result = analyzer.analyze("/path/to/project", entry_point="main")
# Generate report
from pyreachx import Reporter
reporter = Reporter(result)
reporter.generate_report("report.html")
Example Output
HTML Report:
<div class='item'>
<strong>module.py</strong> (lines 10-15)<br>
Type: function<br>
Name: unused_function<br>
Confidence: 95%
</div>
JSON Report:
{
"unreachable_items": [
{
"file_path": "module.py",
"line_start": 10,
"line_end": 15,
"code_type": "function",
"name": "unused_function",
"confidence": 0.95
}
],
"statistics": {
"total_unreachable_lines": 6,
"files_affected": ["module.py"],
"type_distribution": {
"function": 1
}
}
}
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/ad3002/pyreachx.git
cd pyreachx
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e .[test]
Running Tests
pytest tests/
Code Style
This project uses:
- Black for code formatting
- isort for import sorting
- flake8 for linting
# Format code
black pyreachx tests
isort pyreachx tests
# Check linting
flake8 pyreachx tests
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- AST module from Python standard library
- NetworkX for dependency graph analysis
- Click for CLI interface
- Jinja2 for report templating
Project Status
PyReachX is in alpha stage. While it's functional, there might be false positives and edge cases that aren't handled yet. Use with caution in production environments.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyreachx-0.1.0.tar.gz
.
File metadata
- Download URL: pyreachx-0.1.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb73d728a51c13c40126f1f84d2abbd166cf2844c1d8ef75591219e5d95362cb |
|
MD5 | f8aa864f73dbe7dd27223db3180abf8f |
|
BLAKE2b-256 | 0212717eafedab2823a011361771e059058c5899ee2dd1948eeabe6aaa19c3a4 |
File details
Details for the file pyreachx-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pyreachx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dbb61263793650177755e7017126a49ff667ef4bdfefe64accd9025d3d3b61d |
|
MD5 | 597f0d30679d6c5fe39ed2ddbea98ca9 |
|
BLAKE2b-256 | 0eccd85289bacce0ce03926c9d876759e459d34b864f6c91eea9f25816a0ea2b |