cdifflib


Namecdifflib JSON
Version 1.2.8 PyPI version JSON
download
home_pageNone
SummaryC implementation of parts of difflib
upload_time2025-01-13 11:09:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.4
licenseCopyright (c) 2013, Matthew Duggan All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the {organization} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords difflib c diff
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            cdifflib
========
  [<img src="https://travis-ci.org/mduggan/cdifflib.svg?branch=master">](https://travis-ci.org/mduggan/cdifflib/)

Python [difflib](http://docs.python.org/2/library/difflib.html) sequence
matcher reimplemented in C.

Actually only contains reimplemented parts.  Creates a `CSequenceMatcher` type
which inherets most functions from `difflib.SequenceMatcher`.

`cdifflib` is about 4x the speed of the pure python `difflib` when diffing
large streams.

Limitations
-----------
The C part of the code can only work on `list` rather than generic iterables,
so anything that isn't a `list` will be converted to `list` in the
`CSequenceMatcher` constructor.  This may cause undesirable behavior if you're
not expecting it.

Works with Python 2.7 and 3.6 (Should work on all 3.3+)

Usage
-----
Can be used just like the `difflib.SequenceMatcher` as long as you pass lists.  These examples are right out of the [difflib docs](http://docs.python.org/2/library/difflib.html):
```Python
>>> from cdifflib import CSequenceMatcher
>>> s = CSequenceMatcher(None, ' abcd', 'abcd abcd')
>>> s.find_longest_match(0, 5, 0, 9)
Match(a=1, b=0, size=4)
>>> s = CSequenceMatcher(lambda x: x == " ",
...                      "private Thread currentThread;",
...                      "private volatile Thread currentThread;")
>>> print round(s.ratio(), 3)
0.866
```

It's completely compatible, so you can replace the difflib version on startup
and then other libraries will use CSequenceMatcher too, eg:
```Python
from cdifflib import CSequenceMatcher
import difflib
difflib.SequenceMatcher = CSequenceMatcher
import library_that_uses_difflib

# Now the library will transparantely be using the C SequenceMatcher - other
# things remain the same
library_that_uses_difflib.do_some_diffing()
```


Making
------
Set up a venv:
```
python -m venv .venv
source .venv/bin/activate
```

To install:
```
python -m build
```

To test:
```
python -m pytest tests/cdifflib_tests.py
```

License etc
-----------
This code lives at https://github.com/mduggan.  See LICENSE for the license.


Changelog
---------
* 1.2.8 - Bump to fix version number in py file
* 1.2.7 - Update for newer pythons
* 1.2.6 - Clear state correctly when replacing seq1 (#10)
* 1.2.5 - Fix some memory leaks (#7)
* 1.2.4 - Repackage yet again using twine for pypi upload (no binary changes)
* 1.2.3 - Repackage again with changelog update and corrected src package (no binary changes)
* 1.2.2 - Repackage to add README.md in a way pypi supports (no binary changes)
* 1.2.1 - Fix bug for longer sequences with "autojunk"
* 1.2.0 - Python 3 support for other versions
* 1.1.0 - Added Python 3.6 support (thanks Bclavie)
* 1.0.4 - Changes to make it compile on MSVC++ compiler, no change for other platforms
* 1.0.2 - Bugfix - also replace set_seq1 implementation so `difflib.compare` works with a `CSequenceMatcher`
* 1.0.1 - Implement more bits in c to squeeze a bit more speed out
* 1.0.0 - First release

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cdifflib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.4",
    "maintainer_email": null,
    "keywords": "difflib, c, diff",
    "author": null,
    "author_email": "Matthew Duggan <mgithub@guarana.org>",
    "download_url": "https://files.pythonhosted.org/packages/b3/3a/12dbc22cb2d4d8438e6e963d6dc86b470ba82823cf2e48a26769f3db68be/cdifflib-1.2.8.tar.gz",
    "platform": null,
    "description": "cdifflib\n========\n  [<img src=\"https://travis-ci.org/mduggan/cdifflib.svg?branch=master\">](https://travis-ci.org/mduggan/cdifflib/)\n\nPython [difflib](http://docs.python.org/2/library/difflib.html) sequence\nmatcher reimplemented in C.\n\nActually only contains reimplemented parts.  Creates a `CSequenceMatcher` type\nwhich inherets most functions from `difflib.SequenceMatcher`.\n\n`cdifflib` is about 4x the speed of the pure python `difflib` when diffing\nlarge streams.\n\nLimitations\n-----------\nThe C part of the code can only work on `list` rather than generic iterables,\nso anything that isn't a `list` will be converted to `list` in the\n`CSequenceMatcher` constructor.  This may cause undesirable behavior if you're\nnot expecting it.\n\nWorks with Python 2.7 and 3.6 (Should work on all 3.3+)\n\nUsage\n-----\nCan be used just like the `difflib.SequenceMatcher` as long as you pass lists.  These examples are right out of the [difflib docs](http://docs.python.org/2/library/difflib.html):\n```Python\n>>> from cdifflib import CSequenceMatcher\n>>> s = CSequenceMatcher(None, ' abcd', 'abcd abcd')\n>>> s.find_longest_match(0, 5, 0, 9)\nMatch(a=1, b=0, size=4)\n>>> s = CSequenceMatcher(lambda x: x == \" \",\n...                      \"private Thread currentThread;\",\n...                      \"private volatile Thread currentThread;\")\n>>> print round(s.ratio(), 3)\n0.866\n```\n\nIt's completely compatible, so you can replace the difflib version on startup\nand then other libraries will use CSequenceMatcher too, eg:\n```Python\nfrom cdifflib import CSequenceMatcher\nimport difflib\ndifflib.SequenceMatcher = CSequenceMatcher\nimport library_that_uses_difflib\n\n# Now the library will transparantely be using the C SequenceMatcher - other\n# things remain the same\nlibrary_that_uses_difflib.do_some_diffing()\n```\n\n\nMaking\n------\nSet up a venv:\n```\npython -m venv .venv\nsource .venv/bin/activate\n```\n\nTo install:\n```\npython -m build\n```\n\nTo test:\n```\npython -m pytest tests/cdifflib_tests.py\n```\n\nLicense etc\n-----------\nThis code lives at https://github.com/mduggan.  See LICENSE for the license.\n\n\nChangelog\n---------\n* 1.2.8 - Bump to fix version number in py file\n* 1.2.7 - Update for newer pythons\n* 1.2.6 - Clear state correctly when replacing seq1 (#10)\n* 1.2.5 - Fix some memory leaks (#7)\n* 1.2.4 - Repackage yet again using twine for pypi upload (no binary changes)\n* 1.2.3 - Repackage again with changelog update and corrected src package (no binary changes)\n* 1.2.2 - Repackage to add README.md in a way pypi supports (no binary changes)\n* 1.2.1 - Fix bug for longer sequences with \"autojunk\"\n* 1.2.0 - Python 3 support for other versions\n* 1.1.0 - Added Python 3.6 support (thanks Bclavie)\n* 1.0.4 - Changes to make it compile on MSVC++ compiler, no change for other platforms\n* 1.0.2 - Bugfix - also replace set_seq1 implementation so `difflib.compare` works with a `CSequenceMatcher`\n* 1.0.1 - Implement more bits in c to squeeze a bit more speed out\n* 1.0.0 - First release\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2013, Matthew Duggan All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of the {organization} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "C implementation of parts of difflib",
    "version": "1.2.8",
    "project_urls": {
        "Bug Tracker": "https://github.com/mduggan/cdifflib/issues",
        "Homepage": "https://github.com/mduggan/cdifflib"
    },
    "split_keywords": [
        "difflib",
        " c",
        " diff"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f842490a890c822a89d4a674ef1f5a49ac8327a8b17ecb361026990dcbd8e97a",
                "md5": "35e822a9a1ad2ba6958132a24830a5b6",
                "sha256": "bfd1b3d6d0415c05a2734118a7467f2acae3d0f8e382d5220cd49ca0b6c18b44"
            },
            "downloads": -1,
            "filename": "cdifflib-1.2.8-cp310-cp310-macosx_15_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "35e822a9a1ad2ba6958132a24830a5b6",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.4",
            "size": 9843,
            "upload_time": "2025-01-13T11:08:53",
            "upload_time_iso_8601": "2025-01-13T11:08:53.277497Z",
            "url": "https://files.pythonhosted.org/packages/f8/42/490a890c822a89d4a674ef1f5a49ac8327a8b17ecb361026990dcbd8e97a/cdifflib-1.2.8-cp310-cp310-macosx_15_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83ad9176a618be389503f29cf86977399b19c5e59d95064f20512da18acf3287",
                "md5": "f228a9f56620ae520ca89c8df094a212",
                "sha256": "2987db5b484e5fc37ab874ad81bcb992dd362e4278a5b3e2f7b6db4f4465a2c1"
            },
            "downloads": -1,
            "filename": "cdifflib-1.2.8-cp311-cp311-macosx_15_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "f228a9f56620ae520ca89c8df094a212",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.4",
            "size": 9843,
            "upload_time": "2025-01-13T11:08:55",
            "upload_time_iso_8601": "2025-01-13T11:08:55.760163Z",
            "url": "https://files.pythonhosted.org/packages/83/ad/9176a618be389503f29cf86977399b19c5e59d95064f20512da18acf3287/cdifflib-1.2.8-cp311-cp311-macosx_15_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e00a478ecb528985cb942b51d096a5bfc3896ffe5bef740e09153b21ec9877b5",
                "md5": "6071639324f2377738d61ced199c1769",
                "sha256": "1605aa5cd46ada5d03148a08010ff2e59788a7df9480dd66794ba71e69625d36"
            },
            "downloads": -1,
            "filename": "cdifflib-1.2.8-cp312-cp312-macosx_15_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "6071639324f2377738d61ced199c1769",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.4",
            "size": 9836,
            "upload_time": "2025-01-13T11:08:58",
            "upload_time_iso_8601": "2025-01-13T11:08:58.109453Z",
            "url": "https://files.pythonhosted.org/packages/e0/0a/478ecb528985cb942b51d096a5bfc3896ffe5bef740e09153b21ec9877b5/cdifflib-1.2.8-cp312-cp312-macosx_15_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0835c3b9e4b5eb519f19b0870dc216065e50c1f62c385c01e99e6ac6ba85e500",
                "md5": "c95836feaf5e4b3b02cb15a8f881b72c",
                "sha256": "721969bb055641ae7598056f121fe487bc2768a47f1e5e80c81c4342bcc2c3f8"
            },
            "downloads": -1,
            "filename": "cdifflib-1.2.8-cp313-cp313-macosx_15_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "c95836feaf5e4b3b02cb15a8f881b72c",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": ">=3.4",
            "size": 9844,
            "upload_time": "2025-01-13T11:09:02",
            "upload_time_iso_8601": "2025-01-13T11:09:02.723825Z",
            "url": "https://files.pythonhosted.org/packages/08/35/c3b9e4b5eb519f19b0870dc216065e50c1f62c385c01e99e6ac6ba85e500/cdifflib-1.2.8-cp313-cp313-macosx_15_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be5f7a4ea8a3507a5a69cbb6a89b60a2dea8f8ad14640b5d5e75da3c4222c662",
                "md5": "6a6d4507fb7a4890deafe8562c7b8579",
                "sha256": "9713b02c328773a2794eaba96b278393a359ba433169f8b5f4bd49ceade4f43b"
            },
            "downloads": -1,
            "filename": "cdifflib-1.2.8-cp39-cp39-macosx_15_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "6a6d4507fb7a4890deafe8562c7b8579",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.4",
            "size": 9840,
            "upload_time": "2025-01-13T11:09:04",
            "upload_time_iso_8601": "2025-01-13T11:09:04.261773Z",
            "url": "https://files.pythonhosted.org/packages/be/5f/7a4ea8a3507a5a69cbb6a89b60a2dea8f8ad14640b5d5e75da3c4222c662/cdifflib-1.2.8-cp39-cp39-macosx_15_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b33a12dbc22cb2d4d8438e6e963d6dc86b470ba82823cf2e48a26769f3db68be",
                "md5": "8b4496ac89ed5096adf0f74e31619c37",
                "sha256": "3235ea10b532c1fc830253c499525ce23355ee52606047f7f94a9da9e4d5749d"
            },
            "downloads": -1,
            "filename": "cdifflib-1.2.8.tar.gz",
            "has_sig": false,
            "md5_digest": "8b4496ac89ed5096adf0f74e31619c37",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.4",
            "size": 11011,
            "upload_time": "2025-01-13T11:09:06",
            "upload_time_iso_8601": "2025-01-13T11:09:06.720631Z",
            "url": "https://files.pythonhosted.org/packages/b3/3a/12dbc22cb2d4d8438e6e963d6dc86b470ba82823cf2e48a26769f3db68be/cdifflib-1.2.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-13 11:09:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mduggan",
    "github_project": "cdifflib",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cdifflib"
}
        
Elapsed time: 1.32683s