| Name | unidiff2 JSON |
| Version |
0.7.8
JSON |
| download |
| home_page | None |
| Summary | Unified diff parsing/metadata extraction library. |
| upload_time | 2025-10-30 11:15:54 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.7 |
| license | MIT |
| keywords |
unified
diff
parse
metadata
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
|
| coveralls test coverage |
No coveralls.
|
Unidiff
=======
Simple Python library to parse and interact with unified diff data.
The original version seems not to be actively maintained.
This repository intend to offer an actively maintained version of unidiff.
Installing unidiff
------------------
::
$ pip install unidiff2
Quick start
-----------
.. code-block:: python
>>> import urllib.request
>>> from unidiff import PatchSet
>>> diff = urllib.request.urlopen('https://github.com/matiasb/python-unidiff/pull/3.diff')
>>> encoding = diff.headers.get_charsets()[0]
>>> patch = PatchSet(diff, encoding=encoding)
>>> patch
<PatchSet: [<PatchedFile: .gitignore>, <PatchedFile: unidiff/patch.py>, <PatchedFile: unidiff/utils.py>]>
>>> patch[0]
<PatchedFile: .gitignore>
>>> patch[0].is_added_file
True
>>> patch[0].added
6
>>> patch[1]
<PatchedFile: unidiff/patch.py>
>>> patch[1].added, patch[1].removed
(20, 11)
>>> len(patch[1])
6
>>> patch[1][2]
<Hunk: @@ 109,14 110,21 @@ def __repr__(self):>
>>> patch[2]
<PatchedFile: unidiff/utils.py>
>>> print(patch[2])
diff --git a/unidiff/utils.py b/unidiff/utils.py
index eae63e6..29c896a 100644
--- a/unidiff/utils.py
+++ b/unidiff/utils.py
@@ -37,4 +37,3 @@
# - deleted line
# \ No newline case (ignore)
RE_HUNK_BODY_LINE = re.compile(r'^([- \+\\])')
-
Load unified diff data by instantiating :code:`PatchSet` with a file-like object as
argument, or using :code:`PatchSet.from_filename` class method to read diff from file.
A :code:`PatchSet` is a list of files updated by the given patch. For each :code:`PatchedFile`
you can get stats (if it is a new, removed or modified file; the source/target
lines; etc), besides having access to each hunk (also like a list) and its
respective info.
At any point you can get the string representation of the current object, and
that will return the unified diff data of it.
As a quick example of what can be done, check bin/unidiff file.
Also, once installed, unidiff provides a command-line program that displays
information from diff data (a file, or stdin). For example:
::
$ git diff | unidiff
Summary
-------
README.md: +6 additions, -0 deletions
1 modified file(s), 0 added file(s), 0 removed file(s)
Total: 6 addition(s), 0 deletion(s)
Load a local diff file
----------------------
To instantiate :code:`PatchSet` from a local file, you can use:
.. code-block:: python
>>> from unidiff import PatchSet
>>> patch = PatchSet.from_filename('tests/samples/bzr.diff', encoding='utf-8')
>>> patch
<PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>
Notice the (optional) :code:`encoding` parameter. If not specified, unicode input will be expected. Or alternatively:
.. code-block:: python
>>> import codecs
>>> from unidiff import PatchSet
>>> with codecs.open('tests/samples/bzr.diff', 'r', encoding='utf-8') as diff:
... patch = PatchSet(diff)
...
>>> patch
<PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>
Finally, you can also instantiate :code:`PatchSet` passing any iterable (and encoding, if needed):
.. code-block:: python
>>> from unidiff import PatchSet
>>> with open('tests/samples/bzr.diff', 'r') as diff:
... data = diff.readlines()
...
>>> patch = PatchSet(data)
>>> patch
<PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>
If you don't need to be able to rebuild the original unified diff input, you can pass
:code:`metadata_only=True` (defaults to :code:`False`), which should help making the
parsing more efficient:
.. code-block:: python
>>> from unidiff import PatchSet
>>> patch = PatchSet.from_filename('tests/samples/bzr.diff', encoding='utf-8', metadata_only=True)
References
----------
* https://en.wikipedia.org/wiki/Diff_utility
* https://www.artima.com/weblogs/viewpost.jsp?thread=164293
Raw data
{
"_id": null,
"home_page": null,
"name": "unidiff2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "Jef Roelandt <roelandt.jef@plaws.fr>",
"keywords": "unified, diff, parse, metadata",
"author": null,
"author_email": "Matias Bordese <mbordese@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/49/d2/d26bbf825d8d9e0386c0c980cc10435861b5a31ec4f3683d060db0ad85b0/unidiff2-0.7.8.tar.gz",
"platform": null,
"description": "Unidiff\n=======\n\nSimple Python library to parse and interact with unified diff data.\n\nThe original version seems not to be actively maintained.\nThis repository intend to offer an actively maintained version of unidiff.\n\n\nInstalling unidiff\n------------------\n\n::\n\n $ pip install unidiff2\n\n\nQuick start\n-----------\n\n.. code-block:: python\n\n >>> import urllib.request\n >>> from unidiff import PatchSet\n >>> diff = urllib.request.urlopen('https://github.com/matiasb/python-unidiff/pull/3.diff')\n >>> encoding = diff.headers.get_charsets()[0]\n >>> patch = PatchSet(diff, encoding=encoding)\n >>> patch\n <PatchSet: [<PatchedFile: .gitignore>, <PatchedFile: unidiff/patch.py>, <PatchedFile: unidiff/utils.py>]>\n >>> patch[0]\n <PatchedFile: .gitignore>\n >>> patch[0].is_added_file\n True\n >>> patch[0].added\n 6\n >>> patch[1]\n <PatchedFile: unidiff/patch.py>\n >>> patch[1].added, patch[1].removed\n (20, 11)\n >>> len(patch[1])\n 6\n >>> patch[1][2]\n <Hunk: @@ 109,14 110,21 @@ def __repr__(self):>\n >>> patch[2]\n <PatchedFile: unidiff/utils.py>\n >>> print(patch[2])\n diff --git a/unidiff/utils.py b/unidiff/utils.py\n index eae63e6..29c896a 100644\n --- a/unidiff/utils.py\n +++ b/unidiff/utils.py\n @@ -37,4 +37,3 @@\n # - deleted line\n # \\ No newline case (ignore)\n RE_HUNK_BODY_LINE = re.compile(r'^([- \\+\\\\])')\n -\n\n\nLoad unified diff data by instantiating :code:`PatchSet` with a file-like object as\nargument, or using :code:`PatchSet.from_filename` class method to read diff from file.\n\nA :code:`PatchSet` is a list of files updated by the given patch. For each :code:`PatchedFile`\nyou can get stats (if it is a new, removed or modified file; the source/target\nlines; etc), besides having access to each hunk (also like a list) and its\nrespective info.\n\nAt any point you can get the string representation of the current object, and\nthat will return the unified diff data of it.\n\nAs a quick example of what can be done, check bin/unidiff file.\n\nAlso, once installed, unidiff provides a command-line program that displays\ninformation from diff data (a file, or stdin). For example:\n\n::\n\n $ git diff | unidiff\n Summary\n -------\n README.md: +6 additions, -0 deletions\n\n 1 modified file(s), 0 added file(s), 0 removed file(s)\n Total: 6 addition(s), 0 deletion(s)\n\n\nLoad a local diff file\n----------------------\n\nTo instantiate :code:`PatchSet` from a local file, you can use:\n\n.. code-block:: python\n\n >>> from unidiff import PatchSet\n >>> patch = PatchSet.from_filename('tests/samples/bzr.diff', encoding='utf-8')\n >>> patch\n <PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>\n\nNotice the (optional) :code:`encoding` parameter. If not specified, unicode input will be expected. Or alternatively:\n\n.. code-block:: python\n\n >>> import codecs\n >>> from unidiff import PatchSet\n >>> with codecs.open('tests/samples/bzr.diff', 'r', encoding='utf-8') as diff:\n ... patch = PatchSet(diff)\n ...\n >>> patch\n <PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>\n\nFinally, you can also instantiate :code:`PatchSet` passing any iterable (and encoding, if needed):\n\n.. code-block:: python\n\n >>> from unidiff import PatchSet\n >>> with open('tests/samples/bzr.diff', 'r') as diff:\n ... data = diff.readlines()\n ...\n >>> patch = PatchSet(data)\n >>> patch\n <PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>\n\nIf you don't need to be able to rebuild the original unified diff input, you can pass\n:code:`metadata_only=True` (defaults to :code:`False`), which should help making the\nparsing more efficient:\n\n.. code-block:: python\n\n >>> from unidiff import PatchSet\n >>> patch = PatchSet.from_filename('tests/samples/bzr.diff', encoding='utf-8', metadata_only=True)\n\n\nReferences\n----------\n\n* https://en.wikipedia.org/wiki/Diff_utility\n* https://www.artima.com/weblogs/viewpost.jsp?thread=164293\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Unified diff parsing/metadata extraction library.",
"version": "0.7.8",
"project_urls": {
"Homepage": "https://github.com/SuperMeepEnby/python-unidiff2"
},
"split_keywords": [
"unified",
" diff",
" parse",
" metadata"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6e45a6234f5d515eacb2d8d37225264565992a8a916bbe4d127e8b41279c53d4",
"md5": "4b3747a87f1063d36b59010b3425818c",
"sha256": "79e982c799a6604df6c0da2d75bf3693f250bed0d8ed2170f2ab8a7d49835aad"
},
"downloads": -1,
"filename": "unidiff2-0.7.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4b3747a87f1063d36b59010b3425818c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 13900,
"upload_time": "2025-10-30T11:15:53",
"upload_time_iso_8601": "2025-10-30T11:15:53.067551Z",
"url": "https://files.pythonhosted.org/packages/6e/45/a6234f5d515eacb2d8d37225264565992a8a916bbe4d127e8b41279c53d4/unidiff2-0.7.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "49d2d26bbf825d8d9e0386c0c980cc10435861b5a31ec4f3683d060db0ad85b0",
"md5": "cb0d17952270baed330483a469354929",
"sha256": "40865c1037f4d27475d9149ebf2dc2ef1e11d62bf159ab127186ed26d3d61c44"
},
"downloads": -1,
"filename": "unidiff2-0.7.8.tar.gz",
"has_sig": false,
"md5_digest": "cb0d17952270baed330483a469354929",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 22181,
"upload_time": "2025-10-30T11:15:54",
"upload_time_iso_8601": "2025-10-30T11:15:54.477945Z",
"url": "https://files.pythonhosted.org/packages/49/d2/d26bbf825d8d9e0386c0c980cc10435861b5a31ec4f3683d060db0ad85b0/unidiff2-0.7.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-30 11:15:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SuperMeepEnby",
"github_project": "python-unidiff2",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"lcname": "unidiff2"
}