PyDiffChecker
Wrappers for git diff
LineShiftChecker
This tool provides an API for checking shifted but not modified lines in changed files of a Git diff. The tool will collect the lines where the content did not change into dict-like objects with source->destination line number mapping per changed file. File renames are detected as well.
The behavior is very similar to unified diff on Github or output of git-diffn. There are green (added), red (remove) and white (unmodified) lines. The return value of the API will contain these "white" lines with the source/destination line number for the whole file.
Example
Let's assume this is the output of git-diffn:
diff --git a/pydiffchecker/helper.py b/pydiffchecker/helper.py
index f9d4e08..6a6c214 100644
--- a/pydiffchecker/helper.py
+++ b/pydiffchecker/helper.py
@@ -3,14 +3,13 @@ from typing import Iterator
3, 3:
4, 4:
5, 5: def subprocess_readlines(cmd, cwd=None) -> Iterator[str]:
- 6 :- process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE)
+ 6:+ process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, text=True)
7, 7:
8, 8: for line in process.stdout:
- 9 :- line = line.decode().rstrip(r'\n')
- 10 :-
+ 9:+ line = line.rstrip('\n')
11, 10: yield line
12, 11:
- 13 :- process.wait()
+ 12:+ process.communicate()
14, 13:
15, 14: if process.returncode != 0:
16, 15: raise subprocess.CalledProcessError(process.returncode, cmd)
Here the lines 3-5, 7-8, 11-12 and 14-16 are unmodified, but some of them are shifted. Of course, "white" lines that are not shown above are also unmodified. The API fill return the following data (visualized for simplicity, see Usage how to access the data programatically):
* pydiffchecker/helper.py->pydiffchecker/helper.py:
1->1
2->2
3->3
4->4
5->5
6->None
7->7
8->8
9->None
10->None
11->10
12->11
13->None
14->13
15->14
16->15
Usage
from pydiffchecker.line_shift_checker import LineShiftChecker
line_shift_checker = LineShiftChecker('HEAD~', 'HEAD')
all_shifted_lines = line_shift_checker.get_all_shifted_lines()
# Iterate through shifted lines
for src_path, shifted_lines in all_shifted_lines.items():
renamed_to = shifted_lines.dst_path
for src_line_index, dst_line_index in shifted_lines:
print(f'{src_line_index}->{dst_line_index}')
# Find if lines are shifted (and to where) in a file
if 'your/file.cpp' in all_shifted_lines:
shifted_lines = all_shifted_lines['your/file.cpp']
renamed_to = shifted_lines.dst_path
if 12 in shifted_lines:
# line 12 was shifted, to where?
shifted_to = shifted_lines[12]
Metadata
Release files for pydiffchecker 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydiffchecker-0.1.6.tar.gz | 16.8 kB | Without provenance | Details for pydiffchecker-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydiffchecker-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for pydiffchecker-0.1.6-py3-none-any.whl |
Total release size: 35.0 kB
Release files / pydiffchecker-0.1.6.tar.gz
| Download URL | pydiffchecker-0.1.6.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9205c41cf5be9c63c4e0bd65ef0309abbd4f2c3371353108ce69cfe08680fb9
|
|
BLAKE2b-256 checksum How to use checksums |
8568835db25741b3b61dc5339d2b61a70d0197685f450daca6e0035a9b9aaa74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / pydiffchecker-0.1.6-py3-none-any.whl
| Download URL | pydiffchecker-0.1.6-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ebb8cc26928261ffa3b8c2eb91348ce912f031d5486cabca879efc1cb782804
|
|
BLAKE2b-256 checksum How to use checksums |
45847be3b37ef985527e828810e8072379cf7454ea4418a57b30f9307e40c1bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for pydiffchecker 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.