ShortDiff
This is a Python implementation of a diff algorithm. It aims at producing one-way as-short-as-possible patch to go from a file to another. This is useful to keep track of modifications in a text file without keeping a copy of each state (this is the easy part of version control). This produce shorter patch than any output from the GNU diff tool. Since it is one-way only, the patch to go from A to B does not permit to to go from B to A.
Disclaimer
This algorithm have a time complexity of O(N*M) (where N and M are the number of line of each file) and is implemented in pure python. There performances are not great. You should probably not use it in any serious project. I wrote it for educational purpose and I use it in a really small scale project.
Still for educational project there are more naive version in the archive directory. The final module is a refinment of these.
Installation
Use pip to install it or copy this directory in a relevant place if you know what you are doing.
pip install ShortDiff
Usage
CLI
Create a patch
python -m ShortDiff diff FILA_A [FILE_B]
Create the patch to go from A to B. If FILE_B is ommited, its content is expected from the standard input. Output the patch to standard output.
Apply a patch
python -m ShortDiff patch PATCH [FILE]
Apply PATCH to FILE. If FILE is ommited, apply patch to standard input. Result is printed to standard output.
API
Functions can be imported from the module to be used in other apps. Useful functions include:
-
differ(old, new): (low level) take to arbitrary sequences and return the Levenstein distance and the path from one to another as a sequence of pairs (position in old, position in new). If the position in old is the same in two consecutive pair, it correspond to an insertion. If the position in new is the same in two consecutive pair, it correspond to a deletion. Else it correspond to an unmodified chunk. Path is made so to consecutive operations cannot be of the same kind (a deletion cannot be immediatly followed by another deletion). -
get_chunks(old_txt, new_txt): (high level) generator taking two strings and compute the live diff. It yields 4 elements tuples(kind, start, stop, content).kindis one of'd'(deletion)'i'(insertion) and'k'(keep/unmodified).startandstopare the line number boundaries of the chunk concerned by the operations inold_txtfor deletion and keep and innew_txtfor insertion.contentis the list of lines of the chunk. -
create_patch(old_txt, new_txt): (high level) return the patch as printed by the CLI -
apply_patch(old_txt, patch): (high level) return the result of applyingpatchtoold_txt
Metadata
Release files for ShortDiff 0.1.3
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 |
|---|---|---|---|---|
| ShortDiff-0.1.3.tar.gz | 4.6 kB | Without provenance | Details for ShortDiff-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ShortDiff-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for ShortDiff-0.1.3-py3-none-any.whl |
Total release size: 10.7 kB
Release files / ShortDiff-0.1.3.tar.gz
| Download URL | ShortDiff-0.1.3.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae548193dafe0a4200bd9baf959c88f99f06b64ea68837c32bcab3feab409718
|
|
BLAKE2b-256 checksum How to use checksums |
ec5077f9c607201f6158829fda1cee65b47da255567281627bf10758bb56a572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.4
|
Release files / ShortDiff-0.1.3-py3-none-any.whl
| Download URL | ShortDiff-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c9c12cf44a5ea4ac9535ece4fdc7d7c5938e7d58ea347b1a4b9cef251cd3c7b
|
|
BLAKE2b-256 checksum How to use checksums |
de3653fec31d5ecb9f73a9b8fcf962fb46040744c2198c2da28a0e1dac033052
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.4
|
Security for ShortDiff 0.1.3
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.