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 --group dev
uv run poe all      # pre-commit, lint, format, mypy, pyright, bandit, pip-audit, complexity, 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.1.0.tar.gz (137.1 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.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for venv_patcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 852c640e6cd54cbc22d1015584782856182869905e1daa293e95c00178ca28b0
MD5 6502196ab8f544369fa485490cdb0ca8
BLAKE2b-256 5e5f1060cf513cc88f0fd44e0bf454508d72019753b78b4bacccb63baa0c7d3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for venv_patcher-0.1.0.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.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for venv_patcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eebfed8c5d7ba99d690c1329af1581440ff1837f939fefd0e8a4b57c232fdc10
MD5 39bfd11eb612351eb4456352ef3d16b4
BLAKE2b-256 c354324475e7d508f6e9a3e800611b7a71850045b74678b2b2dccea8b30f4154

See more details on using hashes here.

Provenance

The following attestation bundles were made for venv_patcher-0.1.0-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

This release

0.1.0 This release

2 files

0.0.2

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