Skip to content

Commit baa69f6

Browse files
rkorsakkeithrfung
authored andcommitted
🛠 Add VS Code debugging support (#61)
* 🛠 Add support for debugging the application * Added basic debugging instructions to the README * Fix formatting in main.py * Remove comments from launch.json * Update docs with README debugging info
1 parent a61dff2 commit baa69f6

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Web API",
6+
"type": "python",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/app/main.py",
9+
"console": "integratedTerminal",
10+
"env": {
11+
"PYTHONPATH": "${workspaceRoot}"
12+
}
13+
}
14+
]
15+
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ To start the api:
3232
make start
3333
```
3434

35+
## 🛠 Debugging
36+
37+
For local debugging with Visual Studio Code, choose the `Web API` option from the dropdown in the Run menu. Once the server is up, you can easily hit your breakpoints.
38+
39+
If the code fails to run, [make sure your Python interpreter is set](https://code.visualstudio.com/docs/python/environments) to use your pipenv environment.
40+
3541
## 🐳 Docker
3642
A DockerFile is available to quickly create and run a docker container.
3743

app/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@
1919
)
2020

2121
app.include_router(api_router, prefix=settings.API_V1_STR)
22+
23+
if __name__ == "__main__":
24+
# IMPORTANT: This should only be used to debug the application.
25+
# For normal execution, run `make start`.
26+
#
27+
# To make this work, the PYTHONPATH must be set to the root directory, e.g.
28+
# `PYTHONPATH=. pipenv run python ./app/main.py`
29+
# See the VSCode launch configuration for detail.
30+
import uvicorn
31+
32+
uvicorn.run(app, host="0.0.0.0", port=8000)

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ To start the api:
3232
make start
3333
```
3434

35+
## 🛠 Debugging
36+
37+
For local debugging with Visual Studio Code, choose the `Web API` option from the dropdown in the Run menu. Once the server is up, you can easily hit your breakpoints.
38+
39+
If the code fails to run, [make sure your Python interpreter is set](https://code.visualstudio.com/docs/python/environments) to use your pipenv environment.
40+
3541
## 🐳 Docker
3642
A DockerFile is available to quickly create and run a docker container.
3743

0 commit comments

Comments
 (0)