Skip to main content

patch 3rd party Python packages

Project description

patch-package-py

A Python package patching tool that allows you to make and apply patches to third-party packages in your virtual environment.

Installation

uv add patch-package-py

Usage

The tool provides three main commands via the p12y CLI:

1. Create a patch workspace

p12y patch <package_name>

This command:

  • Resolves the package from an environment path
    • if omitted, it detects from the current directory (/.venv)
  • Creates a temporary virtual environment
  • Installs the same version of the package without dependencies
  • Sets up a git repository for tracking changes
  • Provides a path where you can edit the package files

Example:

p12y patch requests [-e <environment-path>]

2. Commit changes and create patch file

p12y commit <edit_path>

After editing the package files, use this command to:

  • Generate a git diff of your changes
  • Create a .patch file in the patches/ directory
  • Test that the patch can be applied successfully

Example:

p12y commit /tmp/patch-requests-2.28.1-abc123/venv/lib/python3.11/site-packages/requests

3. Apply patches

p12y apply [-e <environment-path>]

This command:

  • Looks for .patch files in the patches/ directory
  • Applies them to the packages in the environment path
    • if omitted, it detects from the current directory (/.venv)
  • Reports success/failure for each patch

Workflow

  1. Prepare for patching: Run p12y patch <package_name> to set up a workspace
  2. Make your changes: Edit the files in the provided path
  3. Create the patch: Run p12y commit <path> to generate the patch file
  4. Apply patches: Run p12y apply in your project to apply all patches

How it works

  • Uses uv for fast virtual environment creation and package installation
  • Leverages git for tracking changes and generating diffs
  • Stores patch files in a patches/ directory in your project root
  • Patch files are named using the format: <package-name>+<version>.patch

Using with poetry

  • detect the environment path using poetry show -v
  • use the -e / --env-path option for patch and/or apply.

Requirements

  • Python ≥ 3.9
  • uv package manager
  • git version control system
  • patch utility (typically pre-installed on Unix-like systems)
    • for windows you can install
      • using chocolatey: choco install patch
      • using winget winget install --id=GnuWin32.Patch -e
      • or it might be packed with cygwin.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

patch_package_py-0.1.4.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

patch_package_py-0.1.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file patch_package_py-0.1.4.tar.gz.

File metadata

  • Download URL: patch_package_py-0.1.4.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.15

File hashes

Hashes for patch_package_py-0.1.4.tar.gz
Algorithm Hash digest
SHA256 32b1d9e8d926a211ecce3912fd11ab395bb6d45e226d59b291bf1b158576b51b
MD5 cdd1ddf79561cda10b53edde500efb39
BLAKE2b-256 9796d0e81d5e2f666f4fe87f29043ac5355ecf59d50bfef8317a677f678b5172

See more details on using hashes here.

File details

Details for the file patch_package_py-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for patch_package_py-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0404949f50e0a17c611c4674d995c8f82581571ab7915db133a40bb7febcd71f
MD5 b0f36b7191cb3ebcf0d4e17c092bdbf0
BLAKE2b-256 35cdc5826d641b66b4fe06a35d85472cd32f4514a344b8cc50a5715410b838e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page