python-packages-in-virtualenv

Description

Installs Python packages into a Virtualenv.

Don't use this directly (in most cases), just use the 'python-virtualenv' frecklet instead, because this frecklet does not create that virtualenv, nor does it ensure that Python is available at all.

Variables

Name Type Default Description

venv_name

string --

The name of the virtualenv to set up. Required

pip_extra_args

string --

Extra arguments forwarded to 'pip'.

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.

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.

Code

doc:
  short_help: Installs Python packages into a Virtualenv.
  help: |
    Installs Python packages into a Virtualenv.

    Don't use this directly (in most cases), just use the 'python-virtualenv' frecklet instead, because this frecklet does not create that virtualenv, nor does it ensure that Python is available at all.

args:
  _import: python-virtualenv-exists
  system_dependencies:
    doc:
      short_help: System packages the application depends on.
    type: list
    empty: true
    required: false
    default: []
    cli:
      param_decls:
      - --system-dependency
      - -s
  python_packages:
    doc:
      short_help: All necessary Python packages.
    type: list
    empty: true
    required: true
    default: []
    schema:
      type: string
    cli:
      param_decls:
      - --python-pkg
      - -p
  pip_extra_args:
    doc:
      short_help: Extra arguments forwarded to 'pip'.
    type: string
    required: false
  update:
    doc:
      short_help: Update packages if already installed.
    type: boolean
    default: false
    cli:
      param_decls:
      - --update
frecklets:
- packages-installed:
    frecklet::skip: '{{:: system_dependencies | true_if_empty ::}}'
    packages: '{{:: system_dependencies ::}}'

- frecklet:
    name: freckfrackery.python
    type: ansible-role
    resources:
      ansible-role:
      - freckfrackery.python
      - freckfrackery.install-pkgs
      - freckfrackery.install-pkg-mgrs
    properties:
      idempotent: true
      internet: true
      elevated: '{{:: user | true_if_not_empty ::}}'
    desc:
      references:
        pyenv homepage: https://github.com/pyenv/pyenv
  task:
    include-type: include
  vars:
    frecklet::skip: '{{:: python_packages | true_if_empty ::}}'
    python_owner: '{{:: user ::}}'
    python_virtualenv_name: '{{:: venv_name ::}}'
    python_virtualenv_base: '{{:: venv_base_path ::}}'
    python_version: '{{:: python_version ::}}'
    python_type: '{{:: python_type ::}}'
    python_virtualenv_exe: '{{:: venv_python_exe ::}}'
    python_tasks:
    - install-packages
    python_pip_extra_args: '{{:: pip_extra_args ::}}'
    python_pip_packages: '{{:: python_packages ::}}'
    python_pip_packages_state: '{%:: if update ::%}latest{%:: else ::%}present{%::
      endif ::%}'
frecklecute python-packages-in-virtualenv --help

Usage: frecklecute python-packages-in-virtualenv [OPTIONS]

  Installs Python packages into a Virtualenv.

  Don't use this directly (in most cases), just use the 'python-virtualenv'
  frecklet instead, because this frecklet does not create that virtualenv,
  nor does it ensure that Python is available at all.

Options:
  --venv-name VENV_NAME           The name of the virtualenv to set up.
                                  [required]
  --pip-extra-args PIP_EXTRA_ARGS
                                  Extra arguments forwarded to 'pip'.
  -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.
  --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.
# -*- coding: utf-8 -*-


#
# module path: pycklets.python_packages_in_virtualenv.PythonPackagesInVirtualenv
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class PythonPackagesInVirtualenv(AutoPycklet):
    """Installs Python packages into a Virtualenv.

     Don't use this directly (in most cases), just use the 'python-virtualenv' frecklet instead, because this frecklet does not create that virtualenv, nor does it ensure that Python is available at all.

       Args:
         pip_extra_args: Extra arguments forwarded to 'pip'.
         python_packages: All necessary Python packages.
         python_type: How to install Python. Defaults to 'pyenv'.
         python_version: The version of python.
         system_dependencies: System packages the application depends on.
         update: Update packages if already installed.
         user: The user who owns/runs the virtualenv.
         venv_base_path: The path that holds the virtualenv directory.
         venv_name: The name of the virtualenv to set up.
         venv_python_exe: The (optional) path to an existing Python executable to be used for the venv.

    """

    FRECKLET_ID = "python-packages-in-virtualenv"

    pip_extra_args: str = None
    python_packages: List = None
    python_type: str = None
    python_version: str = None
    system_dependencies: List = None
    update: bool = None
    user: str = None
    venv_base_path: str = None
    venv_name: str = None
    venv_python_exe: str = None


    def __post_init__(self):
        super(PythonPackagesInVirtualenv, self).__init__(var_names=["pip_extra_args", "python_packages", "python_type", "python_version", "system_dependencies", "update", "user", "venv_base_path", "venv_name", "venv_python_exe"])


