Skip to content

Commit 4c4e803

Browse files
DEV: Add initial devcontainer config for codepaces (numpy#22722)
* initial files * STY: remove noop.txt (we have an environment.yaml) some other style fixups Co-authored-by: Sarah Kaiser <[email protected]>
1 parent c4ce4e9 commit 4c4e803

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

.devcontainer/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3-anaconda/.devcontainer/base.Dockerfile
2+
3+
FROM mcr.microsoft.com/vscode/devcontainers/anaconda:0-3
4+
5+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
6+
ARG NODE_VERSION="none"
7+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
8+
9+
10+
# Copy environment.yml (if found) to a temp location so we update the environment. Also
11+
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
12+
COPY environment.yml* /tmp/conda-tmp/
13+
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env create -f /tmp/conda-tmp/environment.yml; fi \
14+
&& rm -rf /tmp/conda-tmp
15+
16+
# [Optional] Uncomment this section to install additional OS packages.
17+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18+
# && apt-get -y install --no-install-recommends <your-package-list-here>

.devcontainer/add-notice.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Display a notice when not running in GitHub Codespaces
2+
3+
cat << 'EOF' > /usr/local/etc/vscode-dev-containers/conda-notice.txt
4+
When using "conda" from outside of GitHub Codespaces, note the Anaconda repository
5+
contains restrictions on commercial use that may impact certain organizations. See
6+
https://aka.ms/vscode-remote/conda/anaconda
7+
EOF
8+
9+
notice_script="$(cat << 'EOF'
10+
if [ -t 1 ] && [ "${IGNORE_NOTICE}" != "true" ] && [ "${TERM_PROGRAM}" = "vscode" ] && [ "${CODESPACES}" != "true" ] && [ ! -f "$HOME/.config/vscode-dev-containers/conda-notice-already-displayed" ]; then
11+
cat "/usr/local/etc/vscode-dev-containers/conda-notice.txt"
12+
mkdir -p "$HOME/.config/vscode-dev-containers"
13+
((sleep 10s; touch "$HOME/.config/vscode-dev-containers/conda-notice-already-displayed") &)
14+
fi
15+
EOF
16+
)"
17+
18+
echo "${notice_script}" | tee -a /etc/bash.bashrc >> /etc/zsh/zshrc

.devcontainer/devcontainer.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3-anaconda
3+
{
4+
"name": "Numpy (devcontainer)",
5+
"build": {
6+
"context": "..",
7+
"dockerfile": "Dockerfile",
8+
"args": {
9+
"NODE_VERSION": "lts/*"
10+
}
11+
},
12+
13+
// Configure tool-specific properties.
14+
"customizations": {
15+
// Configure properties specific to VS Code.
16+
"vscode": {
17+
// Set *default* container specific settings.json values on container create.
18+
"settings": {
19+
"python.defaultInterpreterPath": "/opt/conda/bin/python",
20+
"python.linting.enabled": true,
21+
"python.linting.pylintEnabled": true,
22+
"python.formatting.autopep8Path": "/opt/conda/bin/autopep8",
23+
"python.formatting.yapfPath": "/opt/conda/bin/yapf",
24+
"python.linting.flake8Path": "/opt/conda/bin/flake8",
25+
"python.linting.pycodestylePath": "/opt/conda/bin/pycodestyle",
26+
"python.linting.pydocstylePath": "/opt/conda/bin/pydocstyle",
27+
"python.linting.pylintPath": "/opt/conda/bin/pylint"
28+
},
29+
30+
// Add the IDs of extensions you want installed when the container is created.
31+
"extensions": [
32+
"ms-python.python",
33+
"ms-python.vscode-pylance",
34+
"njpwerner.autodocstring",
35+
"ms-toolsai.jupyter",
36+
"donjayamanne.python-environment-manager",
37+
"ms-azuretools.vscode-docker"
38+
]
39+
}
40+
},
41+
42+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
43+
// "forwardPorts": [],
44+
45+
// Use 'postCreateCommand' to run commands after the container is created.
46+
"postCreateCommand": "conda init",
47+
48+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
49+
"remoteUser": "vscode",
50+
"features": {
51+
"ghcr.io/devcontainers/features/rust:1": {
52+
"version": "latest"
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)