Skip to content

Commit

Permalink
forward args to flask from wsgi (#573)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Bufolo <[email protected]>
  • Loading branch information
RedX2501 and Guilherme Bufolo authored Dec 13, 2024
1 parent 224b117 commit 4fa523c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
15 changes: 12 additions & 3 deletions backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -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)
67 changes: 66 additions & 1 deletion docs/docs/reference/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.
Expand Down

0 comments on commit 4fa523c

Please sign in to comment.