| Branch | Pipeline |
|---|---|
| master |
Ansible role to install pyenv and pyenv-virtualenv on Ubuntu or macOS development machines.
Optionally, pyenv-virtualenvwrapper can be installed and used for managing environments.
Don't use this role on production servers as it supports installing pyenv only under user home directory.
The default method to install pyenv and plugins on macOS is to use Homebrew.
The role doesn't know how to migrate from existing Homebrew installs to Git-based installations, so it will try to detect any existing installation and keep using the previous method.
If you want to migrate, backup and delete your existing ~/.pyenv directory
before running this role.
The role includes an experimental support for installing pyenv and plugins with Homebrew on Linux.
The role doesn't install Homebrew on Linux itself and expects it to be installed
in the default /home/linuxbrew/.linuxbrew location.
Installing Python versions with pyenv on Linux when Homebrew installation exists has some known issues:
- readline extension was not compiled, installed pyenv by Linuxbrew on Ubuntu 16 #1479
This role installs Python versions defined in pyenv_python_versions
variable.
To set global version, set pyenv_global variable to the desired version(s).
pyenv_global: "{{ pyenv_python37_version }} system"This is configured to use latest Python 2 and Python 3 versions and the system version as default.
This role creates config file in ~/.pyenv/.pyenvrc that is loaded in
.bashrc and .zshrc files.
Code completion is loaded by default.
If you're managing your shell scripts .dotfiles or are using a framework, you
should set pyenv_init_shell to false and update these files yourself to keep
them clean.
Reference .bashrc configuration:
if [ -e "$HOME/.pyenv/.pyenvrc" ]; then
source $HOME/.pyenv/.pyenvrc
if [ -e "$HOME/.pyenv/completions/pyenv.bash" ]; then
source $HOME/.pyenv/completions/pyenv.bash
elif [ -e "/usr/local/opt/pyenv/completions/pyenv.bash" ]; then
source /usr/local/opt/pyenv/completions/pyenv.bash
fi
fiReference .zshrc configuration:
if [ -e "$HOME/.pyenv/.pyenvrc" ]; then
source $HOME/.pyenv/.pyenvrc
if [ -e "$HOME/.pyenv/completions/pyenv.zsh" ]; then
source $HOME/.pyenv/completions/pyenv.zsh
elif [ -e "/usr/local/opt/pyenv/completions/pyenv.zsh" ]; then
source /usr/local/opt/pyenv/completions/pyenv.zsh
fi
fiPath to ~/.pyenv is based on environment variables:
pyenv_home: "{{ ansible_env.HOME }}"
pyenv_root: "{{ ansible_env.HOME }}/.pyenv"Update .bashrc and .zshrc files in user home directory:
pyenv_init_shell: trueVersions to install:
pyenv_version: "v1.2.13"
pyenv_virtualenv_version: "v1.1.5"
pyenv_virtualenvwrapper_version: "v20140609"Latest Python 3.7 and Python 3.8 versions:
pyenv_python37_version: "3.7.6"
pyenv_python38_version: "3.8.1"Python 2 and Python 3 versions are installed by default:
pyenv_python_versions:
- "{{ pyenv_python37_version }}"
- "{{ pyenv_python38_version }}"Set global version to Python 3.7 with system fallback:
pyenv_global: "{{ pyenv_python37_version }} system"Install virtualenvwrapper plugin:
pyenv_virtualenvwrapper: false
pyenv_virtualenvwrapper_home: "{{ ansible_env.HOME }}/.virtualenvs"Install using Homebrew package manager on macOS:
pyenv_install_from_package_manager: trueDetect existing installation method and use that:
pyenv_detect_existing_install: trueInstall using Homebrew on Linux:
pyenv_homebrew_on_linux: true- hosts: localhost
connection: local
become: false
roles:
- role: markosamuli.pyenvRun the following scripts to get latest releases from GitHub and update them in role defaults.
Update pyenv release:
./update-release pyenvUpdate pyenv-virtualenv release:
./update-release pyenv-virtualenvUpdate default Python 3.7 version:
./update-python python37Update default Python 3.8 version:
./update-python python38Update all versions:
make updateInstall pre-commit hooks and validate coding style:
make lintRun tests in Ubuntu and Debian using Docker:
make testUse of .pyenvrc file and parts used for installing python version taken from
avanov.pyenv role.
Install development dependencies in a local virtualenv:
make setupInstall pre-commit hooks:
make install-git-hooks