Skip to main content

import-resolve

CI License: MIT

Auto-resolve Git merge conflicts in Python import blocks. Deterministic, zero dependencies, zero config, no AI.

Before / after (from a real git merge)

Two branches each added one import. Git conflicted. import-resolve kept both.

Before (docs/examples/app.before.py):

import json
<<<<<<< HEAD
import os
=======
import math
>>>>>>> feature-a

print(json.dumps({'ok': True}))

Terminal:

$ import-resolve
[ok] app.py: resolved 1 import conflict

After (docs/examples/app.after.py):

import json
import math
import os

print(json.dumps({'ok': True}))

Both branches survive. Duplicates removed. Sorted. Conflict markers gone.

Install

From PyPI (once published):

pip install import-resolve-cli

From this GitHub repo (works today):

pip install git+https://github.com/ikrame-ih/import-resolve.git

That installs the import-resolve command. The PyPI package is named import-resolve-cli because import-resolve is already taken by an unrelated project from 2017.

Requires Python 3.9+. No runtime dependencies — a few hundred lines of standard library.

Usage

import-resolve                 # fix every conflicted .py file Git reports
import-resolve app.py utils.py # fix specific files
import-resolve --dry-run       # show the diff, write nothing
import-resolve --check         # exit 1 if any conflict markers are found (CI)

Exit codes: 0 all import conflicts resolved (or none existed), 1 conflicts remain for a human, 2 usage error.

Optional: fully automatic mode

Register a merge driver in the current repository only:

import-resolve --install-hook    # .git/config + .git/info/attributes
import-resolve --uninstall-hook

After that, git merge / rebase / cherry-pick clear pure-import conflicts quietly and only stop for conflicts that need a person. Nothing goes into global Git config or into the versioned tree — teammates opt in themselves.

Safety model

If a conflict block contains one line that is not an import, a comment, or a blank line, the block is left untouched and you get a reason:

[skip] app.py:14: left untouched for safety (non-import line: 'value = compute()')

Also refused (on purpose):

  • multiline imports (from typing import ())
  • backslash line continuations
  • indented imports (inside functions / try)

Extra guards:

  • merged block must pass ast.parse or nothing is written
  • atomic write (temp file + os.replace)
  • LF/CRLF and UTF-8 BOM preserved
  • binary / non-UTF-8 / files over 5 MB refused
  • no network, no AI, no telemetry — code never leaves your machine

Logic conflicts further down the same file stay exactly as Git left them.

What it does NOT do

Out of scope Why
Business-logic conflicts That needs a human
Multiline import blocks Too easy to corrupt; skipped with a warning
Full isort/ruff style Run your formatter after; we sort simply
JS/TS imports Possible v2
Config files Zero config is the point

Why this exists (short case study)

Import conflicts are mechanical: two people added different import lines to the same header. Current options are weak for that case:

  • GitHub's CLI guide — open the editor and delete markers by hand
  • StackOverflow --ours / --theirs — destructive; one side's imports vanish
  • isort / ruff / Black — fail with a syntax error while markers are present
  • AI resolvers — need API keys, send code off-machine, non-deterministic
  • Mergiraf — excellent structural merge driver; if you want that full pipeline and can install a Rust binary + Git config, use it

import-resolve is the remaining gap: the file is already broken in front of you, and you want one local command, right now, with nothing configured.

Roadmap

  • JS/TS import blocks (v2, if there's demand)
  • --stage to git add fully resolved files

Development

pip install -e ".[dev]"
pytest
mypy
ruff check .

License

MIT © Ikrame Ih

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

import_resolve_cli-0.1.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

import_resolve_cli-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: import_resolve_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for import_resolve_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd18af7e8d176c0c8fa913ddfd9bea89452809c6eaf766408047e2ac90db9d1a
MD5 ded3b6c9c13f07fe08c5bf0f35e2c2a7
BLAKE2b-256 9eab0364249550bd3a1522aa90ddad1718a8ae85599366084a4fc79a830b0f2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for import_resolve_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5c573201dce79860ce90454c18d214787d0ecd548a3c423e9654ba33e12dd36
MD5 1f993440fd01d173fc12ff8e6d50eba0
BLAKE2b-256 b6d771d51b858dba1ec58327f4760af2d44799932c105f457be1c3e198853df8

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