Python

freckles is written in Python, which is why there are already a few frecklets to be used in combination with Python projects available.

Installing Python

There are several ways to ensure Python is available on a machine. Most likely one would want to use the system Python, but sometimes a specific version of Python is required, in which case pyenv is a good option.

Python 3 (system packages)

This installs whichever Python 3 version is available in the current platforms package manager.

# run with: freckles <this_file>
- python-lang-installed:
    python_version: 3
    python-type: system
frecklecute python-lang-installed \
   --version 3 \
   --python-type system

Python 3.7.3 (pyenv)

This will install pyenv for the current user (use the 'user' variable to change that) -- if not available yet -- and then downloads, compiles and installs Python version 3.7.3. The next time the user logs in, pyenv will be available in its path, and the user can use that version of Python (e.g. via 'pyenv global 3.7.3 -- read the pyenv documentation for details).

# run with: freckles <this_file>
- python-lang-installed:
    python_version: 3.7.3
    python-type: pyenv
frecklecute \
   python-lang-installed \
   --version 3.7.3 \
   --python-type pyenv

Note: Root permissions are needed to install the build dependencies for pyenv.

frecklets used:

Virtualenv with pyenv

In this example, we let freckles install pyenv if necessary, then use it to install a specific version on Python (again, if not already present).

After this, a virtualenv called 'cookiecutter' is created using the Python we just installed, and the cookiecutter Python package is installed into that virtualenv via PyPi.

# run with: freckles <this_file>
- python-virtualenv:
    user: my-python-user
    python_version: 3.6.8
    venv_name: cookiecutter
    python_packages:
     - cookiecutter
frecklecute \
   python-virtualenv \
   --user my-python-user \
   --python-version 3.6.8 \
   --venv-name cookiecutter \
   -p cookiecutter

frecklets used:

freckles dev environment

This shows how to use one command to setup a Python project environment to work on the freckles project itself. It can be used as an example on how to setup any Python development project though.

# run with: freckles <this_file>
- freckles-dev-project:
    project_base: /home/markus/projects/freckles-dev
frecklecute \
   freckles-dev-project \
   --project-base /home/markus/projects/freckles-dev

Note: This is a fairly opinionated way of installing a Python project (there are just too many options), and uses pyenv to install Python (which takes a while because it is compiled from sources) and the virtualenv used. Of course, if you have different opinions on how to do such a thing, freckles makes it easy to prepare a recipe for those too!

Another note: On Mac OS X, this frecklet installs the OS X command-line tools, so git is usable. Also, the pyenv install adds two lines to ~/.bashrc to make pyenv avaliable after login. Your machine needs to be configure to read this for it to work.

frecklets used:

More examples

frecklets that either show how to use freckles for Python-related tasks, or install Python-related software:

python-gunicorn-service
Creates a virtualenv and installs specified packages as well as gunicorn, creates a systemd-service unit for it and makes sure service is enabled and started.
python-virtualenv-execute-shell
Executes a command in the context of an (existing) virtualenv.
devpi-standalone
Installs a devpi Python package repository service (incl. Nginx proxy & LetsEncrypt certificate).
airflow-service
Installs an Airflow service on a machine (work in progress).
superset-standalone
Installs a standalone Superset business intelligence service.