frecklet_class = PythonPackagesInVirtualenv
# -*- coding: utf-8 -*-


#
# module path: pycklets.python_packages_in_virtualenv.PythonPackagesInVirtualenv
#


from pyckles import AutoPycklet

class PythonPackagesInVirtualenv(AutoPycklet):
    """Installs Python packages into a Virtualenv.

     Don't use this directly (in most cases), just use the 'python-virtualenv' frecklet instead, because this frecklet does not create that virtualenv, nor does it ensure that Python is available at all.

       Args:
         pip_extra_args: Extra arguments forwarded to 'pip'.
         python_packages: All necessary Python packages.
         python_type: How to install Python. Defaults to 'pyenv'.
         python_version: The version of python.
         system_dependencies: System packages the application depends on.
         update: Update packages if already installed.
         user: The user who owns/runs the virtualenv.
         venv_base_path: The path that holds the virtualenv directory.
         venv_name: The name of the virtualenv to set up.
         venv_python_exe: The (optional) path to an existing Python executable to be used for the venv.

    """

    FRECKLET_ID = "python-packages-in-virtualenv"

    def __init__(self, pip_extra_args=None, python_packages=None, python_type="pyenv", python_version="latest", system_dependencies=None, update=None, user=None, venv_base_path=None, venv_name=None, venv_python_exe=None):

        super(PythonPackagesInVirtualenv, self).__init__(var_names=["pip_extra_args", "python_packages", "python_type", "python_version", "system_dependencies", "update", "user", "venv_base_path", "venv_name", "venv_python_exe"])
        self._pip_extra_args = pip_extra_args
        self._python_packages = python_packages
        self._python_type = python_type
        self._python_version = python_version
        self._system_dependencies = system_dependencies
        self._update = update
        self._user = user
        self._venv_base_path = venv_base_path
        self._venv_name = venv_name
        self._venv_python_exe = venv_python_exe

    @property
    def pip_extra_args(self):
        return self._pip_extra_args

    @pip_extra_args.setter
    def pip_extra_args(self, pip_extra_args):
        self._pip_extra_args = pip_extra_args

    @property
    def python_packages(self):
        return self._python_packages

    @python_packages.setter
    def python_packages(self, python_packages):
        self._python_packages = python_packages

    @property
    def python_type(self):
        return self._python_type

    @python_type.setter
    def python_type(self, python_type):
        self._python_type = python_type

    @property
    def python_version(self):
        return self._python_version

    @python_version.setter
    def python_version(self, python_version):
        self._python_version = python_version

    @property
    def system_dependencies(self):
        return self._system_dependencies

    @system_dependencies.setter
    def system_dependencies(self, system_dependencies):
        self._system_dependencies = system_dependencies

    @property
    def update(self):
        return self._update

    @update.setter
    def update(self, update):
        self._update = update

    @property
    def user(self):
        return self._user

    @user.setter
    def user(self, user):
        self._user = user

    @property
    def venv_base_path(self):
        return self._venv_base_path

    @venv_base_path.setter
    def venv_base_path(self, venv_base_path):
        self._venv_base_path = venv_base_path

    @property
    def venv_name(self):
        return self._venv_name

    @venv_name.setter
    def venv_name(self, venv_name):
        self._venv_name = venv_name

    @property
    def venv_python_exe(self):
        return self._venv_python_exe

    @venv_python_exe.setter
    def venv_python_exe(self, venv_python_exe):
        self._venv_python_exe = venv_python_exe



frecklet_class = PythonPackagesInVirtualenv