A tool to track where Python constructs are used and update docstrings
Project description
uzpy
A Python tool that automatically analyzes code usage patterns and updates docstrings with "Used in:" documentation.
uzpy scans Python codebases to find where each function, class, and method is used, then automatically updates their docstrings with comprehensive usage information. This helps developers understand code dependencies and maintain better documentation.
Features
- ๐ Smart Analysis: Uses Tree-sitter for fast, error-resilient Python parsing
- ๐ฏ Accurate References: Combines Rope and Jedi for comprehensive usage detection
- ๐ Safe Modifications: Preserves code formatting using LibCST (planned)
- โก High Performance: Optimized for large codebases with hybrid analysis strategies
- ๐จ Beautiful Output: Rich terminal interface with progress indicators and summaries
- ๐ก๏ธ Error Recovery: Graceful handling of syntax errors and edge cases
Installation
# Install from PyPI (when published)
pip install uzpy
# Or install from source
git clone https://github.com/yourusername/uzpy.git
cd uzpy
pip install -e .
Quick Start
# Analyze a single file
uzpy run --edit myproject/utils.py
# Analyze entire directory
uzpy run --edit src/ --ref .
# Dry run to see what would change
uzpy run --edit src/ --dry-run --verbose
# Get detailed help
uzpy run --help
Usage Examples
Basic Analysis
# Analyze functions in utils.py and search for usage across the current directory
uzpy run --edit utils.py --ref .
Advanced Options
# Comprehensive analysis with verbose output
uzpy run \
--edit src/mypackage/ \
--ref . \
--verbose \
--include-methods \
--include-classes \
--include-functions \
--exclude-patterns="tests/*,build/*"
Configuration Examples
# Focus on specific construct types
uzpy run --edit src/ --include-functions --no-include-methods
# Exclude test directories
uzpy run --edit src/ --exclude-patterns="**/test_*,**/tests/*"
# Dry run to preview changes
uzpy run --edit src/ --dry-run
How It Works
uzpy uses a sophisticated three-phase pipeline:
- ๐ Discovery Phase: Finds all Python files while respecting gitignore patterns
- ๐ Parsing Phase: Uses Tree-sitter to extract functions, classes, and methods with their docstrings
- ๐ Analysis Phase: Employs a hybrid approach combining Rope and Jedi to find usage patterns
Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ File Discovery โโโโโถโ Tree-sitter โโโโโถโ Hybrid Analyzerโ
โ (gitignore + โ โ Parser โ โ (Rope + Jedi) โ
โ pathspec) โ โ (AST + constructs)โ โ (usage finding)โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ LibCST Modifierโ
โ (docstring โ
โ updates) โ
โโโโโโโโโโโโโโโโโโโ
Example Output
When you run uzpy, you'll see beautiful terminal output like this:
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ uzpy Configuration โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Edit Path โ src/myproject/ โ
โ Reference Path โ . โ
โ Dry Run โ No โ
โ Verbose โ Yes โ
โโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ File Discovery Summary โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Edit Files โ 23 โ utils.py, models.py, ... โ
โ Reference Files โ 156 โ main.py, tests.py, ... โ
โโโโโโโโโโโโโโโโโโโดโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Construct Parsing Summary โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Module โ 23 โ 12/23 โ
โ Class โ 45 โ 31/45 โ
โ Function โ 128 โ 89/128โ
โ Method โ 267 โ 156/267โ
โ Total โ 463 โ 288/463โ
โโโโโโโโโโโโดโโโโโโโดโโโโโโโโ
CLI Reference
Commands
uzpy run- Main analysis command
Options
| Option | Description | Default |
|---|---|---|
--edit |
Path to analyze and modify | Required |
--ref |
Reference path to search for usage | Same as edit |
--verbose |
Enable detailed logging | False |
--dry-run |
Show changes without modifying files | False |
--include-methods |
Include method definitions | True |
--include-classes |
Include class definitions | True |
--include-functions |
Include function definitions | True |
--exclude-patterns |
Comma-separated glob patterns to exclude | None |
Development
uzpy is built with modern Python practices and comprehensive testing.
Setup Development Environment
# Clone the repository
git clone https://github.com/yourusername/uzpy.git
cd uzpy
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Development Workflow
# Run tests
python -m pytest
# Run tests with coverage
python -m pytest --cov=uzpy
# Lint and format code
ruff check --fix
ruff format
# Type checking
mypy src/uzpy
# Full development pipeline
fd -e py -x autoflake {}; fd -e py -x pyupgrade --py311-plus {}; fd -e py -x ruff check --output-format=github --fix --unsafe-fixes {}; fd -e py -x ruff format --respect-gitignore --target-version py311 {}; python -m pytest;
Architecture Overview
uzpy is designed with modularity and extensibility in mind:
src/uzpy/cli.py- Command-line interface using Fire and Richsrc/uzpy/discovery.py- File discovery with gitignore supportsrc/uzpy/parser/- Tree-sitter based Python parsingsrc/uzpy/analyzer/- Hybrid analysis using Rope and Jedisrc/uzpy/modifier/- LibCST-based code modification (planned)
Contributing
Contributions are welcome! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Run the full development pipeline
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Style
We follow strict code quality standards:
- Formatting: Ruff with line length 88
- Type Hints: Full type annotations required
- Documentation: Comprehensive docstrings for all public APIs
- Testing: Minimum 90% test coverage
Current Status
Version: 0.1.0 (Development)
Completed Features:
- โ CLI interface with Rich formatting
- โ File discovery with gitignore support
- โ Tree-sitter Python parsing
- โ Rope and Jedi analysis integration
- โ Hybrid analysis strategies
- โ Comprehensive test suite
Planned Features:
- ๐ LibCST-based docstring modification
- ๐ Configuration file support
- ๐ Language Server Protocol integration
- ๐ CI/CD integration tools
Requirements
- Python: 3.11+ (uses modern Python features)
- Dependencies: All managed automatically via pip
tree-sitterandtree-sitter-pythonfor parsingropefor accurate reference findingjedifor fast symbol resolutionfirefor CLI generationrichfor beautiful terminal outputlogurufor structured loggingpathspecfor gitignore pattern matching
License
This project is licensed under the MIT License. See LICENSE for details.
Changelog
See CHANGELOG.md for detailed version history.
Built with โค๏ธ using modern Python tools and best practices.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uzpy-1.0.4.tar.gz.
File metadata
- Download URL: uzpy-1.0.4.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb74a86faf908c53e8963cb69bd072453feccf37842fba414fbf6363ca9f9e71
|
|
| MD5 |
903effd0821c6ae9d524974b58b1a379
|
|
| BLAKE2b-256 |
7bfae3f717a92337c8e7fd9a13ba19af0684760e41b3e4a5a4b531b27c80dbea
|
File details
Details for the file uzpy-1.0.4-py3-none-any.whl.
File metadata
- Download URL: uzpy-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bef1452f6113cb873dcc0cbf06a14f7914157aaafbd579f64bb23a440a3ed8c
|
|
| MD5 |
08dfabec365e7fcd6211f618575a7bd7
|
|
| BLAKE2b-256 |
b6db33365961f04240e7cc885379e322645006e68545ceedcc394d4cc0e24792
|