Skip to main content

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

Project description

import-mend

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-mend 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-mend

Usage

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

# Fix broken imports only
python -m import_mend fix

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

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

Programmatic API

from import_mend 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_mend]
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.1.tar.gz (47.2 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.1-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: import_mend-0.1.1.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for import_mend-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c6d1e4c87a6415768794dbafaf8f8b83990ef9bdbe1159c8150f6e69062d3896
MD5 e1c383928626e1f9c47ab8e2a5edfb74
BLAKE2b-256 a4baf630b28a80f03644c0ad599c1b4286b047ab3c600f9ddd14f003c6856caf

See more details on using hashes here.

Provenance

The following attestation bundles were made for import_mend-0.1.1.tar.gz:

Publisher: publish.yml on JuanSync7/import-mend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: import_mend-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for import_mend-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a815250e8831923dded50a1511f71283d012278479b92592cc223a30cf3b5919
MD5 7df9622f55ef0b21c91137484ed11404
BLAKE2b-256 d828ae0ae7dee493e386b12bfb270358ca7ccfe44e5069af78ce790327911ab0

See more details on using hashes here.

Provenance

The following attestation bundles were made for import_mend-0.1.1-py3-none-any.whl:

Publisher: publish.yml on JuanSync7/import-mend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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