Skip to content

Development Environment Setup

Yuxin David Huang edited this page Oct 6, 2020 · 3 revisions

Introduction

Welcome to the Development Environment Setup page! This page is intended for those who desire step-by-step instructions to setup a development environment on their own machine. Most instructions will be for MacOS; other versions incoming.

Software

Required

  • PostgreSQL > 9.6 (backend database)
  • redis (asynchronous messaging for job queues)

Recommended

  • IntelliJ IDEA
    • Our team uses this IDE internally, and the instructions will gear towards IDEA. Please adapt any IDEA-specific instructions to your preferred IDE/code editor/manual steps.

Step-by-step Instructions

First, install the required software.

Installing required software

PostgreSQL

There are two options: you can either directly download the installing package, or get it through a package manager like Homebrew.

  • Direct download

    • The official PostgreSQL download page will have links to download the installer according to your OS version.
    • Install PostgreSQL once the installer is downloaded.
  • Package manager (Homebrew)

    Instructions here are adapted from this tutorial.

    $ brew install postgresql
    

    Once the installation finishes, you can then simply run

    $ postgres -D /usr/local/var/postgres
    

    This will initialize a default database in the directory /usr/local/var/postgres. To have PostgreSQL run on system startup, do

    $ brew services start postgresql
    

redis

Like PostgreSQL, you can either do a direct download or get it from a package manager.

  • Direct download
  • Package manager
    $ brew install redis
    <install output...>
    $ brew services start redis
    

(Optional) Installing IntelliJ IDEA

Download page

It is recommended that you get the Ultimate version if you can. If not, the Community version should suffice.

Misc.

To check that both PostgreSQL and redis is running (or whether you already have them installed), do

$ brew services

This will list all services running through Homebrew, and you can check whether postgresql and redis are started or not. grep if you have many Homebrew-managed services.

Setting up IntelliJ IDEA/your preferred IDE

Please adapt the instructions if you don't use IDEA. Most modern IDEs will have similar functions.

  • Install pipenv if not installed
  • Project settings -> SDK Setup, Use pipenv as SDK
  • Make sure module forecast_repo is using pipenv SDK
  • Get local_postgres.env and local_sqlite3.env into root repo directory (acquire these files with the dev team)
  • Connect to PostgreSQL with default user, create forecast-repo database
  • (on MacOS) PostgreSQL should come with a superuser with your username; go to forecast_repo/settings/local_postgres.py, change username to your superuser username. If not, create a new user using the createuser command and use that as your superuser username.
  • Install EnvFile plugin in IntelliJ IDEA
  • Make several run configurations:
    • manage.py-migrate-postgres
      • Script path: <your local repository location>/manage.py
      • Parameters: migrate
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab (should show up after installing the plugin)
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-runserver-postgres
      • Script path: <your local repository location>/manage.py
      • Parameters: runserver
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-rqworker-postgres
      • Script path: <your local repository location>/manage.py
      • Parameters: rqworker high default low --settings=forecast_repo.settings.local_postgres
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-test-postgres
      • Script path: <your local repository location>/manage.py
      • Parameters: test --verbosity 2
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-test-individual-postgres (optional, for running individual tests)
      • Script path: <your local repository location>/manage.py
      • Parameters: test <specify individual test method using dot notation> --verbosity 2
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-test-individual-postgres (optional, for running individual tests)
      • Script path: <your local repository location>/manage.py
      • Parameters: test <specify individual test method using dot notation> --verbosity 2
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-score-postgres
      • Script path: <your local repository location>/utils/score_util.py
      • Parameters: update --score-pk=<primary key of the score> --model-pk=<primary key of the model> --no-enqueue
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • manage.py-test-sqlite
      • Script path: <your local repository location>/utils/score_util.py
      • Parameters: test --verbosity 2
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-sqlite3.env to the enabled list
    • temp_app.py-postgres (optional, if you want to try certain things out)
      • Script path: <your local repository location>/temp_app.py
      • Parameters: none
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
    • make_minimal_projects
      • Script path: <your local repository location>/utils/make_minimal_projects.py
      • Parameters: none
      • Python interpreter: use specified interpreter with the pipenv virtual environment
      • Working directory: <root repository directory>
      • EnvFile tab
        • Enable EnvFile, and add the local-postgres.env to the enabled list
  • Create a superuser:
    $ python3 manage.py createsuperuser --settings=forecast_repo.settings.local_postgres
    
    then follow the prompts to create a super user. This will allow you to login as a super user on your local instance of Zoltar.

First-time setup

  1. Run the migrate run configuration. This will setup the forecast_repo database in PostgreSQL.
  2. Run the make_minimal_project run configuration. This will setup an example project for Zoltar to show.

Typical workflow

  • Run the runserver and rqworker run configuration to view a local Zoltar instance.
  • Run the test run configuration to run all tests.
  • Run the test-individual run configuration (specifying a test to run) to run an individual test.

Conclusion

You should be all set to develop! If you have any questions please contact the dev team.