Skip to content

Commit 7f75e16

Browse files
committed
chore: spruce up the vscode build tasks
chore: add vscode action for "run currently focused python test file" chore: fix permissions in devcontainer image chore: fix devcontainer image brace expansion chore: improve vscode test task chore: add reasonable minimum requirements chore: add commented podman workarounds chore: setup vscode test discovery for python
1 parent 9721810 commit 7f75e16

File tree

3 files changed

+136
-49
lines changed

3 files changed

+136
-49
lines changed

.devcontainer/Dockerfile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM mcr.microsoft.com/devcontainers/typescript-node:22
22
# The default username for most devcontainer-base-images is 'vscode', but the typescript-node image uses 'node'.
33
ARG USERNAME=node
4+
SHELL ["/bin/bash", "-c"]
45

56
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
67
RUN --mount=type=cache,target=/var/cache/apt \
@@ -49,11 +50,12 @@ UV_PYTHON=${PYTHON_VERSION}
4950

5051
# Volumes for the dependency stores/caches
5152
ARG CACHE_DIR=/home/${USERNAME}/.cache
53+
ARG DATA_DIR=/home/${USERNAME}/.data
5254
# Setting XDG_CACHE_HOME will affect the location of the cache for pnpm and uv, and possibly other tools
5355
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
5456
# We set XDG_DATA_HOME to a non-volume-mounted location to guarantee that UV pre-installs python. (if its mounted it will only be installed after container start)
5557
ENV XDG_CACHE_HOME=${CACHE_DIR} \
56-
XDG_DATA_HOME=/home/${USERNAME}/.data \
58+
XDG_DATA_HOME=${DATA_DIR} \
5759
GIT_LFS_CACHE=${CACHE_DIR}/git-lfs \
5860
PATH="$UV_PROJECT_ENVIRONMENT/bin:$CACHE_DIR/pnpm:$CACHE_DIR/uv:$PATH" \
5961
PYTHONPATH="$PYTHONPATH:${INVOKEAI_SRC}"
@@ -65,18 +67,10 @@ VOLUME [ "${CACHE_DIR}", "${INVOKEAI_SRC}", "${INVOKEAI_ROOT}", "${HF_HOME}"]
6567

6668
# Create & set ownership of directories
6769
RUN set -eux; \
68-
mkdir -p ${CACHE_DIR} && \
69-
mkdir -p ${CACHE_DIR}/uv && \
70-
mkdir -p ${CACHE_DIR}/pnpm && \
71-
mkdir -p ${CACHE_DIR}/node && \
72-
mkdir -p ${CACHE_DIR}/Microsoft && \
73-
mkdir -p ${INVOKEAI_ROOT}/models/.download_cache && \
70+
mkdir -p ${CACHE_DIR}/{uv,pnpm,node,Microsoft} && \
71+
mkdir -p ${DATA_DIR}/{uv,pnpm,node} && \
7472
mkdir -p ${UV_PROJECT_ENVIRONMENT} && \
75-
chown --recursive ${USERNAME}:${USERNAME} ${CACHE_DIR} && \
76-
chown --recursive ${USERNAME}:${USERNAME} ${INVOKEAI_ROOT} && \
77-
chown --recursive ${USERNAME}:${USERNAME} ${UV_PROJECT_ENVIRONMENT} && \
78-
mkdir -p /home/${USERNAME}/.data && \
79-
chown --recursive ${USERNAME}:${USERNAME} /home/${USERNAME}/.data
73+
mkdir -p ${INVOKEAI_ROOT}/models/.download_cache
8074

8175
# Setup PNPM
8276
RUN corepack use pnpm && corepack enable
@@ -87,4 +81,10 @@ COPY --from=ghcr.io/astral-sh/uv:0.6 /uv /uvx /bin/
8781
RUN uv venv && uv python install ${PYTHON_VERSION}
8882
ENV UV_PYTHON_DOWNLOADS=never
8983

