Metadata-Version: 2.4
Name: import-resolve-cli
Version: 0.1.0
Summary: Deterministic CLI that auto-resolves Git merge conflicts in Python import blocks. Zero dependencies, zero config, no AI.
Project-URL: Homepage, https://github.com/ikrame-ih/import-resolve
Project-URL: Issues, https://github.com/ikrame-ih/import-resolve/issues
Author: Ikrame Ih
License: MIT License
        
        Copyright (c) 2026 Ikrame Ih
        
        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: cli,conflict,developer-tools,git,imports,merge
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 :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Typing :: Typed
Requires-Python: >=3.9
Provides-Extra: dev
Requires-Dist: mypy>=1.8; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# import-resolve

[![CI](https://github.com/ikrame-ih/import-resolve/actions/workflows/ci.yml/badge.svg)](https://github.com/ikrame-ih/import-resolve/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

> 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`](docs/examples/app.before.py)):

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

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

**Terminal:**

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

**After** ([`docs/examples/app.after.py`](docs/examples/app.after.py)):

```python
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):

```bash
pip install import-resolve-cli
```

From this GitHub repo (works today):

```bash
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`](https://pypi.org/project/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

```bash
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**:

```bash
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:

```text
[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](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/resolving-a-merge-conflict-using-the-command-line) — 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](https://mergiraf.org/) — 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

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

## License

[MIT](LICENSE) © Ikrame Ih
