Configure Python develop tool chain

- use pyenv to manage the develop environments
  + install several Python versions (3.7 - 3.10 and 2.7)
  + each version receives its own copies of black, pipenv, and poetry
- add two more virtual environments based off the latest version:
  + "interactive" => default environment optimized for interactive
                     usage with with black, bpython, and ipython
                     (also receives accidental `pip install`s)
  + "utils" => hosts various globally available tools/apps
               (e.g., mackup and youtube-dl)
- add installation and update scripts for the entire tool chain
- set up completions for bash and zsh
- set up convenient aliases
- configure bpython
- configure poetry
This commit is contained in:
Alexander Hess 2022-08-09 13:53:43 +02:00
commit 0319e614b8
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
9 changed files with 233 additions and 1 deletions

31
.bashrc
View file

@ -5,6 +5,12 @@
[[ $- != *i* ]] && return
# Check if a command can be found on the $PATH
_command_exists() {
command -v "$1" 1>/dev/null 2>&1
}
# Enable XON/XOFF software flow control
stty -ixon
@ -69,6 +75,13 @@ if ! shopt -oq posix; then
fi
fi
# Enable completions for various tools
_command_exists invoke && eval "$(invoke --print-completion-script=bash)"
_command_exists nox && eval "$(register-python-argcomplete nox)"
_command_exists pip && eval "$(pip completion --bash)"
_command_exists pipx && eval "$(register-python-argcomplete pipx)"
_command_exists poetry && eval "$(poetry completions bash)"
# Add tab completion for all aliases to commands with completion functions
# (must come after bash completions have been set up)
# Source: https://superuser.com/a/437508
@ -193,5 +206,21 @@ _prompt_jobs() { # Indicate running background jobs with a"%"
(( $(jobs -rp | wc -l) )) && printf "\033[0;32m %\033[0m"
}
PS1='${chroot:+($_debian_chroot)}\w$(_prompt_git)$(_prompt_jobs) > '
_prompt_pyenv() { # Mimic zsh's pyenv/venv integration
if [ -n "$VIRTUAL_ENV" ]; then
echo -e "\033[0;36m py $(python -c "import os, sys; (hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)) and print(os.path.basename(sys.prefix))")\033[0m"
elif [ -n "$PYENV_VERSION" ]; then
if [ "$PYENV_VERSION" != "system" ]; then
echo -e "\033[0;36m py $PYENV_VERSION\033[0m"
fi
elif [ -f "$(pwd)/.python-version" ]; then
echo -e "\033[0;36m py $(cat .python-version | sed ':a;N;$!ba;s/\n/:/g')\033[0m"
fi
}
# Disable the default prompts set by pyenv and venv
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export VIRTUAL_ENV_DISABLE_PROMPT=1
PS1='${chroot:+($_debian_chroot)}\w$(_prompt_git)$(_prompt_jobs)$(_prompt_pyenv) > '
PS2='... '