|
8 | 8 | "remoteEnv": { |
9 | 9 | // Allow X11 apps to run inside the container |
10 | 10 | "DISPLAY": "${localEnv:DISPLAY}", |
| 11 | + // Put things that allow it in the persistent cache |
| 12 | + "PRE_COMMIT_HOME": "/cache/pre-commit", |
| 13 | + "UV_CACHE_DIR": "/cache/uv", |
| 14 | + "UV_PYTHON_CACHE_DIR": "/cache/uv-python", |
| 15 | + // Make a venv that is specific for this workspace path as the cache is shared |
| 16 | + "UV_PROJECT_ENVIRONMENT": "/cache/venv-for${localWorkspaceFolder}", |
11 | 17 | // Do the equivalent of "activate" the venv so we don't have to "uv run" everything |
12 | | - "PATH": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin:${containerEnv:PATH}" |
| 18 | + "VIRTUAL_ENV": "/cache/venv-for${localWorkspaceFolder}", |
| 19 | + "PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}" |
13 | 20 | }, |
14 | 21 | "customizations": { |
15 | 22 | "vscode": { |
16 | 23 | // Set *default* container specific settings.json values on container create. |
17 | 24 | "settings": { |
18 | | - "python.defaultInterpreterPath": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin/python", |
| 25 | + // Use the container's python by default |
| 26 | + "python.defaultInterpreterPath": "/cache/venv-for${localWorkspaceFolder}/bin/python", |
| 27 | + // Don't activate the venv as it is already in the PATH |
19 | 28 | "python.terminal.activateEnvInCurrentTerminal": false, |
20 | 29 | "python.terminal.activateEnvironment": false, |
21 | | - "remote.autoForwardPorts": false |
| 30 | + // Workaround to prevent garbled python REPL in the terminal |
| 31 | + // https://github.com/microsoft/vscode-python/issues/25505 |
| 32 | + "python.terminal.shellIntegration.enabled": false |
22 | 33 | }, |
23 | 34 | // Add the IDs of extensions you want installed when the container is created. |
24 | 35 | "extensions": [ |
|
34 | 45 | } |
35 | 46 | }, |
36 | 47 | // Create the config folder for the bash-config feature and uv cache |
37 | | - "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config ${localEnv:HOME}/.cache/uv", |
| 48 | + "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config", |
38 | 49 | "runArgs": [ |
39 | 50 | // Allow the container to access the host X11 display and EPICS CA |
40 | 51 | "--net=host", |
|
48 | 59 | "target": "/user-terminal-config", |
49 | 60 | "type": "bind" |
50 | 61 | }, |
51 | | - // Keep a persistent cross container cache for uv |
| 62 | + // Keep a persistent cross container cache for uv, pre-commit, and the venvs |
52 | 63 | { |
53 | | - "source": "${localEnv:HOME}/.cache/uv", |
54 | | - "target": "/root/.cache/uv", |
55 | | - "type": "bind" |
56 | | - }, |
57 | | - // Use a volume mount for the uv venv so it is local to the container |
58 | | - { |
59 | | - "target": "/workspaces/${localWorkspaceFolderBasename}/.venv", |
| 64 | + "source": "devcontainer-shared-cache", |
| 65 | + "target": "/cache", |
60 | 66 | "type": "volume" |
61 | 67 | } |
62 | 68 | ], |
63 | 69 | // Mount the parent as /workspaces so we can pip install peers as editable |
64 | 70 | "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", |
65 | | - // After the container is created, install the python project in editable form |
66 | | - "postCreateCommand": "uv sync && uv run pre-commit install --install-hooks" |
| 71 | + // After the container is created, recreate the venv then make pre-commit first run faster |
| 72 | + "postCreateCommand": "uv venv --clear && uv sync && pre-commit install --install-hooks" |
67 | 73 | } |
0 commit comments