python-virtualenv

Example:

# Create user 'freckles',  install Python via pyenv, create virtualenv 'freckles', install the 'freckles-cli' package in it.
- python-virtualenv:
    venv_name: freckles
    user: freckles
    python_type: pyenv
    python_version: 3.6.8
    python_packages:
    - freckles-cli

Description

Installs Python using pyenv, then use that to create a virtualenv with the specified name and Python version. Also lets you specify (optional) system dependencies as well as packages to install in the virtualenv.

In case you choose 'pyenv' as the 'python_type', this will add a piece of code to $HOME/.bashrc to load pyenv when the user logs in.

Variables

Name Type Default Description

venv_name

string --

The name of the virtualenv to set up. Required

group

string --

The group who owns/runs the virtualenv.

pip_extra_args

string --

Extra arguments forwarded to 'pip'.

python_base_path

string --

The base path to install Python into (if using 'pyenv' or 'conda').

python_build_opts

string --

Build options to be forwarded (if supported by 'install_type').

python_packages

list []

All necessary Python packages.

python_type

string pyenv

How to install Python. Defaults to 'pyenv'.

python_version

string latest

The version of python.

system_dependencies

list []

System packages the application depends on.

system_user

boolean False

Whether the user and group should be a system user/group.

uid

integer --

The uid of the user to create (optional).

update

boolean False

Update packages if already installed.

user

string --

The user who owns/runs the virtualenv.

venv_base_path

string --

The path that holds the virtualenv directory.

venv_python_exe

string --

This only works in combination with the 'system' 'python_install_type', if used with another type, this task will fail.

Examples

Example 1

Create user 'freckles', install Python via pyenv, create virtualenv 'freckles', install the 'freckles-cli' package in it.

Code
- python-virtualenv:
    venv_name: freckles
    user: freckles
    python_type: pyenv
    python_version: 3.6.8
    python_packages:
    - freckles-cli
Description

Create a user 'freckles' if it does not exist yet, install Python version '3.6.8' using Pyenv for that user. Then use 'pyenv virtualenv' to create a virtualenv called 'freckles' (which will be located under /home/freckles/.pyenv/versions/freckles).

Finally, install the pip package 'freckles-cli' into that virtualenv.

Command-line

frecklecute python-virtualenv --help

Usage: frecklecute python-virtualenv [OPTIONS]

  Installs Python using [pyenv](https://github.com/pyenv/pyenv), then use
  that to create a virtualenv with the specified name and Python version.
  Also lets you specify (optional) system dependencies as well as packages
  to install in the virtualenv.

  In case you choose 'pyenv' as the 'python_type', this will add a piece of
  code to ``$HOME/.bashrc`` to load pyenv when the user logs in.

Options:
  --venv-name VENV_NAME           The name of the virtualenv to set up.
                                  [required]
  --group GROUP                   The group who owns/runs the virtualenv.
  --pip-extra-args PIP_EXTRA_ARGS
                                  Extra arguments forwarded to 'pip'.
  --python-base-path PYTHON_BASE_PATH
                                  The base path to install Python into (if
                                  using 'pyenv' or 'conda').
  --python-build-opts PYTHON_BUILD_OPTS
                                  Build options to be forwarded (if supported
                                  by 'install_type').
  -p, --python-pkg PYTHON_PACKAGES
                                  All necessary Python packages.
  --python-type PYTHON_TYPE       How to install Python. Defaults to 'pyenv'.
  --python-version PYTHON_VERSION
                                  The version of python.
  -s, --system-dependency SYSTEM_DEPENDENCIES
                                  System packages the application depends on.
  --system-user / --no-system-user
                                  Whether the user and group should be a
                                  system user/group.
  --uid UID                       The uid of the user to create (optional).
  --update                        Update packages if already installed.
  --user USER                     The user who owns/runs the virtualenv.
  --venv-base-path VENV_BASE_PATH
                                  The path that holds the virtualenv
                                  directory.
  --venv-python-exe VENV_PYTHON_EXE
                                  The (optional) path to an existing Python
                                  executable to be used for the venv.
  --help                          Show this message and exit.