snakeoil.contexts module¶
Various with-statement context utilities.
- class snakeoil.contexts.GitStash(path: str | PathLike[str], pathspecs: Iterable[str] = (), staged=False)[source]¶
Bases:
AbstractContextManagerContext manager for stashing untracked or modified/uncommitted files.
- snakeoil.contexts.os_environ(*remove: str, **update: str) Iterator[None][source]¶
Mangle the
os.environdictionary and revert on exit.This is explicitly not thread safe. It however takes steps to mutate os.environ rather than replacing the instance, so any references held to os.environ will be updated.
- Parameters:
remove – variables to remove
update – variable -> value mapping to add or alter
- snakeoil.contexts.patch(target, new)[source]¶
Simplified module monkey patching via context manager.
- Parameters:
target – Target class or object.
new – Object or value to replace the target with.
- snakeoil.contexts.syspath(path: str, condition: bool = True, position: int = 0)[source]¶
Context manager that mangles
sys.pathand then reverts on exit.- Parameters:
path – The directory path to add to
sys.path.condition – Optional boolean that decides whether
sys.pathis mangled or not, defaults to being enabled.position – Optional integer that is the place where the path is inserted in
sys.path, defaults to prepending.