ensurepkg
is a minimal package to ensure a pip-managed package exists.
from ensurepkg import EnsurePkg
for guard in EnsurePkg(dict(dotenv="python-dotenv")):
with guard:
import dotenv
with EnsurePkg(dict(git="GitPython"), cache_dir="/tmp/ensurepkg"):
import git
print(dotenv.__name__)
print(git.__name__, git.__version__)
cache_dir
is where ensurepkg installs the packages. It is isolated from other environments and it's resolved as:
- setting programatically via
EnsurePkg(cache_dir="...")
- from env var $ENSUREPKG_DIR
- from env var $XDG_CACHE_HOME/ensurepkg
- from env var $HOME/.cache/ensurepkg
- /tmp/ensurepkg