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