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

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.1.tar.gz (57.2 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.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: venv_patcher-0.0.1.tar.gz
  • Upload date:
  • Size: 57.2 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.1.tar.gz
Algorithm Hash digest
SHA256 1091619b63c21c39d6bd1dae60da8384cb2f5562fc53a233cdf4465fc1dadb4e
MD5 19788ea08a0a3c6ddefed4f717914ead
BLAKE2b-256 25fcc2c18cfd6b83afe9f700d069f3644bd19fb72344bab123f791c14048c612

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: venv_patcher-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b9c63cd2ab33644decf23a8ae3cb3d2ae3c403abd755fb5c596eaea86de5595
MD5 0a9f8b57c597bd100f011a3a9f52752c
BLAKE2b-256 9330aa171989fd38b087bca5dbc87738184c178893a55ea01196890551ac3093

See more details on using hashes here.

Provenance

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

0.0.2

2 files

This release

0.0.1 This release

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