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.


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

# install environmental dependencies
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 "--> 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/

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

    # generate database if needed
    ./ migrate

popd > /dev/null

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

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

    ./ runserver

    popd > /dev/null