layout poetry

main
Alpha Chen 1 year ago
parent 388cec0ea5
commit c0161e1f9d
No known key found for this signature in database

@ -27,3 +27,28 @@ use_ruby() {
# bin directory to take precedence # bin directory to take precedence
PATH_add ./.direnv/bin PATH_add ./.direnv/bin
} }
# https://github.com/direnv/direnv/wiki/Python/#poetry
layout_poetry() {
PYPROJECT_TOML="${PYPROJECT_TOML:-pyproject.toml}"
if [[ ! -f "$PYPROJECT_TOML" ]]; then
log_status "No pyproject.toml found. Executing \`poetry init\` to create a \`$PYPROJECT_TOML\` first."
poetry init
fi
if [[ -d ".venv" ]]; then
VIRTUAL_ENV="$(pwd)/.venv"
else
VIRTUAL_ENV=$(poetry env info --path 2>/dev/null ; true)
fi
if [[ -z $VIRTUAL_ENV || ! -d $VIRTUAL_ENV ]]; then
log_status "No virtual environment exists. Executing \`poetry install\` to create one."
poetry install
VIRTUAL_ENV=$(poetry env info --path)
fi
PATH_add "$VIRTUAL_ENV/bin"
export POETRY_ACTIVE=1
export VIRTUAL_ENV
}

Loading…
Cancel
Save