Skip to content

Commit fbb4127

Browse files
authored
Add default devcontainer using conda (#35072)
Now that VSCode support [multiple devcontainer configs](https://github.com/microsoft/vscode-docs/blob/main/remote-release-notes/v1_75.md#folders-with-multiple-devcontainerjson-files), we can add a default config that uses conda (similar to the gitpod config). Closes #34560.
1 parent 525c625 commit fbb4127

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

.devcontainer/devcontainer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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/debian
3+
{
4+
"name": "Conda",
5+
"image": "mcr.microsoft.com/vscode/devcontainers/base:0-bullseye",
6+
7+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
8+
"remoteUser": "vscode",
9+
10+
// Setup conda environment
11+
"onCreateCommand": ".devcontainer/onCreate-conda.sh",
12+
13+
// Install additional features.
14+
"features": {
15+
// For config options, see https://github.com/devcontainers/features/tree/main/src/conda
16+
"ghcr.io/devcontainers/features/conda": {
17+
"version": "latest",
18+
"addCondaForge": "true"
19+
}
20+
},
21+
"customizations": {
22+
"vscode": {
23+
"extensions": [
24+
"guyskk.language-cython",
25+
"ms-python.isort",
26+
"ms-toolsai.jupyter",
27+
"ms-python.vscode-pylance",
28+
"ms-python.pylint",
29+
"ms-python.python",
30+
"lextudio.restructuredtext",
31+
"trond-snekvik.simple-rst"
32+
]
33+
}
34+
}
35+
}

.devcontainer/onCreate-conda.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Do not keep running on errors
2+
set -e
3+
4+
# Create conda environment
5+
./bootstrap-conda
6+
conda install mamba -n base -c conda-forge -y
7+
mamba env create --file src/environment-dev.yml || mamba env update --file src/environment-dev.yml
8+
conda init bash
9+
10+
# Build sage
11+
conda run -n sage-dev ./bootstrap
12+
conda run -n sage-dev ./configure --with-python=/opt/conda/envs/sage-dev/bin/python --prefix=/opt/conda/envs/sage-dev
13+
conda run -n sage-dev pip install --no-build-isolation -v -v -e ./pkgs/sage-conf ./pkgs/sage-setup
14+
conda run -n sage-dev pip install --no-build-isolation -v -v -e ./src

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ src/ENV/
221221
src/env.bak/
222222
src/venv.bak/
223223

224-
# devcontainer
225-
/.devcontainer/devcontainer.json
226-
227224
# mypy
228225
**/.mypy_cache/
229226

src/doc/en/developer/portability_testing.rst

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,23 +1164,7 @@ provides sample ``devcontainer.json`` configuration files
11641164
<https://github.com/sagemath/sage/tree/develop/.devcontainer/>`_ for this
11651165
purpose.
11661166

1167-
To get started, symlink (or copy) one of the sample files to
1168-
``$SAGE_ROOT/.devcontainer/devcontainer.json``. For example, choose
1169-
`$SAGE_ROOT/.devcontainer/portability-ubuntu-jammy-standard/devcontainer.json
1170-
<https://github.com/sagemath/sage/tree/develop/.devcontainer/portability-ubuntu-jammy-standard/devcontainer.json>`_, which uses the Docker image based on ``ubuntu-jammy-standard``,
1171-
the most recent
1172-
development version of Sage (``dev`` tag), and a full installation of
1173-
the Sage distribution (``with-targets``).
1174-
1175-
In macOS for example, you can do this using the shell as follows::
1176-
1177-
[mkoeppe@sage sage] $ (cd .devcontainer && ln -s portability-ubuntu-jammy-standard/devcontainer.json .)
1178-
1179-
Now start VS Code::
1180-
1181-
[mkoeppe@sage sage] $ code .
1182-
1183-
Then VS Code may prompt you whether you would like to open the current
1167+
If you open the sage folder in VS Code, it may prompt you whether you would like to open the current
11841168
directory in the dev container (yes). If it does not, use the command palette
11851169
(:kbd:`Ctrl` + :kbd:`Shift` + :kbd:`P`), enter the command "Remote-Containers:
11861170
Reopen Folder in Container" , and hit :kbd:`Enter`.
@@ -1190,6 +1174,14 @@ application, then in the command palette of VS Code, enter "Remote-Containers:
11901174
Open Folder in Container", and hit :kbd:`Enter`, and choose the directory
11911175
``$SAGE_ROOT`` of your local Sage repository.
11921176

1177+
VS Code then prompts you to choose a dev container configuration.
1178+
For example, choose "Ubuntu jammy" `.devcontainer/portability-ubuntu-jammy-standard/devcontainer.json
1179+
<https://github.com/sagemath/sage/tree/develop/.devcontainer/portability-ubuntu-jammy-standard/devcontainer.json>`_,
1180+
which uses the Docker image based on ``ubuntu-jammy-standard``, the most recent
1181+
development version of Sage (``dev`` tag), and a full installation of
1182+
the Sage distribution (``with-targets``). Other dev container configurations
1183+
are described below.
1184+
11931185
Once VS Code starts configuring the dev container, by clicking on "show log",
11941186
you can see what it does:
11951187

@@ -1225,8 +1217,7 @@ in a terminal, `open a new terminal in VS Code
12251217
``configure`` script.
12261218

12271219
You can edit a copy of the configuration file to change to a different platform, another
1228-
version, or build stage. After editing the configuration file (or changing the
1229-
symlink), run "Remote-Containers: Rebuild Container" from the command
1220+
version, or build stage. After editing the configuration file, run "Remote-Containers: Rebuild Container" from the command
12301221
palette. See the `VS Code devcontainer.json reference
12311222
<https://code.visualstudio.com/docs/remote/devcontainerjson-reference>`_
12321223
and the `GitHub introduction to dev containers
@@ -1248,8 +1239,7 @@ installation of SageMath in this container by building from the current source t
12481239
project <https://hub.docker.com/r/computop/sage/>`_, providing
12491240
SnapPy, Regina, PHCPack, etc.
12501241

1251-
If you want to use one of these ``devcontainer.json`` files, symlink (or copy)
1252-
it and start VS Code as explained above. After VS Code finished configuring the
1242+
After VS Code finished configuring the
12531243
dev container, to use Sage in a terminal, `open a new terminal in VS Code
12541244
<https://code.visualstudio.com/docs/terminal/basics>`_, type ``./sage`` and hit
12551245
:kbd:`Enter`.
@@ -1284,8 +1274,7 @@ work without change) or to adapt them to your needs.
12841274
project <https://hub.docker.com/r/computop/sage/>`_, providing
12851275
SnapPy, Regina, PHCPack, etc.
12861276

1287-
If you want to use one of these ``devcontainer.json`` files, symlink (or copy)
1288-
it and start VS Code as explained above. After VS Code finished configuring the
1277+
After VS Code finished configuring the
12891278
dev container, to use Sage in a terminal, `open a new terminal in VS Code
12901279
<https://code.visualstudio.com/docs/terminal/basics>`_, type ``sage`` and hit
12911280
:kbd:`Enter`. (Do not use ``./sage``; this will not work because the source

0 commit comments

Comments
 (0)