Skip to content

Latest commit

 

History

History
107 lines (82 loc) · 3.55 KB

File metadata and controls

107 lines (82 loc) · 3.55 KB

Report Execution Service

Prerequisites

  1. Install uv (a Python package and project manager), following the instructions outlined on their website.

  2. Ensure you have Python 3.14 installed. If you don't already have a means of managing Python versions, this can be accomplished directly with uv:

    uv python install 3.14

Getting Started

  1. Install all project dependencies, as outlined in pyproject.toml:

    uv sync --frozen
  2. (Optional) Create a .env file from the sample.env, if you'd like to configure the application's port or host during local development (particularly helpful if you're running outside of Docker). NOTE: You'll need to manually load the env (export $(xargs <.env)), add --env-file .env to uv commands, or install and configure direnv (or an equivalent shell extension) in order to make these environment variables available to the application.

    cp sample.env .env
  3. Have the NBS MSSQL database running and make sure the env vars in this workspace are correct for that DB (sample.env values should match). Using the cdc-sandbox docker compose is a good/opinionated way to do this

    # from a dedicated terminal at the repo root
    cd cdc-sandbox
    # create .env if it doesn't exist
    ./check_env.sh
    # run the database
    docker compose up nbs-mssql
  4. Start the FastAPI development server with Uvicorn (the default ASGI server program shipped with FastAPI):

    uv run uvicorn src.main:app

The application will be available at:

Sample curl:

curl -X POST 'http://localhost:8001/report/execute' -H "accept: application/json" -H "Content-Type: application/json" -d '{
            "version": 1,
            "is_export": true,
            "is_builtin": true,
            "report_title": "Test Report",
            "library_name": "nbs_custom",
            "data_source_name": "random_db_table_0",
            "subset_query": "SELECT * FROM test"
}'

Testing

Unit testing for this project is currently handled with pytest. To invoke the unit test suite, simply run the following:

uv run pytest -m "not integration"

Or something similar to the following, if you're looking to run a specific test suite:

uv run pytest src/main_test.py

To run integration tests, ensure the .env is loaded or passed to uv and run

uv run pytest # all tests
uv run pytest -m integration # just integration tests
uv run --env-file .env pytest # pass env file to uv

Code Linting and Formatting

Additionally, this project uses Ruff (also created by Astral, the makers of uv) for linting and formatting and Pyrefly for type checking.

In order to check for existing linter issues, run:

uv run ruff check

To automatically address any auto-fixable linter issues, run:

uv run ruff check --fix

Run the formatter with the following:

uv run ruff format

Run the type checker with the following:

uv run pyrefly check

Additional Resources