Metadata-Version: 2.4
Name: clawde
Version: 0.1.0
Summary: Move inline imports (imports inside function bodies) to the top of Python files.
Project-URL: Homepage, https://github.com/mahner/clawde
Project-URL: Repository, https://github.com/mahner/clawde
Project-URL: Issues, https://github.com/mahner/clawde/issues
Author-email: Martin Mahner <martin@elephant.house>
License: MIT License
        
        Copyright (c) 2026 Martin Mahner
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ast,code-quality,imports,lint,refactor
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Requires-Dist: rich>=13.0
Description-Content-Type: text/markdown

# clawde

Move inline imports — imports buried inside function bodies — back to the top of the file, where they belong.

Imports inside `try/except` blocks, inside `if TYPE_CHECKING:` blocks, or marked with `# noqa` are left in place.

## Install / run

Run without installing:

```bash
uvx clawde --help
```

Or install it:

```bash
uv tool install clawde
# or
pipx install clawde
```

## Usage

By default, `clawde` runs in **dry-run** mode and prints a table of imports it would move. Pass `--write` to actually apply the changes.

```bash
# Show what would change in the current directory
clawde

# Apply changes
clawde --write

# Target specific paths
clawde src/ scripts/foo.py
```

### Example output

```text
❯ clawde myproject/
  Scanning Python files... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%

Inline Import Analysis

 Status      File:Line             Import                                          Reason
 🟢 Skipped  manage.py:13          from django.core.management import              Inside try/except block
                                   execute_from_command_line
 🟢 Skipped  apps/team/cache.py:9  from .models import AboutPage  # noqa: PLC0415  Marked with # noqa
 🟢 Skipped  apps/til/apps.py:18   from .signals import post_delete  # noqa        Marked with # noqa
 🟡 Move     apps/blog/0024.py:16  from wagtail.images import get_image_model
 🟡 Move     apps/blog/0024.py:17  from wagtail.models import Page, Site

Total: 5 imports analyzed
To Move: 2
Skipped: 3

Note: This was a dry-run. No files were modified.
Use --write to apply changes.
```

### What it does

For every `.py` file under the given paths, `clawde` parses the source with `ast` and looks for `import` / `from ... import` statements inside function bodies. Each finding is reported as:

| Status  | Meaning                                                                 |
| ------- | ----------------------------------------------------------------------- |
| Move    | Will be lifted to the top of the file (under any `__future__` imports). |
| Skipped | Left in place — inside `try`, `TYPE_CHECKING`, or marked `# noqa`.      |
| Error   | File could not be parsed.                                               |

Hidden directories (any path segment starting with `.`) are always skipped — this catches `.git`, `.venv`, `.tox`, `.mypy_cache`, `.ruff_cache`, `.pytest_cache`, and so on.

In addition, the following directory names are skipped by default:

- `node_modules`
- `venv`
- `build`
- `dist`
- `__pycache__`
- `site-packages`
- `htmlcov`

### Configuration

You can override the named exclude list by adding a `[tool.clawde]` section to your `pyproject.toml`:

```toml
[tool.clawde]
exclude = ["build", "dist", "node_modules", "vendor", "generated"]
```

- The list **replaces** the default — include any defaults you still want.
- Entries are matched against path *segments* (folder names), not full paths or globs.
- Hidden directories are skipped regardless of this setting.
- Set `exclude = []` to scan every non-hidden directory.

`clawde` looks for a `pyproject.toml` by walking up from the current working directory.
