TOOCS.python

TOOCS / Ansible Role: TOOCS.python

/!\ This role has been renamed - Old name: FlorianKempenich.python-virtualenv /!\

  • Install multiple Python versions using asdf (or pyenv)
  • Install pipenv for all versions
  • Optionally, install global pip packages for the default Python version

What is TOOCS?

TOOCS - The Opinionated One-Click Setups is a set of tools/Ansible roles designed to set up a system quickly. They provide a simple and reliable way to install a specific tool. You can use them directly, or inspect the code as a step-by-step tutorial.

They are "opinionated," meaning they ensure the tool is set up quickly but do not guarantee consistency in how it's done. New updates might introduce changes that could break things.
Review the code to understand what it does!

Requirements

This role works only on MacOS and Ubuntu/Debian.

Role Variables

  • python_versions

  • global_pip_packages

    • List of pip packages to install
    • Packages will only be installed for the default Python version (the first one in the list)
    • Default: []
  • installation_method

  • asdf_skip_shell_setup

Installation Methods

asdf

This is the preferred and default installation method using the asdf version manager.

The installation and configuration of asdf, as well as Python installation, is handled by another TOOCS: TOOCS.asdf.

This TOOCS only installs the optional global pip packages.

Post-install - with asdf: Shell configuration

  • Using zsh? You're all set! Your shell is automatically configured during asdf installation.

  • Not using zsh? Manual setup is needed: TOOCS/asdf - Non zsh Users

  • If asdf is already set up on your computer, you can skip automatic shell setup by setting asdf_skip_shell_setup to True.


pyenv

An alternative method using the pyenv version manager.

Post-install - with pyenv: Shell configuration

Since pyenv manages different Python versions, it must be activated in your shell.

Add these lines to the appropriate files:

  • ~/.zshrc or ~/.bashrc

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
  • ~/.zlogin or ~/.bash_profile

if command -v pyenv 1>/dev/null 2>&1; then
    eval "$(pyenv init -)"
fi

The split initialization helps avoid problems with both pyenv and pipenv. This way, pyenv activation happens once per login shell and doesn't interfere with pipenv shell.
Learn more: Pyenv Issue #184 - Wrong Python inside of 'pipenv shell'


Example Playbook

- hosts: localhost
  tasks:
    - include_role:
        name: TOOCS.python
      vars:
        python_versions:
          - 3.7.0
          - 2.7.15
        global_pip_packages:
          - cheat
          - howdoi
          - ansible-droplet


# OR

- hosts: localhost
  tasks:
    - include_role:
        name: TOOCS.python
      vars:
        python_versions:
          - 3.7.0
        installation_method: asdf
        asdf_skip_shell_setup: True

# OR

- hosts: localhost
  tasks:
    - include_role:
        name: TOOCS.python
      vars:
        python_versions:
          - 3.7.0
        installation_method: pyenv

License

MIT

Author Information

Follow me on Twitter: @ThisIsFlorianK
Learn more about my work: Florian Kempenich - Personal Website

Informazioni sul progetto

Install multiple versions of Python with some optional global packages

Installa
ansible-galaxy install TOOCS.python
Licenza
mit
Download
117
Proprietario
The Opinionated One-Click Setups - TOOCS - Logo made with DesignEvo (www.designevo.com)