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.0.tar.gz (6.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.2.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for patch_package_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8a2dfa16179a4467db65d0db13c21596e41791f92a86b6ef8cbaa512b9fa8cc2
MD5 4fb7cdc1c9634c13b4087decd79f6a6f
BLAKE2b-256 dbcfeedba01e5322576bb53c2532675fb667582963ea470eb2c26456b9cda801

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for patch_package_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1aea86a54591626a9ea25877d3441891977569f4914ed64ff39cc6e0e7b17f38
MD5 fdaa42f7595babb9e0d48d21fbf65ff2
BLAKE2b-256 9b943a1e6b7660c4863f93773799e1e21abb0bd9921222e6928f7e6494348ee3

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