snakeoil.contexts module¶
Various with-statement context utilities.
- class snakeoil.contexts.GitStash(path, pathspecs=None, staged=False)[source]¶
Bases:
AbstractContextManagerContext manager for stashing untracked or modified/uncommitted files.
- snakeoil.contexts.os_environ(*remove, **update)[source]¶
Mangle the
os.environdictionary and revert on exit.- 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.