|
7 | 7 | }, |
8 | 8 | "remoteEnv": { |
9 | 9 | // Allow X11 apps to run inside the container |
10 | | - "DISPLAY": "${localEnv:DISPLAY}" |
| 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}", |
| 17 | + // Do the equivalent of "activate" the venv so we don't have to "uv run" everything |
| 18 | + "VIRTUAL_ENV": "/cache/venv-for${localWorkspaceFolder}", |
| 19 | + "PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}" |
11 | 20 | }, |
12 | 21 | "customizations": { |
13 | 22 | "vscode": { |
14 | 23 | // Set *default* container specific settings.json values on container create. |
15 | 24 | "settings": { |
16 | | - "python.defaultInterpreterPath": "/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 |
| 28 | + "python.terminal.activateEnvInCurrentTerminal": false, |
| 29 | + "python.terminal.activateEnvironment": 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 |
17 | 33 | }, |
18 | 34 | // Add the IDs of extensions you want installed when the container is created. |
19 | 35 | "extensions": [ |
|
27 | 43 | ] |
28 | 44 | } |
29 | 45 | }, |
30 | | - "features": { |
31 | | - // add in eternal history and other bash features |
32 | | - "ghcr.io/diamondlightsource/devcontainer-features/bash-config:1": {} |
33 | | - }, |
34 | | - // Create the config folder for the bash-config feature |
35 | | - "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/bash-config", |
| 46 | + // Create the config folder for the bash-config feature and uv cache |
| 47 | + "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config", |
36 | 48 | "runArgs": [ |
37 | 49 | // Allow the container to access the host X11 display and EPICS CA |
38 | 50 | "--net=host", |
39 | 51 | // Make sure SELinux does not disable with access to host filesystems like tmp |
40 | 52 | "--security-opt=label=disable" |
41 | 53 | ], |
| 54 | + "mounts": [ |
| 55 | + // Mount in the user terminal config folder so it can be edited |
| 56 | + { |
| 57 | + "source": "${localEnv:HOME}/.config/terminal-config", |
| 58 | + "target": "/user-terminal-config", |
| 59 | + "type": "bind" |
| 60 | + }, |
| 61 | + // Keep a persistent cross container cache for uv, pre-commit, and the venvs |
| 62 | + { |
| 63 | + "source": "devcontainer-shared-cache", |
| 64 | + "target": "/cache", |
| 65 | + "type": "volume" |
| 66 | + } |
| 67 | + ], |
42 | 68 | // Mount the parent as /workspaces so we can pip install peers as editable |
43 | 69 | "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", |
44 | | - // After the container is created, install the python project in editable form |
45 | | - "postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install" |
| 70 | + // After the container is created, recreate the venv then make pre-commit first run faster |
| 71 | + "postCreateCommand": "uv venv --clear && uv sync && pre-commit install --install-hooks" |
46 | 72 | } |
0 commit comments