Basic utilities for the MIT Cave App.
This package is intended to be used by the Cave App and the Cave API.
This package is part of the larger Cave App framework. It provides utilities that are commonly used across different Cave applications, such as validation and logging. It is designed to be an easy to integrate library that can be used in any Cave application. It also serves to provide automated documentation and testing.
You can find the low level documentation for this package here.
Make sure you have Python 3.11.x (or higher) installed on your system. You can download it here.
pip install cave_utils
Make sure Docker is installed and running.
-
Create a docker container and drop into a shell
./run.sh
-
Run all tests (see ./utils/test.sh)
./run.sh test
-
Prettify the code (see ./utils/prettify.sh)
./run.sh prettify
-
Update the docs (see ./utils/docs.sh)
./run.sh docs
-
Note: You can and should modify the
Dockerfileto test different python versions.
-
In your
cave_app, update the following file:utils/run_server.sh#!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) APP_DIR=$(dirname "$SCRIPT_DIR") pip install -e /cave_utils source ./utils/helpers/shell_functions.sh source ./utils/helpers/ensure_postgres_running.sh # Check if the app is functional before proceeding if [ "$(python ./manage.py check --deployment_type development | grep "System check identified no issues" | wc -l)" -eq "0" ]; then printf "Unable to start the app due to an error in the code. See the stacktrace above." 2>&1 | pipe_log "ERROR" rm -r "./tmp" exit 1 fi source ./utils/helpers/ensure_db_setup.sh python "$APP_DIR/manage.py" runserver 0.0.0.0:8000 2>&1 | pipe_log "INFO" -
Remove
cave_utilsfrom the rootrequirements.txtfile -
In your
cave_app, setLIVE_API_VALIDATION_PRINT=Truein the.envfile- This will validate your data every time an API command is called for each session
-
Use the following command to run your
cave_app:cave run --docker-args "--volume {local_path_to_cave_utils}/cave_utils:/cave_utils"- As you edit
cave_utils, any changes will be hotloaded into your runningcave_app
- As you edit
- Note: This is for very specific use cases, such as running tests or debugging in an interactive shell.
- Note: In general, we copy all included examples from the cave_app to the
cave_utils/test/api_examplesdirectory, so you can run tests against them without needing to run the cave_app.- These copied examples can be tested by running
./run.sh testin the cave_utils directory, which will run all tests in thecave_utils/test.- This includes
test_validator.pywhich runs all examples in thecave_utils/test/api_examplesdirectory
- This includes
- These copied examples can be tested by running
- Run cave_app in interactive mode mounting cave_utils as a volume:
cave run --docker-args "--volume {local_path_to_cave_utils}/cave_utils:/cave_utils" -it - Then install cave utils in the docker container:
pip install -e /cave_utils - Then run some tests (eg
validate_all_examples.py):python cave_api/tests/validate_all_examples.py
- Make sure all tests are passing and the code is prettified.
- Make sure the documentation is up to date.
- Make sure the version number is updated in
setup.cfgandpyproject.toml. - Set up your virtual environment
python3 -m virtualenv venvsource venv/bin/activatepip install -r requirements.txt
- Update the release
source venv/bin/activate./publish.sh