Skip to content

Commit 46d8314

Browse files
authored
feat: Added VS Code debug launch configurations (#1)
* fix(api): unnecessary default type arguments (Ruff UP043) * feat: added VS Code launch configurations for FastAPI and pytest * feat: added VS Code debug launch configuration for Typer CLI
1 parent 4fce603 commit 46d8314

File tree

9 files changed

+99
-7
lines changed

9 files changed

+99
-7
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dist/
6363
.terraform/
6464

6565
# VS Code
66-
.vscode/
66+
.vscode/*
6767

6868
# Default template
6969
my-project/

template/.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ dist/
6262
# Terraform
6363
.terraform/
6464

65-
# VS Code
66-
.vscode/
65+
# VS Code (but still include launch configurations)
66+
.vscode/*
67+
!/.vscode/launch.json*

template/.vscode/launch.json.jinja

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{%- if with_fastapi_api %}
5+
{
6+
"name": "API [debug]",
7+
"type": "debugpy",
8+
"request": "launch",
9+
"module": "uvicorn",
10+
"args": [
11+
"{{ project_name_snake_case }}.api:app",
12+
"--reload"
13+
],
14+
"jinja": true,
15+
"justMyCode": true,
16+
"console": "integratedTerminal"
17+
},
18+
{%- endif %}
19+
{%- if with_typer_cli %}
20+
{
21+
"name": "CLI [debug]",
22+
"type": "debugpy",
23+
"request": "launch",
24+
"program": "${workspaceFolder}//src//{{ project_name_snake_case }}//cli.py",
25+
"args": [
26+
"--name",
27+
"Someone"
28+
],
29+
"justMyCode": true,
30+
"console": "integratedTerminal"
31+
},
32+
{%- endif %}
33+
{
34+
"name": "Python file [debug]",
35+
"type": "debugpy",
36+
"request": "launch",
37+
"program": "${file}",
38+
"console": "integratedTerminal"
39+
}
40+
]
41+
}

template/src/{{ project_name_snake_case }}/{% if with_fastapi_api %}api.py{% endif %}.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from fastapi import FastAPI
99

1010

1111
@asynccontextmanager
12-
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
12+
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
1313
"""Handle FastAPI startup and shutdown events."""
1414
# Startup events.
1515
for handler in logging.root.handlers:

template/src/{{ project_name_snake_case }}/{% if with_typer_cli %}cli.py{% endif %}.jinja

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ app = typer.Typer()
1010
def fire(name: str = "Chell") -> None:
1111
"""Fire portal gun."""
1212
rprint(f"[bold red]Alert![/bold red] {name} fired [green]portal gun[/green] :boom:")
13+
14+
15+
if __name__ == "__main__":
16+
app()

{{ cookiecutter.__project_name_kebab_case }}/.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ __pycache__/
6464
# Terraform
6565
.terraform/
6666

67-
# VS Code
68-
.vscode/
67+
# VS Code (but still include launch configurations)
68+
.vscode/*
69+
!/.vscode/launch.json*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{%- if with_fastapi_api %}
5+
{
6+
"name": "API [debug]",
7+
"type": "debugpy",
8+
"request": "launch",
9+
"module": "uvicorn",
10+
"args": [
11+
"{{ project_name_snake_case }}.api:app",
12+
"--reload"
13+
],
14+
"jinja": true,
15+
"justMyCode": true,
16+
"console": "integratedTerminal"
17+
},
18+
{%- endif %}
19+
{%- if with_typer_cli %}
20+
{
21+
"name": "CLI [debug]",
22+
"type": "debugpy",
23+
"request": "launch",
24+
"program": "${workspaceFolder}//src//{{ project_name_snake_case }}//cli.py",
25+
"args": [
26+
"--name",
27+
"Someone"
28+
],
29+
"justMyCode": true,
30+
"console": "integratedTerminal"
31+
},
32+
{%- endif %}
33+
{
34+
"name": "Python file [debug]",
35+
"type": "debugpy",
36+
"request": "launch",
37+
"program": "${file}",
38+
"console": "integratedTerminal"
39+
}
40+
]
41+
}

{{ cookiecutter.__project_name_kebab_case }}/src/{{ cookiecutter.__project_name_snake_case }}/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@asynccontextmanager
12-
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
12+
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
1313
"""Handle FastAPI startup and shutdown events."""
1414
# Startup events.
1515
for handler in logging.root.handlers:

{{ cookiecutter.__project_name_kebab_case }}/src/{{ cookiecutter.__project_name_snake_case }}/cli.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
def fire(name: str = "Chell") -> None:
1111
"""Fire portal gun."""
1212
print(f"[bold red]Alert![/bold red] {name} fired [green]portal gun[/green] :boom:")
13+
14+
15+
if __name__ == "__main__":
16+
app()

0 commit comments

Comments
 (0)