Metadata-Version: 2.4
Name: koz
Version: 0.1.0
Summary: Python monkeypatch detection and analysis tool
Author: Koz Contributors
License: Unlicense
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: Public Domain
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0.0
Requires-Dist: gitpython>=3.1.0
Requires-Dist: tomli-w>=1.0.0
Requires-Dist: click>=8.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
Requires-Dist: types-click; extra == "dev"
Dynamic: license-file

# koz

Python monkeypatch detection and analysis tool.

## Overview

`koz` is a static analysis tool that detects and catalogs monkeypatch modifications in Python codebases. It uses AST parsing to identify patches and generates structured output for patch management.

## Features

- Detects three types of monkeypatching:
  - `@patch_to` decorator from `fastcore.basic`
  - Direct attribute assignment monkeypatching
  - `functools.wraps` decorator in `__init__` methods
- Generates JSON/TOML output with comprehensive metadata
- Integrates with git history for author and timestamp information
- Fast AST-based analysis without code execution

## Installation

```bash
pip install -e .
```

## Usage

### Command Line

```bash
# Analyze current directory
koz analyze

# Analyze specific directory
koz analyze /path/to/project

# Output to TOML
koz analyze --format toml --output patches.toml

# Output to JSON
koz analyze --format json --output patches.json
```

### Detected Patterns

#### 1. fastcore.basic.patch_to Decorator
The most common pattern in fastai/fastcore projects:

```python
from fastcore.basic import patch_to

class MyClass:
    def __init__(self):
        self.value = 0

@patch_to(MyClass)
def new_method(self):
    """This method is added to MyClass via patch_to."""
    return self.value * 2
```

#### 2. Direct Attribute Assignment
```python
def custom_method(self):
    return "custom"

MyClass.method = custom_method
```

#### 3. functools.wraps Pattern
```python
from functools import wraps

class Wrapper:
    def __init__(self):
        @wraps(TargetClass.method)
        def wrapped(self):
            return "wrapped"
        TargetClass.method = wrapped
```

## Development

```bash
# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run linter
ruff check src/ tests/

# Format code
black src/ tests/

# Type check
mypy src/

# Install pre-commit hooks
pre-commit install
```

## License

Unlicense
