diff --git a/backend/wsgi.py b/backend/wsgi.py index 7b8eb729..7e30d07d 100644 --- a/backend/wsgi.py +++ b/backend/wsgi.py @@ -1,12 +1,21 @@ import gevent.monkey gevent.monkey.patch_all() - -from app import app, socketio, celery_app +import argparse import os +from app import app, socketio from app.config import UPLOAD_FOLDER +def parse_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument("--host", required=False, default=None, type=str, nargs="?", help="Set the host to use. Forwarded to flask.") + parser.add_argument("--debug", required=False, default=True, type=bool, help="Set the debug flag. Forwarded to flask.") + + return parser.parse_args() + + if __name__ == "__main__": + arguments = parse_arguments() if not os.path.exists(UPLOAD_FOLDER): os.makedirs(UPLOAD_FOLDER) - socketio.run(app, debug=True) + socketio.run(app, debug=arguments.debug, host=arguments.host) diff --git a/docs/docs/reference/contributing.md b/docs/docs/reference/contributing.md index 6a163a93..32a9beee 100644 --- a/docs/docs/reference/contributing.md +++ b/docs/docs/reference/contributing.md @@ -34,14 +34,65 @@ The `description` is a descriptive summary of the change the PR will make. - Install dependencies: `flutter packages get` - Create empty environment file: `touch .env` - Run app: `flutter run` + +==== Debugging + +An example configuration (for launch.json) for debugging in VS Code when opening the root folder in the editor: + +``` +{ + "name": "kitchenowl", + "cwd": "kitchenowl", + "request": "launch", + "type": "dart" +}, +{ + "name": "kitchenowl (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" +} +``` + +For an easier debug setup see the section below. + + === "Backend" - Go to `./backend` - Create a python environment `python3 -m venv venv` - Activate your python environment `source venv/bin/activate` (environment can be deactivated with `deactivate`) - Install dependencies `pip3 install -r requirements.txt` - Initialize/Upgrade the sqlite database with `flask db upgrade` - - Run debug server with `python3 wsgi.py` + - Run debug server with `python3 wsgi.py` (to make the the server visible to any device add `--host=0.0.0.0` or the network IP address on which to provide the server) - The backend should be reachable at `localhost:5000` + + **Do not run the backend using `flask` as it won't initialize the sockets properly.** + +==== Debugging + +An example configuration (for launch.json) for debugging in VS Code when opening the root folder in the editor: + +``` +{ + "name": "Python Debugger: KitchenOwl", + "type": "debugpy", + "request": "launch", + "cwd": "${workspaceFolder}/backend/", + "program": "wsgi.py", + "jinja": true, + "justMyCode": true, + "gevent": true +}, +``` + +To expose the backend to the complete network add the followig parameters: + +``` +args: [ + "--host=0.0.0.0" +] +``` + === "Docs" - Go to `./docs` - Create a python environment `python3 -m venv venv` @@ -53,6 +104,20 @@ The `description` is a descriptive summary of the change the PR will make. - Clone the website repository - Run website: `hugo server` + +=== Debugging + +It is generally recommended to open the backend and the frontend projects in different VS Code instances. When developing in this way the debugging configuration for the backend must be adapted by removing `cwd`. + +If there is need to debug the interaction between two different different apps (i.e. Linux native and Web Browser) they can be started on the same host by running flutter multiple times: + +- `flutter run -d chrome` +- `flutter run -d linux` + +The Android version can also be run by using an emulator on the same PC to avoid needing to expose the backend on the local network. + +The debugger in VS Code can also be started multiple times in the same editor session. This is not recommended as it can be confusing to understand in which instance breakpoints are being hit. It is easier to start mulitple VS Code sessions. + ### Git Commit Message Style This project uses the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format.