Simple library for parsing unified diff.
Project description
Udiff
Udiff is a simple library for parsing unified diff.
>>> import udiff
>>> d = udiff.UdiffParser('diff --git a/sample b/sample\nindex 0000001..0ddf2ba\n--- a/sample\n+++ b/sample\n@@ -1 +1 @@\n-test\n+test1r\n')
>>> d.object
{'options': {'encoding': None, 'dst_prefix': None, 'src_prefix': None, 'diff_max_changes': None, 'diff_max_line_length': None, 'diff_too_big_message': None}, 'files': [{'deleted_lines': 1, 'added_lines': 1, 'is_git_diff': True, 'checksum_before': '0000001', 'checksum_after': '0ddf2ba', 'old_name': 'sample', 'language': '', 'new_name': 'sample', 'is_combined': False, 'blocks': [{'old_start_line': 1, 'old_start_line_2': None, 'new_start_line': 1, 'header': '@@ -1 +1 @@', 'lines': [{'source_line_no': 1, 'target_line_no': None, 'line_type': '-', 'content': '-test'}, {'source_line_no': None, 'target_line_no': 1, 'line_type': '+', 'content': '+test1r'}]}]}]}
>>> d.getitem('sample').added_lines
1
>>> d.getitem('sample').deleted_lines
1
Installing Requests and Supported Versions
Udiff is available on PyPI:
$ python -m pip install udiff
Udiff supports Python 2.7 & 3.5+.
Usage
Parse from file:
>>> from udiff import UdiffParser
>>> d = UdiffParser.from_filename(path_to_file)
Parse string:
>>> from udiff import UdiffParser
>>> with codecs.open(path_to_file, 'r', encoding='utf-8') as diff:
>>> d = UdiffParser.from_filename(diff.read())
Options:
src_prefix: add a prefix to all source (before changes) filepaths, default is''. Should match the prefix used when generating the diff.dst_prefix: add a prefix to all destination (after changes) filepaths, default is''. Should match the prefix used when generating the diffdiff_max_changes: number of changed lines after which a file diff is deemed as too big and not displayed, default isNonediff_max_line_length: number of characters in a diff line after which a file diff is deemed as too big and not displayed, default isNonediff_too_big_message: message for file diff too big, defaultDiff too big to be displayed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
udiff-0.1.0.tar.gz
(32.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
udiff-0.1.0-py2.py3-none-any.whl
(13.8 kB
view details)
File details
Details for the file udiff-0.1.0.tar.gz.
File metadata
- Download URL: udiff-0.1.0.tar.gz
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3366eebaaadbf7e56408fc6b4d6ed9f353dd7cf56cba6bd86f6eaabbf29d0e75
|
|
| MD5 |
a7ede898bbc2af4bbd07baea4d5e4822
|
|
| BLAKE2b-256 |
7cc753685dd3bce04d94b20e8ddd0522d84c476f3d43448a74efc7af7e8a1026
|
File details
Details for the file udiff-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: udiff-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48c9dc3d8ff43588fb204382b906ac3404e2a836605d1bd2a82cea3d0b2856b
|
|
| MD5 |
63f704931d509e88eaf33fe6bde2ffa4
|
|
| BLAKE2b-256 |
6903ecf5235ddef564340298d0f63f005587552bbf4725a9c960027f518c4a47
|