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

Agent skill

This repository includes an agent skill for AI agents that support agent skills.

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> [--skip-restore]

After editing the package files, use this command to:

  • Generate a git diff of your changes
  • Create a .patch file in the patches/ directory
  • Reinstall the original package in the target environment
  • Apply the new patch to the target environment

Example:

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

Use --skip-restore to write the patch file and apply it to the current target environment directly.

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
  • Reinstalls the target package during commit before applying the newly generated patch
  • 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 env info --path.
  • Use the -e / --env-path option for patch and apply.
  • commit reuses the environment path recorded by patch -e.
p12y patch requests -e "$(poetry env info --path)"
p12y commit <edit_path>
p12y apply -e "$(poetry env info --path)"

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.2.1.tar.gz (6.6 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.2.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: patch_package_py-0.2.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for patch_package_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a5addd8c4c897bf7795496f3148d4470f84a4abbebdcab06cea2213a4303de67
MD5 aee219931e2f0278dd1402f3216c2174
BLAKE2b-256 ce6c1a15f563b8506b5fe4edbcd70836d4c481704518aeb5bc5c79602656083e

See more details on using hashes here.

Provenance

The following attestation bundles were made for patch_package_py-0.2.1.tar.gz:

Publisher: publish.yml on nomyfan/patch-package-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for patch_package_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 135054c5eb112377c67adcbd7e4502007c24a94d2cd98b5a6fa119fe60ae693e
MD5 8e8f302b91664d4bca62399bab1adb65
BLAKE2b-256 876c8cd23d431ee1a3ccbfa2ac9ced565c9df1b91fe51119b1b008e6588131ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for patch_package_py-0.2.1-py3-none-any.whl:

Publisher: publish.yml on nomyfan/patch-package-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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