patchpy


Namepatchpy JSON
Version 2.0.4 PyPI version JSON
download
home_pageNone
SummaryA modern Python library for patch file parsing (diff file parsing)
upload_time2024-08-12 08:28:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PatchPy

*A modern Python library for patch file parsing (diff file parsing)*

PatchPy is a Python library for parsing and applying patch files.

```python
patch_file = PatchFile.from_path("example.patch")
patch_file.validate()
reversed_patch = patch_file.reversed()
reversed_patch.apply(root=".")
```

**Features:**

 - Parse unified and context diff formats
 - Apply/revert patches with optional path stripping
 - Fix line counts in hunk headers

## Installation

Install via [PyPI](https://pypi.org/project/patchpy/):

```sh
pip install patchpy
```

## Usage

### Library API

You can use PatchPy programmatically within your Python code. Here is a simple example:

```python
from patchpy import DiffFile

# Load a patch from a file
diff_file = DiffFile.from_path("example.patch")

# Validate the patch (ie. checks line counts in hunk headers)
diff_file.validate()

# Get attributes of the patch
print(diff_file.modifications[0].header)

# Reverse the patch and apply it
reversed_patch = diff_file.reversed()
reversed_patch.apply(root=".")
```

### CLI

The PatchPy CLI provides a simple interface for applying patches. Below is an example of how to use it:

```sh
# Apply a patch file
patchypy apply example.patch

# Apply a patch from a URL
patchypy apply https://example.com/patch.diff

# Display diffstat
patchypy diffstat example.patch

# Apply a patch with stripped leading path components
patchypy apply example.patch -p 1

# Transform a patch
patchypy transform --revert example.patch -o reversed.patch 

# Fix line counts in hunk headers in patch
patchpy transfform --fix-counts example.patch -o fixed.patch
```

## Development

PatchPy uses Rye for dependency management and development workflow. To get started with development, ensure you have [Rye](https://github.com/astral-sh/rye) installed and then clone the repository and set up the environment:

```sh
git clone https://github.com/MatthewScholefield/patchpy.git
cd patchpy
rye sync
rye run pre-commit install

# Run tests
rye test
```

Contributions are welcome! Feel free to open issues or submit pull requests.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "patchpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "\"Matthew D. Scholefield\" <matthew331199@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d3/e3/cdac841ab3268b3fec521c40111e9299d5bfd234ff76bcb99a5098ee190e/patchpy-2.0.4.tar.gz",
    "platform": null,
    "description": "# PatchPy\n\n*A modern Python library for patch file parsing (diff file parsing)*\n\nPatchPy is a Python library for parsing and applying patch files.\n\n```python\npatch_file = PatchFile.from_path(\"example.patch\")\npatch_file.validate()\nreversed_patch = patch_file.reversed()\nreversed_patch.apply(root=\".\")\n```\n\n**Features:**\n\n - Parse unified and context diff formats\n - Apply/revert patches with optional path stripping\n - Fix line counts in hunk headers\n\n## Installation\n\nInstall via [PyPI](https://pypi.org/project/patchpy/):\n\n```sh\npip install patchpy\n```\n\n## Usage\n\n### Library API\n\nYou can use PatchPy programmatically within your Python code. Here is a simple example:\n\n```python\nfrom patchpy import DiffFile\n\n# Load a patch from a file\ndiff_file = DiffFile.from_path(\"example.patch\")\n\n# Validate the patch (ie. checks line counts in hunk headers)\ndiff_file.validate()\n\n# Get attributes of the patch\nprint(diff_file.modifications[0].header)\n\n# Reverse the patch and apply it\nreversed_patch = diff_file.reversed()\nreversed_patch.apply(root=\".\")\n```\n\n### CLI\n\nThe PatchPy CLI provides a simple interface for applying patches. Below is an example of how to use it:\n\n```sh\n# Apply a patch file\npatchypy apply example.patch\n\n# Apply a patch from a URL\npatchypy apply https://example.com/patch.diff\n\n# Display diffstat\npatchypy diffstat example.patch\n\n# Apply a patch with stripped leading path components\npatchypy apply example.patch -p 1\n\n# Transform a patch\npatchypy transform --revert example.patch -o reversed.patch \n\n# Fix line counts in hunk headers in patch\npatchpy transfform --fix-counts example.patch -o fixed.patch\n```\n\n## Development\n\nPatchPy uses Rye for dependency management and development workflow. To get started with development, ensure you have [Rye](https://github.com/astral-sh/rye) installed and then clone the repository and set up the environment:\n\n```sh\ngit clone https://github.com/MatthewScholefield/patchpy.git\ncd patchpy\nrye sync\nrye run pre-commit install\n\n# Run tests\nrye test\n```\n\nContributions are welcome! Feel free to open issues or submit pull requests.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A modern Python library for patch file parsing (diff file parsing)",
    "version": "2.0.4",
    "project_urls": {
        "Homepage": "https://github.com/MatthewScholefield/patchpy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa339233df81238d7162dbbbe7efad6cf29c1d23da8dd40214b38ce8a5108b30",
                "md5": "293495ebf8545b0f8fa1d07014acaa38",
                "sha256": "5c03b5ee89385f598c0c1c5e262b47f57f48d48bfda51f827f4e8e3ebdbc57b3"
            },
            "downloads": -1,
            "filename": "patchpy-2.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "293495ebf8545b0f8fa1d07014acaa38",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6914,
            "upload_time": "2024-08-12T08:28:07",
            "upload_time_iso_8601": "2024-08-12T08:28:07.123481Z",
            "url": "https://files.pythonhosted.org/packages/fa/33/9233df81238d7162dbbbe7efad6cf29c1d23da8dd40214b38ce8a5108b30/patchpy-2.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3e3cdac841ab3268b3fec521c40111e9299d5bfd234ff76bcb99a5098ee190e",
                "md5": "e1973196e964564d3325322678c09965",
                "sha256": "abe93dbd8cf972b0ac063239407ed7cf7415a67b73ac85de3b8e7a772af37f82"
            },
            "downloads": -1,
            "filename": "patchpy-2.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "e1973196e964564d3325322678c09965",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8100,
            "upload_time": "2024-08-12T08:28:09",
            "upload_time_iso_8601": "2024-08-12T08:28:09.220477Z",
            "url": "https://files.pythonhosted.org/packages/d3/e3/cdac841ab3268b3fec521c40111e9299d5bfd234ff76bcb99a5098ee190e/patchpy-2.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-12 08:28:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MatthewScholefield",
    "github_project": "patchpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "patchpy"
}
        
Elapsed time: 0.68252s