From c2858533d0b4ec49ba39f7c173af44bf911e6ee2 Mon Sep 17 00:00:00 2001 From: Mikhail Zhuk Date: Wed, 11 Dec 2024 20:59:48 +0100 Subject: [PATCH] add support a new env var to auto activate poetry (#25) --- README.md | 3 +++ bin/utils.sh | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) mode change 100755 => 100644 bin/utils.sh diff --git a/README.md b/README.md index e627216..80ca54d 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,9 @@ poetry = {version='latest', pyproject='pyproject.toml'} python = '3.11' # must be after poetry so the poetry bin is first in PATH ``` +You can also set `MISE_POETRY_VENV_AUTO=1` to automatically activate the virtualenv if the +project contains both `pyproject.toml` and `poetry.lock` files. + Set `MISE_POETRY_AUTO_INSTALL=1` to automatically run `poetry install` to create the virtualenv. ## License diff --git a/bin/utils.sh b/bin/utils.sh old mode 100755 new mode 100644 index 1f2941c..ad2ef80 --- a/bin/utils.sh +++ b/bin/utils.sh @@ -15,8 +15,14 @@ poetry_bin() { poetry_venv() { local pyproject pyproject="$(eval "echo ${MISE_TOOL_OPTS__PYPROJECT-}")" - if [ "$pyproject" = "" ]; then + if [[ "${MISE_POETRY_VENV_AUTO:-}" != "true" ]] && [[ "${MISE_POETRY_VENV_AUTO:-}" != "1" ]]; then + if [ "$pyproject" = "" ]; then + return 1 + fi + elif [[ ! -f "poetry.lock" ]] | [[ ! -f "pyproject.toml" ]]; then return 1 + else + pyproject="pyproject.toml" fi if [[ $pyproject != /* ]] && [[ -n ${MISE_PROJECT_ROOT-} ]]; then pyproject="${MISE_PROJECT_ROOT-}/$pyproject"