84+
RUN set -eux; \
85+
chown --recursive ${USERNAME}:${USERNAME} ${CACHE_DIR} && \
86+
chown --recursive ${USERNAME}:${USERNAME} ${DATA_DIR} && \
87+
chown --recursive ${USERNAME}:${USERNAME} ${INVOKEAI_ROOT} && \
88+
chown --recursive ${USERNAME}:${USERNAME} ${UV_PROJECT_ENVIRONMENT}
89+
9090
WORKDIR ${INVOKEAI_SRC}

.devcontainer/devcontainer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@
4646
"ghcr.io/devcontainers/features/github-cli": {}
4747
},
4848
"hostRequirements": {
49-
"gpu": "optional"
49+
"gpu": "optional",
50+
"cpus": 2,
51+
"memory": "8gb",
52+
"storage": "10gb" // rough estimate of all dev packages & a handful of ai-models
5053
},
51-
"runArgs": ["--env-file", ".devcontainer/.env"],
54+
"runArgs": [
55+
"--env-file",
56+
".devcontainer/.env"
57+
// "--userns=keep-id", // Uncomment if using podman instead of docker.
58+
// "--device=nvidia.com/gpu=all", // Uncomment if using podman instead of docker.
59+
],
5260
"initializeCommand": [".devcontainer/scripts/init"],
5361
"onCreateCommand": "pnpm config --global set store-dir $XDG_CACHE_HOME/pnpm",
5462
"updateContentCommand": "pnpm install --dir invokeai/frontend/web --prefer-offline",
@@ -62,6 +70,10 @@
6270
"/home/node/.venv/lib",
6371
"${containerWorkspaceFolder}"
6472
],
73+
"python.testing.pytestEnabled": true,
74+
"python.testing.pytestArgs": [
75+
"--no-cov" // prevents interference from code-coverage when running tests within the debugger
76+
],
6577
"files.autoSaveWhenNoErrors": true,
6678
"editor.formatOnSave": true,
6779
"editor.codeActionsOnSave": {

.vscode/tasks.json

Lines changed: 110 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,62 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"label": "Lint :: Fix Python Linting Errors",
5+
"label": "Backend :: Install",
66
"type": "shell",
7-
"command": "ruff check --fix",
7+
"command": "uv",
8+
"args": [
9+
"sync",
10+
"--extra using-$(echo ${COMPUTE_DEVICE:-cpu})",
11+
"--extra dev",
12+
"--extra test",
13+
"--extra docs"
14+
],
815
"group": {
916
"kind": "build",
1017
"isDefault": false
1118
},
1219
"presentation": {
13-
"group": "build",
14-
"echo": true
20+
"group": "install"
1521
}
1622
},
1723
{
18-
"label": "Lint :: Fix TypeScript Linting Errors",
24+
"label": "Backend :: Linting :: Scan All",
1925
"type": "shell",
20-
"command": "pnpm fix",
21-
"options": {
22-
"cwd": "${workspaceFolder}/invokeai/frontend/web/"
26+
"command": "ruff check",
27+
"group": {
28+
"kind": "build",
29+
"isDefault": false
2330
},
31+
"presentation": {
32+
"group": "backend"
33+
}
34+
},
35+
{
36+
"label": "Backend :: Linting :: Fix All",
37+
"type": "shell",
38+
"command": "ruff check --fix",
2439
"group": {
2540
"kind": "build",
2641
"isDefault": false
2742
},
2843
"presentation": {
29-
"group": "build",
30-
"echo": true
44+
"group": "backend"
3145
}
3246
},
3347
{
34-
"label": "Test :: Backend",
48+
"label": "Backend :: Linting :: Format All",
49+
"type": "shell",
50+
"command": "ruff format",
51+
"group": {
52+
"kind": "build",
53+
"isDefault": false
54+
},
55+
"presentation": {
56+
"group": "backend"
57+
}
58+
},
59+
{
60+
"label": "Backend :: Testing :: Unit Tests",
3561
"type": "shell",
3662
"command": "pytest",
3763
"args": [],
@@ -43,20 +69,31 @@
4369
"isDefault": false
4470
},
4571
"presentation": {
46-
"echo": true,
4772
"reveal": "always",
4873
"focus": true,
4974
"panel": "dedicated",
5075
"showReuseMessage": false,
5176
"clear": false,
52-
"group": "test"
77+
"group": "backend"
5378
}
5479
},
5580
{
56-
"label": "Test :: Frontend",
81+
"label": "Frontend :: Install",
5782
"type": "shell",
5883
"command": "pnpm",
59-
"args": ["test"],
84+
"args": ["install", "--dir", "invokeai/frontend/web/"],
85+
"group": {
86+
"kind": "build",
87+
"isDefault": false
88+
},
89+
"presentation": {
90+
"group": "install"
91+
}
92+
},
93+
{
94+
"label": "Frontend :: Linting :: Scan All",
95+
"type": "shell",
96+
"command": "pnpm lint",
6097
"options": {
6198
"cwd": "${workspaceFolder}/invokeai/frontend/web/"
6299
},
@@ -65,45 +102,83 @@
65102
"isDefault": false
66103
},
67104
"presentation": {
68-
"echo": true,
69-
"reveal": "always",
70-
"focus": true,
71-
"panel": "dedicated",
72-
"showReuseMessage": false,
73-
"clear": false,
74-
"group": "test"
105+
"group": "frontend"
75106
}
76107
},
77108
{
78-
"label": "Install :: Backend",
109+
"label": "Frontend :: Linting :: Fix All",
79110
"type": "shell",
80-
"command": "uv",
81-
"args": [
82-
"sync",
83-
"--inexact",
84-
"--all-extras",
85-
"--no-extra",
86-
"onnx-directml"
87-
],
111+
"command": "pnpm fix",
112+
"options": {
113+
"cwd": "${workspaceFolder}/invokeai/frontend/web/"
114+
},
88115
"group": {
89116
"kind": "build",
90117
"isDefault": false
91118
},
92119
"presentation": {
93-
"group": "install"
120+
"group": "frontend"
94121
}
95122
},
96123
{
97-
"label": "Install :: Frontend",
124+
"label": "Frontend :: Testing :: Unit Tests",
98125
"type": "shell",
99126
"command": "pnpm",
100-
"args": ["install", "--dir", "invokeai/frontend/web/"],
127+
"args": ["test"],
128+
"options": {
129+
"cwd": "${workspaceFolder}/invokeai/frontend/web/"
130+
},
101131
"group": {
102132
"kind": "build",
103133
"isDefault": false
104134
},
105135
"presentation": {
106-
"group": "install"
136+
"group": "frontend"
137+
}
138+
},
139+
{
140+
"label": "Tooling :: OpenAPI :: Generate Types",
141+
"dependsOn": ["tools/regenerate-openapi-definitions"],
142+
"type": "shell",
143+
"command": "pnpm typegen",
144+
"options": {
145+
"cwd": "${workspaceFolder}/invokeai/frontend/web"
146+
},
147+
"group": {
148+
"kind": "build",
149+
"isDefault": false
150+
},
151+
"presentation": {
152+
"group": "frontend"
153+
}
154+
},
155+
{
156+
"label": "tools/regenerate-openapi-definitions",
157+
"type": "shell",
158+
"command": "python",
159+
"args": ["../../../scripts/generate_openapi_schema.py"],
160+
"options": {
161+
"cwd": "${workspaceFolder}/invokeai/frontend/web"
162+
},
163+
"hide": true
164+
},
165+
{
166+
"label": "Backend :: Testing :: Run Active File",
167+
"type": "process",
168+
"command": "pytest",
169+
"args": ["${file}"],
170+
"options": {
171+
"cwd": "${workspaceFolder}"
172+
},
173+
"problemMatcher": "$python",
174+
"group": {
175+
"kind": "test",
176+
"isDefault": "**/tests/**.py"
177+
},
178+
"presentation": {
179+
"focus": true,
180+
"clear": true,
181+
"panel": "dedicated"
107182
}
108183
}
109184
]

0 commit comments

Comments
 (0)