python-lang-installed

Example:

# Install Python version 3.6.8 for user 'freckles', using 'pyenv'.
- python-lang-installed:
    version: 3.6.8
    user: freckles

Description

Install a Python environment for a user, using pyenv or system packages.

If using 'pyenv', this will install all dependencies required to build Python, then it will download the specified version of Python, compile it, and use the 'pyenv global' command (which will write that information into the file $HOME/.pyenv/version) to make it the default version for the user.

If Python type is 'pyenv', this will add a piece of code to $HOME/.bashrc to load pyenv when the user logs in.

Resources

Variables

Name Type Default Description

build_opts

string --

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

python_type

string pyenv

How to install Python.

user

string --

The user to install Python for.

version

n/a latest

The version of Python to install.

Examples

Example 1

Install Python version 3.6.8 for user 'freckles', using 'pyenv'.

Code
- python-lang-installed:
    version: 3.6.8
    user: freckles

Example 2

Install the latest version of Python using 'pyenv'.

Code
- python-lang-installed

Example 3

Install system Python, version 2

Code
- python-lang-installed:
    version: 2
    python_type: system

Code

doc:
  short_help: Install a Python runtime for a user.
  help: |
    Install a Python environment for a user, using [pyenv](https://github.com/pyenv/pyenv) or system packages.

    If using 'pyenv', this will install all dependencies required to build Python, then it will download the specified version of Python,
    compile it, and use the 'pyenv global' command (which will write that information into the file $HOME/.pyenv/version)
    to make it the default version for the user.

    If Python type is 'pyenv', this will add a piece of code to ``$HOME/.bashrc`` to load pyenv when the user logs in.

  references:
    pyenv homepage: https://github.com/pyenv/pyenv
  examples:
  - title: Install Python version 3.6.8 for user 'freckles', using 'pyenv'.
    vars:
      version: 3.6.8
      user: freckles
  - title: Install the latest version of Python using 'pyenv'.
  - title: Install system Python, version 2
    vars:
      version: 2
      python_type: system

args:
  version:
    doc:
      short_help: The version of Python to install.
    default: latest
    required: true
  user:
    doc:
      short_help: The user to install Python for.
    type: string
    required: false
  path:
    doc:
      short_help: The path to install pyenv into.
      help: |
        Defaults to $HOME/.pyenv
    type: string
    required: false
#  set_global:
#    doc:
#      short_help: Don't set 'global' version.
#    type: boolean
#    required: false
#    default: true
  python_type:
    doc:
      short_help: How to install Python.
    type: string
    required: false
    default: pyenv
    allowed:
    - pyenv
#      - "conda"
    - system
  build_opts:
    doc:
      short_help: Build options to be forwarded (if supported by 'python_type').
    type: string
    required: false
    empty: true

frecklets:
- user-exists:
    frecklet::skip: '{{:: user | true_if_empty ::}}'
    name: '{{:: user ::}}'
#  - package-installed:
#      package: git
- frecklet:
    name: freckfrackery.python
    type: ansible-role
    resources:
      ansible-role:
      - freckfrackery.python
      - freckfrackery.install-pkgs
      - freckfrackery.install-pkg-mgrs
      - geerlingguy.homebrew
      - elliotweiser.osx-command-line-tools
    properties:
      idempotent: true
      internet: true
        # elevated: "{%:: if user or python_type == 'system' ::%}true{%:: else ::%}false{%:: endif ::%}"
      elevated: true   # because of pyenv dependencies
    desc:
      references:
        pyenv homepage: https://github.com/pyenv/pyenv
  task:
    include-type: include
  vars:
    python_owner: '{{:: user ::}}'
    python_build_opts: '{{:: build_opts ::}}'
    python_type: '{{:: python_type ::}}'
    python_version: '{{:: version ::}}'
    python_tasks: [install-python]
frecklecute python-lang-installed --help

Usage: frecklecute python-lang-installed [OPTIONS]

  Install a Python environment for a user, using
  [pyenv](https://github.com/pyenv/pyenv) or system packages.

  If using 'pyenv', this will install all dependencies required to build
  Python, then it will download the specified version of Python, compile it,
  and use the 'pyenv global' command (which will write that information into
  the file $HOME/.pyenv/version) to make it the default version for the
  user.

  If Python type is 'pyenv', this will add a piece of code to
  ``$HOME/.bashrc`` to load pyenv when the user logs in.

Options:
  --build-opts BUILD_OPTS    Build options to be forwarded (if supported by
                             'python_type').
  --python-type PYTHON_TYPE  How to install Python.
  --user USER                The user to install Python for.
  --version VERSION          The version of Python to install.
  --help                     Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.python_lang_installed.PythonLangInstalled
#


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

@dataclass
class PythonLangInstalled(AutoPycklet):
    """Install a Python environment for a user, using [pyenv](https://github.com/pyenv/pyenv) or system packages.

     If using 'pyenv', this will install all dependencies required to build Python, then it will download the specified version of Python,
     compile it, and use the 'pyenv global' command (which will write that information into the file $HOME/.pyenv/version)
     to make it the default version for the user.

     If Python type is 'pyenv', this will add a piece of code to ``$HOME/.bashrc`` to load pyenv when the user logs in.

       Args:
         build_opts: Build options to be forwarded (if supported by 'python_type').
         python_type: How to install Python.
         user: The user to install Python for.
         version: The version of Python to install.

    """

    FRECKLET_ID = "python-lang-installed"

    build_opts: str = None
    python_type: str = None
    user: str = None
    version: str = None


    def __post_init__(self):
        super(PythonLangInstalled, self).__init__(var_names=["build_opts", "python_type", "user", "version"])


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


#
# module path: pycklets.python_lang_installed.PythonLangInstalled
#


from pyckles import AutoPycklet

class PythonLangInstalled(AutoPycklet):
    """Install a Python environment for a user, using [pyenv](https://github.com/pyenv/pyenv) or system packages.

     If using 'pyenv', this will install all dependencies required to build Python, then it will download the specified version of Python,
     compile it, and use the 'pyenv global' command (which will write that information into the file $HOME/.pyenv/version)
     to make it the default version for the user.

     If Python type is 'pyenv', this will add a piece of code to ``$HOME/.bashrc`` to load pyenv when the user logs in.

       Args:
         build_opts: Build options to be forwarded (if supported by 'python_type').
         python_type: How to install Python.
         user: The user to install Python for.
         version: The version of Python to install.

    """

    FRECKLET_ID = "python-lang-installed"

    def __init__(self, build_opts=None, python_type="pyenv", user=None, version="latest"):

        super(PythonLangInstalled, self).__init__(var_names=["build_opts", "python_type", "user", "version"])
        self._build_opts = build_opts
        self._python_type = python_type
        self._user = user
        self._version = version

    @property
    def build_opts(self):
        return self._build_opts

    @build_opts.setter
    def build_opts(self, build_opts):
        self._build_opts = build_opts

    @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 user(self):
        return self._user

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

    @property
    def version(self):
        return self._version

    @version.setter
    def version(self, version):
        self._version = version



frecklet_class = PythonLangInstalled