Chemical Curation and Data Management
You'll need the following software installed on your machine to begin development.
Open up a terminal or command prompt for the following.
git clone https://github.com/Chemical-Curation/chemcurator_django.git
cd chemcurator_django
Python 3.8 - Linux and macOS:
python3.8 -m venv .venv
source .venv/bin/activate
Python 3.8 - Windows:
python3.8 -m venv .venv
.venv\Scripts\activate.bat
Conda - Linux and macOS:
conda create -n chemreg python=3.8
source activate chemreg
Conda - Windows:
conda create -n chemreg python=3.8
activate chemreg
If you are on Windows, you will likely need the Microsoft Visual C++ 14.0 build tools
Install the Python requirements from the file w/in the /chemcurator_django
repository:
pip install -r requirements.txt
Make a copy of the "template.env" file and name it ".env". Change the uncommented attribute in .env
to hold the following:
DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/chemreg
Note: A line in your .env preceded by "#" will be ignored.
Note: These may take a while the first time you run them.
chemcurator_default
network...docker run \
--volume=postgresql:/var/lib/postgres/data \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=chemreg \
--name=postgresql \
--network=chemcurator_default \
--publish "5432:5432" \
--detach \
postgres:12.1
docker run \
--volume=pgadmin4:/var/lib/pgadmin \
-e "PGADMIN_DEFAULT_EMAIL=dev@epa.gov" \
-e "PGADMIN_DEFAULT_PASSWORD=postgres" \
-e "PGADMIN_LISTEN_PORT=5047" \
--name=pgadmin4 \
--network=chemcurator_default \
--publish="5432:5432" \
--detach \
dpage/pgadmin4
Note: When adding a server to pgadmin4, use the postgres container name
postgresql
instead oflocalhost
docker network create --driver=bridge pgnetwork
docker run --publish 5432:5432 --volume=postgresql:/var/lib/postgres/data -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=chemreg --name=postgresql --network=pgnetwork --detach postgres:12.1
docker run --publish 5047:80 --volume=pgadmin4:/var/lib/pgadmin -e "PGADMIN_DEFAULT_EMAIL=dev@epa.gov" -e "PGADMIN_DEFAULT_PASSWORD=postgres" --name=pgadmin4 --network=pgnetwork --detach dpage/pgadmin4
This will initialize your git repository to run the .pre-commit-config.yaml
whenever you go to commit changes.
pre-commit install
python manage.py migrate
Note: The variable URL_CONF
variable in the .env file can be set to show admin
or api
urls. Be sure to set it appropriately before starting up the runserver.
For example, to run the API on port 8000 and the admin application on 8001:
python manage.py runserver 8000
(macOS syntax)
URL_CONF=admin python manage.py runserver 8001
(Windows syntax)
set URL_CONF=admin
or
$env:URL_CONF = 'admin'
Then
python manage.py runserver 8001
You can now go to your browser and visit http://127.0.0.1:8000/
to see what the runserver is serving. And for to inspect the DB with the PGAdmin4 container visit http://localhost:5047/
and when prompted to sign in use the variables entered above when starting the container which are:
dev@epa.gov
postgres
You can then right-click on "Servers" on the left and then provide a name in the "General" tab and then use the credentials used in the docker containerlocalhost
; if using pgnetwork postgresql
postgres
postgres
We follow a code-style defined by the default settings of black
. It automatically formats your code. The isort
package handles the structure of imports in .py
files. flake8
is used for PEP8 compliance. Tests will fail if this is not done. To format your code changes, run:
python manage.py lint
Note: The pre-commit hooks installed above will prevent a commit before this is done if any formatting is needed.
We use the Google style-guide for docstrings. Try to write good docstrings as you write functions.
The sphinx-autoapi
package automatically crawls the source code and outputs the docs.
To build the documentation:
cd docs/
sphinx-build -b html . _build