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 install
poetry run pre-commit install
You 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-files
The option --no-verify
allows a committer to bypass the hooks when committing:
git commit --no-verify
Linux 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 .env
Edit this file, and set these variables:
CTMS_UID=1000
CTMS_GID=1000
Set these to your user ID and group ID. These commands might return them:
id -u # Your user ID
id -g # Your group ID
To create or recreate a database with empty tables:
make setup
To 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/
exit
Edit 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
exit
The 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-admin
The 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:
make shell # Enter the web container
ctms/bin/client_credentials.py test --email test@example.com
This will print out new client credentials, such as:
Your OAuth2 client credentials are:
client_id: id_test
client_secret: secret_dGhpcyBpcyBubyBzZWNyZXQu
...
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 sed
1 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 sed
1 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.