Skip to content

Commit d21278c

Browse files
address issues with VS Code dev containers (see issue 559) (TGSAI#576)
* Templates and TemplateRegistry * Fix pre-commit issues * Rever dev container changes * PR Review: address issues * PR Review: register default templates at registry initialization * Dockerfile.dev --------- Co-authored-by: Altay Sansal <[email protected]>
1 parent aae5f51 commit d21278c

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

.devcontainer/Dockerfile.dev

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# USAGE:
2+
# This file will be used by the VS Code DevContainer extension
3+
# to create a development environment for the mdio-python project.
4+
# HOW TO MANUALLY BUILD AND DEBUG THE CONTAINER
5+
# docker build -t mdio-dev -f .devcontainer/Dockerfile.dev .
6+
# docker run -it --rm --entrypoint /bin/bash --name mdio-dev mdio-dev
7+
# NOTES:
8+
# 1. The container will be run as the non-root user 'vscode' with UID 1000.
9+
# 2. The virtual environment will be setup at /home/vscode/.venv
10+
# 3. The project source code will be host-mounted at /workspaces/mdio-python
11+
ARG PYTHON_VERSION="3.13"
12+
ARG LINUX_DISTRO="bookworm"
13+
ARG UV_VERSION="0.6.11"
14+
FROM mcr.microsoft.com/devcontainers/python:1-${PYTHON_VERSION}-${LINUX_DISTRO}
15+
16+
ENV USERNAME="vscode"
17+
USER $USERNAME
18+
19+
COPY --chown=$USERNAME:$USERNAME ./ /workspaces/mdio-python
20+
21+
WORKDIR /workspaces/mdio-python
22+
23+
ARG UV_VERSION
24+
# Install UV as described in https://devblogs.microsoft.com/ise/dockerizing-uv/
25+
RUN python3 -m pip install --no-cache-dir uv==${UV_VERSION}
26+
# Prevent uv from trying to create hard links, which does not work in a container
27+
# that mounts local file systems (e.g. VS Code Dev Containers)
28+
ENV UV_LINK_MODE=copy
29+
# Add path to the site-packages
30+
ENV PYTHONUSERBASE=/home/$USERNAME/.local
31+
ENV PATH="$PYTHONUSERBASE/bin:$PATH"
32+
33+
# Initialize virtual environment in the container
34+
ENV VIRTUAL_ENV="/home/$USERNAME/.venv"
35+
ENV UV_PROJECT_ENVIRONMENT=$VIRTUAL_ENV
36+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
37+
RUN uv venv $VIRTUAL_ENV
38+
39+
# Install the project in the editable mode
40+
# https://setuptools.pypa.io/en/latest/userguide/development_mode.html
41+
# This allows for live reloading of the code during development
42+
RUN uv pip install -e .
43+
# Install "extras" (development dependencies) in pyproject.toml
44+
RUN uv sync --group dev
45+
# Now one can run:
46+
# pre-commit run --all-files

.devcontainer/devcontainer.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// README at: https://github.com/devcontainers/templates/tree/main/src/python
33
{
44
"build": {
5-
"dockerfile": "Dockerfile",
5+
"dockerfile": "Dockerfile.dev",
66
"context": ".."
77
},
88
// Use 'postCreateCommand' to run commands after the container is created.
99
"postCreateCommand": {
10-
"post_create_script": "bash ./.devcontainer/post-install.sh"
10+
// "post_create_script": "bash ./.devcontainer/post-install.sh"
1111
},
1212
// Forward 8787 to enable us to view dask dashboard
1313
"forwardPorts": [8787],
@@ -16,8 +16,9 @@
1616
// Configure properties specific to VS Code.
1717
"vscode": {
1818
"settings": {
19-
"python.terminal.activateEnvInCurrentTerminal": true,
20-
"python.defaultInterpreterPath": "/opt/venv/bin/python"
19+
"python.testing.pytestArgs": ["tests"],
20+
"python.testing.unittestEnabled": false,
21+
"python.testing.pytestEnabled": true
2122
},
2223
"extensions": [
2324
"ms-python.python",
@@ -27,17 +28,19 @@
2728
"ms-toolsai.jupyter-renderers",
2829
"vscode-icons-team.vscode-icons",
2930
"wayou.vscode-todo-highlight",
30-
"streetsidesoftware.code-spell-checker"
31+
"streetsidesoftware.code-spell-checker",
32+
"eamodio.gitlens",
33+
"visualstudioexptteam.vscodeintellicode",
34+
"richie5um2.vscode-sort-json"
3135
]
3236
}
3337
},
3438
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
3539
// "remoteUser": "root",
3640
"updateRemoteUserUID": true,
41+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/mdio-python,type=bind",
42+
"workspaceFolder": "/workspaces/mdio-python",
3743
"mounts": [
38-
// Re-use local Git configuration
39-
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig_tmp,type=bind,consistency=cached",
40-
"source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig_tmp,type=bind,consistency=cached",
41-
"source=${localEnv:SCRATCH_DIR}/${localEnv:USER},target=/scratch/,type=bind,consistency=cached"
44+
// "source=${localWorkspaceFolder}/../DATA/,target=/DATA/,type=bind,consistency=cached"
4245
]
4346
}

0 commit comments

Comments
 (0)