Skip to main content

venv-patcher

Apply and track patches to packages installed in a Python virtual environment.

venv-patcher records the pristine state of every package it touches as a git commit, applies your patches on top as further deterministic commits, and keeps a manifest (in the venv's site-packages) of everything it has done - so you can list or fully revert your patches at any time.

Install

pip install venv-patcher

Or straight from git:

pip install git+https://github.com/thorsten-klein/venv-patcher.git

venv-patcher refuses to run outside of an active virtual environment.

Usage

venv-patcher apply -f patches.yml [-f <file> ...] [-p <package> ...] [--skip-missing] [--force]
venv-patcher list
venv-patcher reset [-p <package> ...]

apply

Use -p/--package one or more times to only apply the patches that target those packages, skipping every other entry in the given yaml file(s).

For each patch entry, on first use for a package, venv-patcher:

  1. Imports the package to find its on-disk directory.
  2. Runs git init, adds a .gitignore for __pycache__/*.pyc, then git add . and commits the pristine state as "initial".

It then applies the patch (git am by default) on top. The result is always wrapped in a commit with a pinned author/committer identity and date (from the yaml, or a fixed fallback), so re-applying the same patch to the same starting state always produces the exact same commit hash.

Patch results (applied or failed) are recorded in the manifest immediately, even when a patch fails to apply. The manifest also stores the sha256 of the patch file content that was actually applied. Running apply again for a patch that was already applied:

  • prints a warning and skips it, if the patch file on disk is unchanged;
  • errors out and tells you to pass --force, if the patch file's content has changed since it was applied (e.g. it's still under development and doesn't have a sha256sum pinned down yet) - venv-patcher won't silently apply a different patch on top of what's already there.

By default, if a package listed in the yaml can't be imported, venv-patcher records the failure and aborts immediately without processing any further patches. Pass --skip-missing to instead skip just that patch and continue with the rest.

Pass --force to start from a clean slate before applying: venv-patcher hard-resets the affected packages back to their recorded initial commit and clears their patch history first, then applies the yaml file(s) as usual. This is meant for iterating on a patch that doesn't have a sha256sum pinned down yet. Combined with -p, only the given package(s) are reset. Without -p, every package tracked in the manifest is reset - including ones not mentioned in the yaml file(s) you're currently applying with -f.

list

Prints every package with applied patches in the current environment, their status, and any errors.

reset

Hard-resets every patched package back to its recorded initial commit and clears the manifest's patch history for it. Use -p/--package one or more times to only reset specific packages.

YAML format

version: 1                          # required, currently must be 1
patches:
  - path: patches/0001-fix.patch    # relative to this yaml file, or absolute
    package: requests               # importable package name
    sha256sum: <optional sha256 of the patch file>
    apply-command: git am           # default; use "git apply" for a plain diff
    author: Jane Doe                # used for the commit identity
    email: jane@example.com
    date: "2024-01-01T00:00:00+00:00"
    comments: "commit message for the patch commit"

See example.yml for a full annotated example.

Development

uv sync
uv run poe all      # lint, format, test

Download files

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

Source Distribution

venv_patcher-0.0.2.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

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

venv_patcher-0.0.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file venv_patcher-0.0.2.tar.gz.

File metadata

  • Download URL: venv_patcher-0.0.2.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for venv_patcher-0.0.2.tar.gz
Algorithm Hash digest
SHA256 57ead30b64b49dfba8cc171ee88f80402f72eb07054b59968790f6001145e39c
MD5 94ce65da806884546ead11986e67ee3c
BLAKE2b-256 0d0d3e8018c1c49685dea011525a0c65ef573bbd7a2dd5bedf0a312c5d1fec26

See more details on using hashes here.

Provenance

The following attestation bundles were made for venv_patcher-0.0.2.tar.gz:

Publisher: publish.yml on thorsten-klein/venv-patcher

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

File details

Details for the file venv_patcher-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: venv_patcher-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for venv_patcher-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb592e6eff242b0498532612097809e6318b19206c1a015b81bba81926afe98
MD5 e02174936214b48d1f9d24830c822b98
BLAKE2b-256 c7a209b5ac3bf9565685b04a36898f9471e84d0b04ad93f3dc99861d7c533396

See more details on using hashes here.

Provenance

The following attestation bundles were made for venv_patcher-0.0.2-py3-none-any.whl:

Publisher: publish.yml on thorsten-klein/venv-patcher

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

Release history Release notifications | RSS feed

0.1.0

2 files

This release

0.0.2 This release

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page