mitodl / mitxpro

BSD 3-Clause "New" or "Revised" License
12 stars 2 forks source link

mitxpro

SECTIONS

  1. Initial Setup
  2. Optional Setup

Initial Setup

mitxpro follows the same initial setup steps outlined in the common ODL web app guide. Run through those steps including the addition of /etc/hosts aliases and the optional step for running the createsuperuser command.

Configure xPro and Open edX

  1. See Configure Open edX
  2. Add an alias to /etc/hosts for Open edX. We have standardized this alias to edx.odl.local. Your /etc/hosts entry should look like this:

    127.0.0.1       edx.odl.local

Add settings values

Add the following settings in your .env file:

MAILGUN_RECIPIENT_OVERRIDE=<your email address>

# Ask a fellow developer for these values
MAILGUN_SENDER_DOMAIN=
MAILGUN_KEY=

OS-specific settings to add to your .env file:

### Linux
# EDX_IP should be something like 172.22.0.1
OPENEDX_API_BASE_URL=http://$EDX_IP:18000

### OSX
OPENEDX_API_BASE_URL=http://docker.for.mac.localhost:18000
OPENEDX_BASE_REDIRECT_URL=http://edx.odl.local:18000

Configure Wagtail (CMS)

There are a few changes that must be made to the CMS for the site to be usable. You can apply all of those changes by running a management command:

docker-compose run --rm web ./manage.py configure_wagtail

Optional Setup

Described below are some setup steps that are not strictly necessary for running the app

Running tests

NOTE: These commands can be run with docker-compose exec to execute them in an already-running container, or with docker-compose run --rm to execute them in a new container.

### PYTHON TESTS/LINTING
# Run Python tests

docker-compose run --rm web pytest
# Run Python tests in a single file
docker-compose run --rm web pytest /path/to/test.py
# Run Python test cases in a single file that match some function/class name
docker-compose run --rm web pytest /path/to/test.py -k test_some_logic
# Run Python linter
docker-compose run --rm web ruff check .

### PYTHON FORMATTING
# Format all python files
docker-compose run --rm web ruff format --check .
# Format a specific file
docker-compose run --rm ruff format --check /path/to/file.py

### JS/CSS TESTS/LINTING
# We also include a helper script to execute JS tests in most of our projects
docker-compose run --rm watch ./scripts/test/js_test.sh
# Run JS tests in specific file
docker-compose run --rm watch ./scripts/test/js_test.sh path/to/file.js
# Run JS tests in specific file with a description that matches some text
docker-compose run --rm watch ./scripts/test/js_test.sh path/to/file.js "should test basic arithmetic"
# Run the JS linter
docker-compose run --rm watch npm run lint
# Run SCSS linter
docker-compose run --rm watch npm run scss_lint
# Run the Flow type checker
docker-compose run --rm watch npm run-script flow

# Run prettier-eslint, fixes style issues that may be causing the build to fail
docker-compose run --rm watch npm run fmt

Seed data

Seed data can be generated via management command. It's designed to be idempotent, so running it multiple times should not create multiple sets of data.

docker-compose run --rm web ./manage.py seed_data
# To delete seed data
docker-compose run --rm web ./manage.py delete_seed_data

Running the app in a notebook

This repo includes a config for running a Jupyter notebook in a Docker container. This enables you to do in a Jupyter notebook anything you might otherwise do in a Django shell. To get started:

From there, you should be able to run code snippets with a live Django app just like you would in a Django shell.

Hubspot integration

Commits

To ensure commits to github are safe, you should install the following first:

pip install pre_commit
pre-commit install

To automatically install precommit hooks when cloning a repo, you can run this:

git config --global init.templateDir ~/.git-template
pre-commit init-templatedir ~/.git-template

Updating python dependencies

Python dependencies are managed with poetry. If you need to add a new dependency, run this command:

docker compose run --rm web poetry add <dependency>

This will update the pyproject.toml and poetry.lock files. Then run docker-compose build web celery to make the change permanent in your docker images. Refer to the poetry documentation for particulars about specifying versions, removing dependencies, etc.