grezzo/featlib/poetry.sh

74 lines
1.5 KiB
Bash

#! /bin/bash --
[ ! -z "${GREZZO_1577142078}" ] && return; GREZZO_1577142078=0
. "$(this_script_path)/pip.sh"
. "$(this_script_path)/curl.sh"
function feat_add_poetry() {
# Questo era il vecchio metodo:
#feat_needed "pip"
#feat_needed "curl"
#curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
# Adesso è raccomandato invece installare direttamente con pip:
pip_feat_needed "poetry"
. "$HOME/.poetry/env"
}
function poetry_initialized() {
poetry check >/dev/null 2>&1
}
function poetry_feat_added() {
poetry show | cut -f1 -d ' ' | grep -q ^"$1"$
}
function poetry_feat_missing() {
# Ricarica .bashrc.before per eventuali modifiche al PATH
if [ -f "$HOME/.bashrc.before" ]; then
source "$HOME/.bashrc.before"
fi
if feat_missing "pip"; then
true
else
if feat_missing "poetry"; then
true
else
if ! poetry_initialized; then
true
fi
! poetry run python -c "import $1" >/dev/null 2>&1
fi
fi
}
function poetry_feat_needed() {
# Ricarica .bashrc.before per eventuali modifiche al PATH
if [ -f "$HOME/.bashrc.before" ]; then
source "$HOME/.bashrc.before"
fi
feat_needed "poetry"
FEAT="$1"
if ! poetry_initialized; then
poetry init -n
fi
if poetry_feat_added "$FEAT"; then
if poetry_feat_missing "$FEAT"; then
poetry install
fi
else
if type "poetry_feat_add_$FEAT" > /dev/null 2>&1 ; then
eval "poetry_feat_add_$FEAT"
else
poetry_feat_add "$FEAT"
fi
fi
}
function poetry_feat_add() {
poetry add "$1"
}
unset DOVE