network_inventory/.envrc

41 lines
1.2 KiB
Plaintext

use flake
eval "$shellHook"
layout_postgres() {
export PGDATA="$(direnv_layout_dir)/postgres"
export PGHOST="$PGDATA"
if [[ ! -d "$PGDATA" ]]; then
initdb
echo -e "listen_addresses = 'localhost'\nunix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
echo "CREATE DATABASE django;" | postgres --single -E postgres
fi
}
layout_pdm() {
PYPROJECT_TOML="${PYPROJECT_TOML:-pyproject.toml}"
if [ ! -f "$PYPROJECT_TOML" ]; then
log_status "No pyproject.toml found. Executing \`pmd init\` to create a \`$PYPROJECT_TOML\` first."
pdm init --non-interactive --python "$(python3 --version 2>/dev/null | cut -d' ' -f2 | cut -d. -f1-2)"
fi
VIRTUAL_ENV=$(pdm venv list | grep "^\*" | awk -F" " '{print $3}')
if [ -z "$VIRTUAL_ENV" ] || [ ! -d "$VIRTUAL_ENV" ]; then
log_status "No virtual environment exists. Executing \`pdm info\` to create one."
pdm info
VIRTUAL_ENV=$(pdm venv list | grep "^\*" | awk -F" " '{print $3}')
fi
PATH_add "$VIRTUAL_ENV/bin"
export PDM_ACTIVE=1
export VIRTUAL_ENV
}
layout postgres
layout pdm
export PROJECT_DIR=$(pwd)
export WEBPORT=$(($RANDOM + 1100))
export PGPORT=$(($WEBPORT + 100))
watch_file "$PGDATA/postgresql.conf"