Skip to main content

Move inline imports (imports inside function bodies) to the top of Python files.

Project description

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:

uvx clawde --help

Or install it:

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.

# Show what would change in the current directory
clawde

# Apply changes
clawde --write

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

Example output

❯ 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:

[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.

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

clawde-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

clawde-0.1.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file clawde-0.1.1.tar.gz.

File metadata

  • Download URL: clawde-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for clawde-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cb49b0eb56ec38cbf0b8f0414658e6c34fc87d9ff57258838a239c2b983c30f6
MD5 3e507372d0081b56a5fc8aaa3b0378c2
BLAKE2b-256 0aa71f862254be307d5897386bdc5294a56101d5073df1295f8e12aba6fe7aab

See more details on using hashes here.

File details

Details for the file clawde-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: clawde-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for clawde-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e61ac84f9db7d77d3d0255a1d80a4663f769f7fae88e999e9d06cd793b9a0dcf
MD5 54f7150af5817bb9b316d8d774110bb3
BLAKE2b-256 5a4281a978acd20b509dd66f04adbc248b8b52fcebc20db2aea79b1c7c71f0a6

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