From daaaab6bb27187b61437c5e9a312e1419cc662b0 Mon Sep 17 00:00:00 2001 From: Chris Lingwood <165787822+chris-lingwood-korelabs-co@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:58:02 +0000 Subject: [PATCH] Use return codes from poetry_venv to disabiguate causes of returns. (#22) * resolve annoying message when pyproject= isn't set in mise.toml * disambiguate "failures" of poetry_venv * remove redundant check on VIRTUAL_ENV * replace exit code 2 with 1 --- bin/exec-env | 10 +++++++++- bin/utils.sh | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/exec-env b/bin/exec-env index 89dca31..bc98b12 100755 --- a/bin/exec-env +++ b/bin/exec-env @@ -11,8 +11,16 @@ setup_virtualenv() { return fi + set +e VIRTUAL_ENV="$(poetry_venv)" - if [[ -z "$VIRTUAL_ENV" ]] || [[ ! -d "$VIRTUAL_ENV" ]]; then + poetry_venv_exit_code=$? + set -e + + if [[ $poetry_venv_exit_code -eq 1 ]]; then + return + fi + + if [[ ! -d "$VIRTUAL_ENV" ]]; then if [[ "${MISE_POETRY_AUTO_INSTALL:-}" != "true" ]] && [[ "${MISE_POETRY_AUTO_INSTALL:-}" != "1" ]]; then echoerr "mise-poetry: Virtualenv does not exist at $VIRTUAL_ENV. Execute \`poetry install\` to create one." return diff --git a/bin/utils.sh b/bin/utils.sh index bedbdd4..1f2941c 100755 --- a/bin/utils.sh +++ b/bin/utils.sh @@ -16,14 +16,14 @@ poetry_venv() { local pyproject pyproject="$(eval "echo ${MISE_TOOL_OPTS__PYPROJECT-}")" if [ "$pyproject" = "" ]; then - return + return 1 fi if [[ $pyproject != /* ]] && [[ -n ${MISE_PROJECT_ROOT-} ]]; then pyproject="${MISE_PROJECT_ROOT-}/$pyproject" fi if [[ ! -f $pyproject ]]; then echoerr "mise-poetry: No pyproject.toml found. Execute \`poetry init\` to create \`$pyproject\` first." - return + return 1 fi poetry_bin -C "${pyproject%/*}" env info --path 2>/dev/null true