2024-10-21 16:24:42 +02:00
|
|
|
# shellcheck shell=bash
|
2022-04-12 17:34:29 +02:00
|
|
|
|
|
|
|
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
|
2024-09-12 14:08:50 +02:00
|
|
|
log_error 'layout_poetry: no pyproject.toml found. Use `poetry init` to create one first'
|
2022-04-12 17:34:29 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create venv if it doesn't exist
|
2024-09-12 14:07:22 +02:00
|
|
|
poetry run -q -- true
|
2022-04-12 17:34:29 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
2024-09-12 15:23:19 +02:00
|
|
|
|
|
|
|
layout_uv() {
|
|
|
|
if ! has uv; then
|
|
|
|
# shellcheck disable=2016
|
|
|
|
log_error 'layout_uv: `uv` is not in PATH'
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -f pyproject.toml ]]; then
|
|
|
|
# shellcheck disable=2016
|
|
|
|
log_error 'layout_uv: no pyproject.toml found. Use `uv init` to create one first'
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local default_venv="$PWD/.venv"
|
|
|
|
: "${VIRTUAL_ENV:=$default_venv}"
|
|
|
|
|
|
|
|
# Use non-default venv path if required
|
|
|
|
if [ "$VIRTUAL_ENV" != "$default_venv" ]; then
|
|
|
|
export UV_PROJECT_ENVIRONMENT="$VIRTUAL_ENV"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create venv if it doesn't exist
|
|
|
|
uv venv -q
|
|
|
|
|
|
|
|
export VIRTUAL_ENV
|
|
|
|
export UV_ACTIVE=1
|
|
|
|
PATH_add "$VIRTUAL_ENV/bin"
|
|
|
|
watch_file pyproject.toml
|
|
|
|
watch_file uv.lock
|
2024-11-27 16:12:10 +01:00
|
|
|
watch_file .python-version
|
2024-09-12 15:23:19 +02:00
|
|
|
}
|