Prerequisites
- Make: https://www.gnu.org/software/make/
- Poetry: https://python-poetry.org/
- Docker: https://www.docker.com/
- Pre-commit: https://pre-commit.com/
- psycopg2 build prerequisites
To set up dependencies necessary for local development, run:
make installpoetry run pre-commit installYou should get the following response after installing pre-commit into the githooks:
pre-commit installed at .git/hooks/pre-commit
Reinstall the pre-commit hooks when there are changes to the .pre-commit-config.yaml file.
Run the following to check all files
poetry run pre-commit run --all-filesThe option --no-verify allows a committer to bypass the hooks when committing:
git commit --no-verifyLinux users will want to set the user ID and group ID used in the container. Users of Docker Desktop for Mac or Windows can skip this step.
Create a .env environment file, if it isn't already created:
make .envEdit this file, and set these variables:
CTMS_UID=1000
CTMS_GID=1000Set these to your user ID and group ID. These commands might return them:
id -u # Your user ID
id -g # Your group IDTo create or recreate a database with empty tables:
make setupTo create a new migration file based on updated SQLAlchemy models:
make shell # To enter the web container
alembic revision --autogenerate -m "A short description of the change"
black /app/migrations/versions/
exitEdit the generated migration script, confirm it does what you meant, and adjust or delete and recreate as needed.
To run this and other migrations on an existing database:
make shell # Enter the web container
alembic upgrade head
exitThe tool adminer is included as postgres-admin,
allowing you to view the database in the development environment. To start it:
docker compose up -d postgres-adminThe adminer website runs at http://localhost:8080. Log in with these credentials:
- System: PostgreSQL (from dropdown)
- Server:
postgres - Username:
postgres - Password:
postgres - Database:
postgres
The API uses OAuth 2 Client Credentials for authentication. To generate credentials for your development environment use the CTMS CLI:
make shell # Enter the web container
ctms-cli clients create <client_id> <email>This will print out new client credentials, such as:
** 🔑 Client Credentials -- Store Securely! 🔑 **
- Client ID: id_test
- Client Secret: secret_JKaKrCCeIucEANisI-z-m4TTTO27ML-TELe2gezWDTI
You can use these on the interactive Swagger docs by clicking the "Authorize" button.
CTMS is a Python application. We tend to keep the application up to date with the latest version of Python -- we pin to the patch version throughout the repository.
Dependabot will submit pull requests to update the Python version in the
Dockerfile, but will miss other places like pyproject.toml and Github Action
workflow files. This sed1 snippet will find/replace all Python versions in
one go - in this example, from version A.B.C to X.Y.Z:
git ls-files | xargs sed -i 's/A\.B\.C/X\.Y\.Z/g'Manually inspect the changes to filter out false positives.
Poetry is pinned to a specific version in a few places throughout the
repository. This sed1 snippet will find/replace all of these insances in
one go - in this example, from version A.B.C to X.Y.Z:
git ls-files | xargs sed -i 's/A\.B\.C/X\.Y\.Z/g'Manually inspect the changes to filter out false positives.