From d118351849468bc5159678e5a03274b8c4c5aba4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 12 Apr 2022 17:34:29 +0200 Subject: [PATCH] home: direnv: add 'python' library file --- home/direnv/lib/python.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 home/direnv/lib/python.sh diff --git a/home/direnv/lib/python.sh b/home/direnv/lib/python.sh new file mode 100644 index 0000000..15a273f --- /dev/null +++ b/home/direnv/lib/python.sh @@ -0,0 +1,25 @@ +#shellcheck shell=bash + +layout_poetry() { + if ! has poetry; then + # shellcheck disable=2016 + log_error 'layout_poetry: `poetry` is not in PATH' + return 1 + fi + + if [[ ! -f pyproject.toml ]]; then + # shellcheck disable=2016 + log_error 'layout_poetry: no pyproject.toml found. Use `poetry new` or `poetry init` to create one first' + return 1 + fi + + # create venv if it doesn't exist + poetry run true + + # shellcheck disable=2155 + export VIRTUAL_ENV=$(poetry env info --path) + export POETRY_ACTIVE=1 + PATH_add "$VIRTUAL_ENV/bin" + watch_file pyproject.toml + watch_file poetry.lock +}