Library to parse and apply unified diffs.
- Python 3 compatible # EOL initiated here
- Automatic correction of
- Linefeeds according to patched file
- Diffs broken by stripping trailing whitespace
- a/ and b/ prefixes
- No dependencies outside Python stdlib
- Patch format detection (SVN, HG, GIT)
- Nice diffstat histogram
- Linux / Windows / OS X
- Test coverage
Things that don't work out of the box:
- File renaming, creation and removal
- Directory tree operations (Partly*)
- Version control specific properties
- Non-unified diff formats
- You can use it to patch files in directory with same name of patched ones and add files ("--- /dev/null")
Install and run it with Python. Example:
python3 -m patcher diff.patchor
patcher diff.patchFor more instructions, run
python3 -m patcher --helpYou can install from this repository:
pip install https://github.com/Kovalit31/python-patchAfter (may be) it will be on PyPI
patch.fromfile(file) - Load patch from file patch.fromstring(string) - Load patch from string patch.ffromuri(uri) - Load patch from uri (need for active internet)
For example:
pt = patcher.fromfile("mydiff.patch")
pt.apply()