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:
- Imports the package to find its on-disk directory.
- Runs
git init, adds a.gitignorefor__pycache__/*.pyc, thengit 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 asha256sumpinned down yet) -venv-patcherwon'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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57ead30b64b49dfba8cc171ee88f80402f72eb07054b59968790f6001145e39c
|
|
| MD5 |
94ce65da806884546ead11986e67ee3c
|
|
| BLAKE2b-256 |
0d0d3e8018c1c49685dea011525a0c65ef573bbd7a2dd5bedf0a312c5d1fec26
|
Provenance
The following attestation bundles were made for venv_patcher-0.0.2.tar.gz:
Publisher:
publish.yml on thorsten-klein/venv-patcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
venv_patcher-0.0.2.tar.gz -
Subject digest:
57ead30b64b49dfba8cc171ee88f80402f72eb07054b59968790f6001145e39c - Sigstore transparency entry: 2232606590
- Sigstore integration time:
-
Permalink:
thorsten-klein/venv-patcher@5829281610da1bfb1c9a3e2dc28c41625f622475 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/thorsten-klein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5829281610da1bfb1c9a3e2dc28c41625f622475 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb592e6eff242b0498532612097809e6318b19206c1a015b81bba81926afe98
|
|
| MD5 |
e02174936214b48d1f9d24830c822b98
|
|
| BLAKE2b-256 |
c7a209b5ac3bf9565685b04a36898f9471e84d0b04ad93f3dc99861d7c533396
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
venv_patcher-0.0.2-py3-none-any.whl -
Subject digest:
ffb592e6eff242b0498532612097809e6318b19206c1a015b81bba81926afe98 - Sigstore transparency entry: 2232607078
- Sigstore integration time:
-
Permalink:
thorsten-klein/venv-patcher@5829281610da1bfb1c9a3e2dc28c41625f622475 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/thorsten-klein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5829281610da1bfb1c9a3e2dc28c41625f622475 -
Trigger Event:
push
-
Statement type: