Contrast api repo
Relevant docs:
We believe in open-science! The data is licensed under CC-BY-SA-4.0 creative commons open license and the code here under the GNU GPLv3 open source license
see CONTRIBUTING
python 3.10 Django + drf + django-filter DB is postgresql Django configurations for settings file Common practice middlewares (timezones, querycount)
-
Python virtual environment:
We are using poetry to manage the projects dependencies.
Install Poetry - https://python-poetry.org/docs/#installation -
Get the code:
Clone this projectgit clone git@github.com:Mudrik-Lab/Contrast2.git
-
Install dependencies:
enter projects directory and install dependencies using Poetry. Poetry will look for pyproject.toml filecd contrast-api poetry install
And enter the virtual env created by Poetry:
poetry shell
From this point in the setup you should run the commands while you are inside the virtual env / poetry shell
-
Database:
We are currently using postgres. You need to set up a user,- After you have installed postgres, enter postgres cli client:
sudo su - postgres psql
- create a database, a user and a role
CREATE DATABASE contrast_api_db; CREATE USER contrast_api_user WITH PASSWORD 'contrast_api_pass'; ALTER ROLE contrast_api_user SET client_encoding TO 'utf8'; GRANT ALL PRIVILEGES ON DATABASE contrast_api_db TO contrast_api_user; ALTER ROLE contrast_api_user CREATEDB; ALTER DATABASE contrast_api_db OWNER TO contrast_api_user;
-
to exit postgres cli:
Ctrl+D
and then exit superuser shell
exit
-
Now you can migrate the data:
python manage.py migrate
-
To load the pre-existing data you need to: 6.
- Download this file in .xlsx format for ConTrast, or
- Download this file in .xlsx format for UnConTrast
-
- Save the file in
/studies/data
directory for ConTrast, or - Save the file in
/uncontrast_studies/data
directory for UnConTrast
- Save the file in
-
-
Run this command for ConTrast:
python manage.py load_historic_data
-
Run this command for UnConTrast:
python manage.py load_uncon_data
-
Note: if you need to do this in bash (for example when migrating on the server): 1. Copy the file to your drive and temporarily allow open access to viewer to view 2. Follow the technique here 6. Create a superuser for yourself to start working
python manage.py createsuperuser
- Run the dev server
python manage.py runserver
poetry run python manage.py test
Currently this project is deployed to Heroku, via github actions ci
e.g when you work on the frontend
docker-compose up --build
# or to run in the background
docker-compose up -d --build
# You might drop --build, in case no changes in the poetry.lock file, but I'd suggest not to
First run would be quite long because of docker building
Postgres has some issues currently with start order, so if you see errors in the logs, just restart the compose a few times until it work
For doing the initial data load while running in compose:
After copying the file as above, and after verifying compose up --build as above
docker exec -it web_contrast_api python manage.py load_historic_data
# This runs the load, but inside the already running containers
As part of deploying this app we also deploy a separately build react app, and serve it from the django project with django-spa.
With ruff, not automated yet as part of CI
ruff check . --fix
ruff format
We're using ruff format
for formatting please adjust prs accordingly