Skip to main content

Detect and repair broken Python imports after refactoring, with zero runtime cost

Project description

import-check

Detect and repair broken Python imports after refactoring — with zero runtime cost.

What it does

After a codebase refactoring (manual or autonomous), module paths shift. Every file that imported moved symbols now references a path that no longer exists. import-check fixes this retroactively:

  1. Inventories symbols before and after using git history + AST (no code executed)
  2. Detects moves, renames, splits, and merges in the migration map
  3. Rewrites all broken imports in-place using libcst (format-preserving)
  4. Verifies every import via filesystem + AST checks (zero runtime loading)

Installation

pip install import-check

Usage

# Full pipeline: fix then verify
python -m import_check run

# Fix broken imports only
python -m import_check fix

# Verify imports only (CI gate)
python -m import_check check

# With options
python -m import_check run \
  --source-dirs src lib \
  --git-ref HEAD~3 \
  --format json \
  --log-level DEBUG

Programmatic API

from import_check import fix, check, run

# Full pipeline
result = run(root="/path/to/project", source_dirs=["src"], git_ref="HEAD~1")

# Fix only
fix_results = fix(root=".", git_ref="abc123")

# Check only
errors = check(root=".", encapsulation_check=True)

Configuration

Add to pyproject.toml:

[tool.import_check]
source_dirs = ["src", "lib"]
exclude_patterns = [".venv", "__pycache__", "node_modules"]
git_ref = "HEAD"
encapsulation_check = true
output_format = "human"   # or "json"
log_level = "INFO"        # or "DEBUG", "ERROR"
check_stubs = true        # .pyi stub fallback
check_getattr = true      # __getattr__ suppression

Design

  • Deterministic-first: AST-based analysis handles the common case. LLM integration for residuals is out of scope — the structured error list is the handoff contract.
  • Zero runtime cost: The checker never loads a module. Safe in any environment.
  • Generic: Works on any Python project with git. No project-specific config required.
  • Single dependency: Only libcst beyond the standard library.

License

MIT

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

import_mend-0.1.0.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

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

import_mend-0.1.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file import_mend-0.1.0.tar.gz.

File metadata

  • Download URL: import_mend-0.1.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for import_mend-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc638e477889470d7bf58f78dba88cd4b379b8d0e3ad01a51df0f19f841fca03
MD5 82fd2a9144ebeb37aefee5d07e1c1093
BLAKE2b-256 15439d683825b0257ee7f3af09fdec9eb36971795f983c20a58f6c9d868a52bb

See more details on using hashes here.

File details

Details for the file import_mend-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: import_mend-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for import_mend-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e3e6cbe77386e266b2e6b156e028a1dd005cc09545d043cd543c054027ffffb
MD5 c8e55201a5e45f83e103173a6932a1fc
BLAKE2b-256 5e3d11cb517bab9e184e5ed738a5ac814960599486e0e5d661f951e483d0d7c3

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