Dependencies are managed with [uv](https://docs.astral.sh/uv/). Install it by following the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/).
`uv` creates and manages a local `.venv` for you. Prefix commands with `uv run` (e.g. `uv run pytest`) to run them inside the project environment, or activate the venv manually via `source .venv/bin/activate`.
Blitz API provides a [Nix](https://github.com/NixOS/nix) Flake file to create a development environment. Execute `nix develop` (make sure you have flakes enabled) to enter the environment.
In this environment a hidden folder `.venv` is created to install the python dependencies locally. If pyright can't find these dependencies create the following file in the root
> ℹ️ The final deployment installs via pip from `requirements.txt` (see `make install`) to avoid having to install uv on the target machine, so keep this file in sync when dependencies change.
Then you can run always `make sync-to-blitz` to copy your latest code over to your RaspiBlitz. The script automatically restarts the backend API with the new code on your RaspiBlitz and shows you the logs.
To test the backend API then call the SwaggerUI: `http://[LOCALIP]/api/v1/docs` - to call protected endpoints run the `/system/login` endpoint first with HTTP POST body:
```
{
"password": "[PASSWORDA]"
}
```
and then copy the JWT Auth string returned to `Authorize` in the top section of the SwaggerUI.
*You can also now test the RaspiBlitz WebUI against the API by running it locally on your dev laptop when you configure it to use the backend API of your RaspiBlitz.*
### Debugging code running on a remote machine via VSCode
To debug Python code that is running on another machine, like a RaspiBlitz, follow these steps.
#### Prepare local machine
* run `make install-dev`.
* open the `.vscode/launch.json` file and change the host to your remote machines IP
* ```json
"connect": {
"host": "192.168.1.49",
"port": 5678
}
```
* open your `.env_sample` file and replace the line `# remote_debugging=false` with `remote_debugging=true`
<details>
This is necessary because we're going to synchronize the local source with the remote node. The blitz_api service will be restarted on the remote node. Any changes to the `.env' file will be overwritten by the setup script on the Blitz. This script will use the `.env_sample` file as a base and fill it with data. This way we can trick the Blitz into enabling this setting every time we change something without the Blitz explicitly supporting it.
</details>
* make sure you follow the steps in the [Sync changes to a RaspiBlitz](#sync-changes-to-a-raspiblitz) section
* execute `make sync-to-blitz`
* Make sure to chose `Attach` in the RUN AND DEBUG windows of VSCode
* Hit F5 and voila you should be connected to your RaspiBlitz and debug code remotely
#### Prepare the RaspiBlitz
* SSH into the Blitz, and run `sudo -i -u blitzapi`
*`cd blitz_api`
* Finally run `make enable-remote-debugging`
Refer to [this documentation](https://code.visualstudio.com/docs/python/debugging#_debugging-by-attaching-over-a-network-connection) to learn how to setup VSCode correctly.