Studio starter for Python / Django applications that deals with TIME_ZONE issues

Here is a working starting point for a .studiorc you can drop into a Python / Django project. You’ll want to add .venv/ to your .gitignore too. This includes patching the Python environment so it can find timezone data.

#!/bin/bash


# prevent supervisor from starting
echo
echo "--> Disabling studio supervisor..."
export HAB_STUDIO_SUP=false


# install environmental dependencies
echo
echo "--> Installing environmental dependencies..."

hab pkg binlink -d /usr/bin core/coreutils env

hab pkg install core/tzdata
export ZONEINFO="$(hab pkg path core/tzdata)/share/zoneinfo"

hab pkg install -b core/python
pip install --upgrade pip


# prepare workspace
echo
echo "--> Preparing python workspace..."
pushd "/src" > /dev/null

    # setup venv
    python3 -m venv .venv

    # fix timezone
    ZONEINFO_ESCAPED="$(echo "${ZONEINFO}" | sed 's/\//\\\//g')" # prepare for use as sed replacement
    sed -i "s/zoneinfo_root = Path('\/usr\/share\/zoneinfo')/zoneinfo_root = Path('${ZONEINFO_ESCAPED}')/g" .venv/lib/python*/site-packages/django/conf/__init__.py

    # activate environment
    source .venv/bin/activate
    pip install -r requirements.txt

    # generate database if needed
    ./manage.py migrate

popd > /dev/null


# set up studio commands
echo
echo "--> Setting up studio commands"

echo "    * Use 'app-run' to run the app for testing"
app-run() {
    pushd "/src" > /dev/null

    ./manage.py runserver

    popd > /dev/null
}