Fix default packages support and document the feature in the README

This commit is contained in:
Stephen Haynes 2019-06-29 14:31:27 +10:00
parent a44bb6d17d
commit 4db4d2263b
2 changed files with 18 additions and 6 deletions

View file

@ -47,3 +47,12 @@ Python 2.7.13
## Pip installed modules and binaries ## Pip installed modules and binaries
If you use pip to install a module like ipython that has a binaries. You will need to run `asdf reshim python` for the binary to be in your path. If you use pip to install a module like ipython that has a binaries. You will need to run `asdf reshim python` for the binary to be in your path.
## Default Python packages
asdf-python can automatically install a default set of Python packages with pip right after installing a Python version. To enable this feature, provide a `$HOME/.default-python-packages` file that lists one package per line, for example:
```
ansible
pipenv
```

View file

@ -22,13 +22,16 @@ install_python() {
install_default_python_packages() { install_default_python_packages() {
local default_python_packages="${HOME}/.default-python-packages" local default_python_packages="${HOME}/.default-python-packages"
if [ ! -f $default_python_packages ]; then return; fi
for name in $(cat $default_python_packages); do if [ ! -f $default_python_packages ]; then return; fi
echo -ne "\nInstalling \e[33m${name}\e[39m python package ... "
if pip install $name > /dev/null 2>&1; then cat "$default_python_packages" | while read -r name; do
echo -e "\e[32mSUCCESS\e[39m" echo -ne "\nInstalling \033[33m${name}\033[39m python package... "
PATH="$ASDF_INSTALL_PATH/bin:$PATH" pip install "$name" > /dev/null 2>&1 && rc=$? || rc=$?
if [[ $rc -eq 0 ]]; then
echo -e "\033[32mSUCCESS\033[39m"
else else
echo -e "\e[31mFAIL\e[39m" echo -e "\033[31mFAIL\033[39m"
fi fi
done done
} }