patch-fixer 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- patch_fixer/patch_fixer.py +3 -3
- {patch_fixer-0.2.2.dist-info → patch_fixer-0.2.3.dist-info}/METADATA +30 -10
- patch_fixer-0.2.3.dist-info/RECORD +7 -0
- patch_fixer-0.2.2.dist-info/RECORD +0 -7
- {patch_fixer-0.2.2.dist-info → patch_fixer-0.2.3.dist-info}/WHEEL +0 -0
- {patch_fixer-0.2.2.dist-info → patch_fixer-0.2.3.dist-info}/licenses/LICENSE +0 -0
- {patch_fixer-0.2.2.dist-info → patch_fixer-0.2.3.dist-info}/top_level.txt +0 -0
patch_fixer/patch_fixer.py
CHANGED
@@ -162,7 +162,7 @@ def fix_patch(patch_lines, original):
|
|
162
162
|
) = capture_hunk(current_hunk, original_lines, offset, last_hunk, hunk_context)
|
163
163
|
except MissingHunkError:
|
164
164
|
raise NotImplementedError(f"Could not find hunk in {current_file}:"
|
165
|
-
f"\n\n{"
|
165
|
+
f"\n\n{"".join(current_hunk)}")
|
166
166
|
fixed_lines.append(fixed_header)
|
167
167
|
fixed_lines.extend(current_hunk)
|
168
168
|
current_hunk = []
|
@@ -343,7 +343,7 @@ def fix_patch(patch_lines, original):
|
|
343
343
|
) = capture_hunk(current_hunk, original_lines, offset, last_hunk, hunk_context)
|
344
344
|
except MissingHunkError:
|
345
345
|
raise NotImplementedError(f"Could not find hunk in {current_file}:"
|
346
|
-
f"\n\n{"
|
346
|
+
f"\n\n{"".join(current_hunk)}")
|
347
347
|
fixed_lines.append(fixed_header)
|
348
348
|
fixed_lines.extend(current_hunk)
|
349
349
|
current_hunk = []
|
@@ -365,7 +365,7 @@ def fix_patch(patch_lines, original):
|
|
365
365
|
) = capture_hunk(current_hunk, original_lines, offset, last_hunk, hunk_context)
|
366
366
|
except MissingHunkError:
|
367
367
|
raise NotImplementedError(f"Could not find hunk in {current_file}:"
|
368
|
-
f"\n\n{"
|
368
|
+
f"\n\n{"".join(current_hunk)}")
|
369
369
|
fixed_lines.append(fixed_header)
|
370
370
|
fixed_lines.extend(current_hunk)
|
371
371
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: patch-fixer
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.3
|
4
4
|
Summary: Fixes erroneous git apply patches to the best of its ability.
|
5
5
|
Maintainer-email: Alex Mueller <amueller474@gmail.com>
|
6
6
|
License-Expression: Apache-2.0
|
@@ -30,27 +30,47 @@ Dynamic: license-file
|
|
30
30
|
So you asked an LLM to generate a code diff, tried to apply it with `git apply`, and got a bunch of malformed patch errors? Well fear no more, `patch_fixer.py` is here to save the day... more or less.
|
31
31
|
|
32
32
|
## Installation
|
33
|
-
```
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
```bash
|
34
|
+
# Make sure you're using at least python 3.10
|
35
|
+
python -m venv .venv/
|
36
|
+
source .venv/bin/activate
|
37
|
+
pip install patch-fixer
|
37
38
|
```
|
38
39
|
|
39
40
|
## Usage
|
41
|
+
### API:
|
42
|
+
```python
|
43
|
+
>>> from patch_fixer import fix_patch
|
44
|
+
>>>
|
45
|
+
>>> patch_file = "/path/to/broken.patch"
|
46
|
+
>>> original = "/path/to/original/state" # file or directory being patched
|
47
|
+
>>> with open(patch_file, encoding="utf-8") as f:
|
48
|
+
... patch_lines = f.readlines()
|
49
|
+
...
|
50
|
+
>>> fixed_lines = fix_patch(patch_lines, original)
|
51
|
+
>>> output_file = "/path/to/fixed.patch"
|
52
|
+
>>>
|
53
|
+
>>> with open(output_file, 'w', encoding='utf-8') as f:
|
54
|
+
... f.writelines(fixed_lines)
|
55
|
+
>>>
|
40
56
|
```
|
41
|
-
|
57
|
+
### Command line:
|
58
|
+
```bash
|
59
|
+
python patch_fixer/patch_fixer.py original broken.patch fixed.patch
|
42
60
|
```
|
43
61
|
where `original` is the file or directory you were trying to patch,
|
44
62
|
`broken.patch` is the malformed patch generated by the LLM,
|
45
63
|
and `fixed.patch` is the output file containing the (hopefully) fixed patch.
|
46
64
|
|
47
|
-
## Testing
|
48
|
-
|
49
|
-
|
65
|
+
## Local Testing
|
66
|
+
```bash
|
67
|
+
git clone https://github.com/ajcm474/patch-fixer.git
|
68
|
+
cd patch-fixer
|
50
69
|
pip install -e .[test]
|
51
70
|
pytest
|
52
71
|
```
|
53
|
-
Note that some
|
72
|
+
Note that some test failures are expected as this project is in the early alpha stage.
|
73
|
+
Please only report test failures if the same test passed in a previous version.
|
54
74
|
|
55
75
|
## License
|
56
76
|
|
@@ -0,0 +1,7 @@
|
|
1
|
+
patch_fixer/__init__.py,sha256=bSp2H7JW2kz1WrT0dqlg64kZpklKPp1FZlDhq2XJ2uU,34
|
2
|
+
patch_fixer/patch_fixer.py,sha256=zZ48yd9eVfCFiUzJ31wVpcEOBH2Nq711kC2c71q-YzM,17463
|
3
|
+
patch_fixer-0.2.3.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
4
|
+
patch_fixer-0.2.3.dist-info/METADATA,sha256=iAC5PmTsdyuTXnWPSvCjPVTD3nrEafqCyE8PrMxvuKs,2667
|
5
|
+
patch_fixer-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
patch_fixer-0.2.3.dist-info/top_level.txt,sha256=yyp3KjFgExJsrFsS9ZBCnkhb05xg8hPYhB7ncdpTOv0,12
|
7
|
+
patch_fixer-0.2.3.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
patch_fixer/__init__.py,sha256=bSp2H7JW2kz1WrT0dqlg64kZpklKPp1FZlDhq2XJ2uU,34
|
2
|
-
patch_fixer/patch_fixer.py,sha256=1Gf6LxQq3xhQVGeyD5W2-JKSJRgs9ty1C8F2QcEkyXQ,17469
|
3
|
-
patch_fixer-0.2.2.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
4
|
-
patch_fixer-0.2.2.dist-info/METADATA,sha256=VCH9g8_yHZfoPJrG9ZpYB0GPSPK8pG8NfeZZVuowsSs,2004
|
5
|
-
patch_fixer-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
patch_fixer-0.2.2.dist-info/top_level.txt,sha256=yyp3KjFgExJsrFsS9ZBCnkhb05xg8hPYhB7ncdpTOv0,12
|
7
|
-
patch_fixer-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|