Developer Workstation Setup


Server Settings

System settings in das are defined by two mechanisms:

  1. The Django settings system, which defines the baseline system settings

    • This includes a series of settings.py files and an .env file, which you must create when setting up your local environment.

  2. The Tenant Management Service (TMS), which augments individual sites with their specific settings.

    • This is preloaded for local development using fixtures generated during the loaddata phase of local developer installation. You don’t have to run the TMS locally.

Override settings using “.env” file

You must create your .env file. Copy the .env.template file from das into das/das and rename it to .env.

Modify that .env as needed, such as changing the FQDN to wherever you run your server (typically localhost). Most of the defaults from .env.template should be correct for an out-of-the-box setup following this guide.

Ensure these values are in your .env file:

DB_PASSWORD=das
GEOS_LIBRARY_PATH= #one of these VALUES:
# /usr/lib/x86_64-linux-gnu/libgeos_c.so.1 IF YOU ARE ON AN X86_64 ARCHITECTURE CHIP
# /usr/lib/aarch64-linux-gnu/libgeos_c.so.1 IF YOU ARE ON AN ARM ARCHITECTURE CHIP
# hint, when running on an ARM system the GEOS path would be
# GEOS_LIBRARY_PATH='/usr/lib/aarch64-linux-gnu/libgeos_c.so.1'
FQDN=localhost # unless you've configured your host otherwise
# without TMS, we load tenant settings from local data.
# comment out TMS_API_CLIENT and TENANT_ID if you have TMS configured
TMS_API_CLIENT="core.tms.DjangoSettingsClient"
# develop.pamdas.org tenant id
TENANT_ID="28bf3d60-195f-41c7-ad75-d249d4d32430"
MEMORY_STORE_CLIENT="utils.persistent.RedisStorage"
MEMORY_STORE_HOST="host.docker.internal" #this connects to the local redis container instead of the TMS Memorystore redis instance used in production deployments
MEMORY_STORE_PORT=6379
MEMORY_STORE_DATABASE=4
GITGUARDIAN_API_KEY="<your key here>" # the API key from your GitGuardian account when you set up your pre-commit hooks
GITGUARDIAN_DOTENV_PATH=/workspaces/das/das/.env # set a shell environment variable for the pre-commit ggshield library to find

Our advanced local development setup has pgcat configured. If you decide to simplify things, add the following to your .env file, to instruct our Django settings to use the simple brew installed postgresql server.

DB_POOLER_NAME=das
DB_POOLER_HOST=host.docker.internal
DB_POOLER_PORT=5432

For environments outside OSX:

DB_HOST=postgis
MEMORY_STORE_HOST="redis"
REDIS_HOST="redis"

Extra info about how our Django settings work:

The primary Django settings exist in the das_server app (das/das/das_server), which is the project’s root Django app.

  • das_server/settings.py - primary settings file. It contains default settings, and additionally loads environment variables to update some defaults.

  • das_server/local_settings_docker.py - these inherit from settings.py. This django_settings_module is used in our kubernetes pod deployments. Kubernetes secrets and configmap is used to inject environment variables into the running pods.

  • test_scripts/unittest_settings.py - used by our CI unit test runner in CircleCI, executing in a docker compose-built environment. This settings file inherits from local_settings_docker, loading environment variables and overriding a few settings in this file.

To avoid mixing up settings between development and testing environments, use the VSCode launch tasks available for running pieces of the stack in development and testing modes.


Set up pre-commit hooks

  1. Install pre-commit libraries and establish the git hooks: pre-commit install

    • To manually run pre-commit: pre-commit run --all-files

    • To update pre-commit: pre-commit autoupdate

  2. Install GitGuardian (GG) by following this documentation to detect secrets before they are pushed.

    • Once installed, authorize ggshield by running ggshield auth login

      • You will have to set up a GG account if you don’t have one already.

      • In addition to a pre-commit hook for GG, you can manually trigger a repo scan at any time by executing this command: ggshield secret scan repo /path/to/your/repo

      • Add the appropriate GG variable values to the .env file as described in the Server Settings section.

Run Redis and Database in containers

The project has a Makefile in the root directory with a single task:

  • start: Start storage containers (redis and postgres)

Run with: make start at project root directory.

Daily development task examples

I finish my changes, want to run new/existing unit tests

  • If it is the first time running unit tests through VSCode, you must first run the VSCode task: PyTest --createdb. This will create a new database called test_das to be used in future tests and avoid the creation of a db every time. (Remember to run this task again if you made changes with migrations.)

  • Run PyTest - this launches a prompt to write your desired path of test. If you want to hard code the path for a while, just click on the gear next to the task and change the last line in args property and overwrite ${input:pytest_path_args} with your desired path (don’t commit the file launch.json).

I want to run a manage.py command

You have two options:

  1. Run Django manage command task and write the command in the prompt

  2. If your command has arguments or something special, edit Django manage command - click on the gear next to the name and overwrite the args property:

    "args": [
        "${input:django_command}",
        "${input:django_command_args}"
    ],
    

    with your desired command:

    "args": [
        "makemigrations", "activity", "--empty"
    ],
    

    Remember to not commit launch.json changes.

I want to use another text editor

PyCharm

Francisco helped set up PyCharm and can help you too.

Neovim

Arthur and Francisco are neovim users and have successfully set up the project to work with neovim using the devcontainer and devpod.


Mac Native Install (alternative to devcontainer)

Here we are running the das project on bare metal, rather than in a docker container. Prepare for some fiddling to get the project running. This is not recommended for a straightforward install. Prefer using the docker approach in VS Code.

1. Install Brew

Brew makes it easy to install the necessary libraries to run the ER stack locally. Download brew here.

2. Install Python 3.10 in a venv using uv

  1. brew install uv

  2. cd das (into the directory you cloned the das repo)

  3. uv venv --python=3.10 .venv

  4. source .venv/bin/activate

  5. Notes: be sure there is no .python-version file in the root directory

3. Install GDAL, libproj and geos

brew install gdal
brew install proj
brew install geos

4. Install Project Dependencies

Use uv to install the requirements. Requirements are found in pyproject.toml, and are pinned in uv.lock.

uv sync --group dev

5. Set GEOS Path in .env

See the Server Settings section on your local .env file.

Other Mac Utilities

  • oh my zsh - handy utility for managing your zsh