Skip to content

Local Development in PHDI Containers

Amy Kintner edited this page Nov 18, 2024 · 1 revision

Getting Started

You will need Python 3.9 or higher as well as a python package manager(we mostly use pip).

Containers

Each of our containers has instructions on running locally in their README.md, and you can run them run using Docker, any other OCI container runtime (e.g., Podman), or directly from the Python source code.

Most packages in this repo use Docker containers for development to keep the various requirements isolated in the container they're imported for without impacting other code or virtual environments. Confirm that you have Docker installed by running docker -v. If you don't see a response similar to what's shown below, follow these instructions to install Docker.

❯ docker -v
Docker version 20.10.21, build baeda1f

You can also run containers from the source code using any virtual environment manager you like, but a number of team members use pyenv-virtualenv. One of the nice features of virtualenv is that you can set a different virtual environment per directory (i.e. fhir-converter/, validation/, etc), and when you leave that directory the virtualenv automatically deactivates.

Starting the virtual env & container

cd containers/$service

pyenv virtualenv $virtual-environment-name

pyenv local $virtual-environment-name

pip install -r requirements.txt

uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload

To stop an existing virtual environment

cd containers

pyenv virtualenvs #lists virtual environments

pyenv deactivate $virtual-environment-name

pyenv virtualenv-delete $virtual-environment-name

You might also need to manually delete the .python-version file in your container directory.

SDK

There isn't a way to "run" the SDK aside from unit tests. See Testing the SDK Locally.

Formatting & pre-commit hooks

The team uses Black and Flake8 for Python formatting.

These formatters run as a PR check in Github, but for your convenience you can run them as a pre-commit hook.

To set up the pre-commit hook (only needs to be run once, in the repo):

pip install pre-commit
pre-commit install

Our pre-commit-config will now run each time you attempt a git commit. If there are failures, you'll need to address these and re-commit.

To bypass the commit hook, run with --no-verify: git commit -am "some very important change" --no-verify

For more information, see the pre-commit docs.