Skip to main content

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.

Python 3.11+ License: MIT

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:

  1. ๐Ÿ” Discovery Phase: Finds all Python files while respecting gitignore patterns
  2. ๐Ÿ“Š Parsing Phase: Uses Tree-sitter to extract functions, classes, and methods with their docstrings
  3. ๐Ÿ”— 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 Rich
  • src/uzpy/discovery.py - File discovery with gitignore support
  • src/uzpy/parser/ - Tree-sitter based Python parsing
  • src/uzpy/analyzer/ - Hybrid analysis using Rope and Jedi
  • src/uzpy/modifier/ - LibCST-based code modification (planned)

Contributing

Contributions are welcome! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with tests
  4. Run the full development pipeline
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. 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-sitter and tree-sitter-python for parsing
    • rope for accurate reference finding
    • jedi for fast symbol resolution
    • fire for CLI generation
    • rich for beautiful terminal output
    • loguru for structured logging
    • pathspec for 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

uzpy-1.0.4.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uzpy-1.0.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

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

Hashes for uzpy-1.0.4.tar.gz
Algorithm Hash digest
SHA256 cb74a86faf908c53e8963cb69bd072453feccf37842fba414fbf6363ca9f9e71
MD5 903effd0821c6ae9d524974b58b1a379
BLAKE2b-256 7bfae3f717a92337c8e7fd9a13ba19af0684760e41b3e4a5a4b531b27c80dbea

See more details on using hashes here.

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

Hashes for uzpy-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6bef1452f6113cb873dcc0cbf06a14f7914157aaafbd579f64bb23a440a3ed8c
MD5 08dfabec365e7fcd6211f618575a7bd7
BLAKE2b-256 b6db33365961f04240e7cc885379e322645006e68545ceedcc394d4cc0e24792

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page