Skip to content

MNT Add initial setup for devcontainer - #31096

Merged
glemaitre merged 15 commits into
scikit-learn:mainfrom
lesteve:codespaces
Oct 2, 2025
Merged

glemaitre merged 15 commits into
scikit-learn:mainfrom
lesteve:codespaces

Conversation

@lesteve

@lesteve lesteve commented Mar 28, 2025

Copy link
Copy Markdown
Member

Instructions how to try it out are in #31091.

I guess let's try to keep feed-back about the user experience in #31091.

@github-actions

github-actions Bot commented Mar 28, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: d66ea43. Link to the linter CI: here

@betatim

betatim commented Apr 1, 2025

Copy link
Copy Markdown
Member

Want to make it "not a draft" so we can merge this?

@lesteve
lesteve marked this pull request as ready for review April 1, 2025 10:09
@lesteve

lesteve commented Apr 1, 2025

Copy link
Copy Markdown
Member Author

Want to make it "not a draft" so we can merge this?

Done 😉. I was planning to add some minimal doc somewhere, but this can be done in a further PR.

@ogrisel

ogrisel commented Apr 7, 2025

Copy link
Copy Markdown
Member

Maybe we should add some minimal doc first to avoid confusing people.

For instance, when opening VS Code on macOS on a latptop with an arm64/M1 processor with the scikit-learn source folder checked out on this branch, VS Code asked me if I wanted to reopen the project within the dev container but then it fails with the following log:

Details
[2025-04-07T09:52:24.373Z] Dev Containers 0.401.0 in VS Code 1.98.2 (ddc367ed5c8936efe395cffeec279b04ffd7db78).
[2025-04-07T09:52:24.373Z] Start: Resolving Remote
[2025-04-07T09:52:24.383Z] Setting up container for folder or workspace: /Users/ogrisel/code/scikit-learn
[2025-04-07T09:52:24.383Z] Context: desktop-linux
[2025-04-07T09:52:24.395Z] Start: Check Docker is running
[2025-04-07T09:52:24.395Z] Start: Run: docker version
[2025-04-07T09:52:24.419Z] Client:
 Version:           28.0.1
 API version:       1.48
 Go version:        go1.23.6
 Git commit:        068a01e
 Built:             Wed Feb 26 10:38:16 2025
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

[2025-04-07T09:52:24.420Z] Server: Docker Desktop 4.39.0 (184744)
 Engine:
  Version:          28.0.1
  API version:      1.48 (minimum version 1.24)
  Go version:       go1.23.6
  Git commit:       bbd0a17
  Built:            Wed Feb 26 10:40:57 2025
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.25
  GitCommit:        bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc:
  Version:          1.2.4
  GitCommit:        v1.2.4-0-g6c52b3f
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[2025-04-07T09:52:24.422Z] Stop (27 ms): Run: docker version
[2025-04-07T09:52:24.423Z] Stop (28 ms): Check Docker is running
[2025-04-07T09:52:24.423Z] Start: Run: docker volume ls -q
[2025-04-07T09:52:24.440Z] Stop (17 ms): Run: docker volume ls -q
[2025-04-07T09:52:24.440Z] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/Users/ogrisel/code/scikit-learn --filter label=vsch.quality=stable
[2025-04-07T09:52:24.456Z] Stop (16 ms): Run: docker ps -q -a --filter label=vsch.local.folder=/Users/ogrisel/code/scikit-learn --filter label=vsch.quality=stable
[2025-04-07T09:52:24.456Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --filter label=devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json
[2025-04-07T09:52:24.474Z] Stop (18 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --filter label=devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json
[2025-04-07T09:52:24.474Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn
[2025-04-07T09:52:24.491Z] Stop (17 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn
[2025-04-07T09:52:24.491Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn
[2025-04-07T09:52:24.505Z] Stop (14 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn
[2025-04-07T09:52:24.505Z] Running Dev Containers CLI:   up --user-data-folder /Users/ogrisel/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-736b008d-3df6-4ed2-857d-ebf2e221425b1744019543794 --workspace-folder /Users/ogrisel/code/scikit-learn --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --id-label devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[2025-04-07T09:52:24.530Z] ProxyResolver#loadSystemCertificates count
[2025-04-07T09:52:24.538Z] ProxyResolver#loadSystemCertificates count filtered
[2025-04-07T09:52:24.538Z] Start: Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/ogrisel/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-736b008d-3df6-4ed2-857d-ebf2e221425b1744019543794 --workspace-folder /Users/ogrisel/code/scikit-learn --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --id-label devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[2025-04-07T09:52:24.683Z] @devcontainers/cli 0.74.0. Node.js v20.18.2. darwin 24.2.0 arm64.
[2025-04-07T09:52:24.683Z] Start: Run: docker buildx version
[2025-04-07T09:52:24.737Z] Stop (54 ms): Run: docker buildx version
[2025-04-07T09:52:24.738Z] github.com/docker/buildx v0.21.1-desktop.2 65a04767fd3000fbac3b7120cc6115d518678e33
[2025-04-07T09:52:24.738Z] 
[2025-04-07T09:52:24.738Z] Start: Run: docker -v
[2025-04-07T09:52:24.749Z] Stop (11 ms): Run: docker -v
[2025-04-07T09:52:24.749Z] Start: Resolving Remote
[2025-04-07T09:52:24.751Z] Start: Run: git rev-parse --show-cdup
[2025-04-07T09:52:24.762Z] Stop (11 ms): Run: git rev-parse --show-cdup
[2025-04-07T09:52:24.763Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --filter label=devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json
[2025-04-07T09:52:24.782Z] Stop (19 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --filter label=devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json
[2025-04-07T09:52:24.782Z] Start: Run: docker inspect --type image mcr.microsoft.com/devcontainers/universal:2
[2025-04-07T09:52:24.799Z] Stop (17 ms): Run: docker inspect --type image mcr.microsoft.com/devcontainers/universal:2
[2025-04-07T09:52:24.800Z] Loading 40 extra certificates from /var/folders/_y/lfnx34p13w3_sr2k12bjb05w0000gn/T/vsch/certificates-d83a8480b394e47ecb8e4412305838f4701c4ac72f86d49f2957b06585b2160c.pem.
[2025-04-07T09:52:25.182Z] Error fetching image details: No manifest found for mcr.microsoft.com/devcontainers/universal:2.
[2025-04-07T09:52:25.183Z] Start: Run: docker pull mcr.microsoft.com/devcontainers/universal:2
[2025-04-07T09:52:25.808Z] 2: Pulling from devcontainers/universal
[2025-04-07T09:52:25.906Z] no matching manifest for linux/arm64/v8 in the manifest list entries
[2025-04-07T09:52:25.907Z] Stop (724 ms): Run: docker pull mcr.microsoft.com/devcontainers/universal:2
[2025-04-07T09:52:25.907Z] []
[2025-04-07T09:52:25.907Z] Error response from daemon: No such image: mcr.microsoft.com/devcontainers/universal:2

[2025-04-07T09:52:25.907Z] Error: Command failed: docker inspect --type image mcr.microsoft.com/devcontainers/universal:2
[2025-04-07T09:52:25.907Z]     at ytA (/Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:468:1260)
[2025-04-07T09:52:25.907Z]     at bH (/Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:468:1002)
[2025-04-07T09:52:25.907Z]     at async TtA (/Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:485:3848)
[2025-04-07T09:52:25.907Z]     at async iB (/Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:485:4963)
[2025-04-07T09:52:25.907Z]     at async wrA (/Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:666:203)
[2025-04-07T09:52:25.907Z]     at async DrA (/Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:665:14830)
[2025-04-07T09:52:25.907Z]     at async /Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js:485:1190
[2025-04-07T09:52:25.910Z] Stop (1372 ms): Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/ogrisel/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-736b008d-3df6-4ed2-857d-ebf2e221425b1744019543794 --workspace-folder /Users/ogrisel/code/scikit-learn --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --id-label devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[2025-04-07T09:52:25.910Z] Exit code 1
[2025-04-07T09:52:25.913Z] Command failed: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users/ogrisel/.vscode/extensions/ms-vscode-remote.remote-containers-0.401.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/ogrisel/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-736b008d-3df6-4ed2-857d-ebf2e221425b1744019543794 --workspace-folder /Users/ogrisel/code/scikit-learn --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/Users/ogrisel/code/scikit-learn --id-label devcontainer.config_file=/Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/ogrisel/code/scikit-learn/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --include-configuration --include-merged-configuration
[2025-04-07T09:52:25.913Z] Exit code 1

I think this is related to devcontainers/images#545.

So maybe we should at least document the purpose of this file, namely, to be used to open the scikit-learn project via the GitHub Codespaces editor.

@ogrisel

ogrisel commented Apr 7, 2025 •

Copy link
Copy Markdown
Member

I am trying again after editing the json config to use base:debian instead of universal:2.

EDIT: the initial setup seems to be fine but you still end-up in a non working env:

vscode ➜ ~ $ micromamba activate sklearn-dev
critical libmamba Cannot activate, prefix does not exist at: '/home/vscode/micromamba/envs/sklearn-dev'
vscode ➜ ~ $ ls /home/vscode/micromamba/
conda-meta  envs  etc
vscode ➜ ~ $ ls /home/vscode/micromamba/envs/

So we should definitely manage expectations and let users now that this devcontainer config is only meant to be used via GitHub Codespaces and not intended for local dev with VS Code.

@betatim

betatim commented Apr 7, 2025

Copy link
Copy Markdown
Member

After a quick conversation with perplexity.ai it seems like there is no way to have a devcontainer setup that is only used by code spaces and does not lead to a prompt by VS Code when used locally. But maybe VS Code remembers your preference? Said differently: it would be nice to have a documentation for people on how to stop VS Code asking you to use a devcontainer every time you start your editor.

I tried to experiment with this locally but I never get prompted :-/ Maybe because I don't have docker installed on my laptop?

I think having an easy way to avoid being prompted every time would be nice for users (and not trivial to find out how to do this) and would reduce the number of people who use the devcontainer. The latter might be important unless we want people to use the container also locally, in which case we need to somehow get ready to answer questions about things that go wrong. I've used devcontainers a bit for cuml, and while it was nice at first to solve setup problems, over time you discover more and more things that you need to "fix up" (e.g. ssh key forwarding/sharing for signed git commits, accessing local directories with datasets, etc - none of these are rocket science, but also not 1min jobs)

@lesteve

lesteve commented Sep 26, 2025

Copy link
Copy Markdown
Member Author

Getting back to this, what would it take to get this merged?

A few lines in .devcontainer/devcontainer.json to explain that this is only meant to be used in GitHub codespaces? Do you insist on having to use Debian so that it works on macOS when trying to run the devcontainers through VSCode?

I would think it would be useful to have it as backup for the PyData upcoming sprint and be able to test it, for people that have trouble getting setup.

@lesteve

lesteve commented Sep 26, 2025

Copy link
Copy Markdown
Member Author

I changed the base docker image to be smaller so that the container starts a bit quicker.

https://github.com/devcontainers/templates/tree/main/src/ubuntu claims that it support arm64/Apple Silicon so maybe the issue with running locally the devcontainer on macOS arm has gone away?

@lesteve

lesteve commented Sep 26, 2025 •

Copy link
Copy Markdown
Member Author

To try using codespaces on this PR:

  • go to the top of this PR
  • On the RHS Code -> Codespaces
  • Click the + icon to start a new codespace
image

Doesn't work for me on Firefox for me (and Tim according to #31091 (comment)) but it works for @StefanieSenger so it may be down to browser settings (like addon/3rd party cookies etc ...). Works fine for me on Chromium. This was also noted in #31091.

@betatim

betatim commented Sep 29, 2025

Copy link
Copy Markdown
Member

Can we make a separate repository (for sprints) that contains sprint setup instructions and a devcontainer? I don't remember everything I was thinking when we last discussed this, but it was the first idea that pop into my head when re-reading the last few comments on this PR.

@lesteve

lesteve commented Sep 30, 2025 •

Copy link
Copy Markdown
Member Author

Codespaces is setup to open the repo code as a project in the VSCode tab. I guess if you do it in another repo, you would need to do additional work to do clone the scikit-learn repo (easy) and open it as a project in VSCode (not sure how easy this is).

This also feels more natural to go to the repo you want to work on i.e. scikit-learn/scikit-learn and open a Codespace directly on it.

To be honest, I am not sure what prevents us from merging this PR to try it out in a sprint ... the worst possible outcome is that the devcontainer is not that useful for sprints or breaks too often without us realizing and we eventually remove it.

On having a separate repo for sprint instructions, I feel this is a slightly tangential discussion.

@betatim

betatim commented Sep 30, 2025

Copy link
Copy Markdown
Member

Codespaces is setup to open the repo code as a project in the VSCode tab. I guess if you do it in another repo, you would need to do additional work to do clone the scikit-learn repo (easy) and open it as a project in VSCode (not sure how easy this is).

I agree the most natural place is the repo itself. What I was thinking is that if we mainly want people to use this for sprints, then maybe having a dedicated repo for that would make sense. With instructions and devcontainer and so on. (There is already a sprint repo that I keep referring to for short beginner events, but I can't find it right now).

To be honest, I am not sure what prevents us from merging this PR to try it out in a sprint ... the worst possible outcome is that the devcontainer is not that useful for sprints or breaks too often without us realizing and we eventually remove it.

I think we can try it. The biggest downside that I expect is that I'll have to work out how to tell VS Code to stop asking me to use the devcontainer. But hopefully that is easy

@lesteve

lesteve commented Sep 30, 2025 •

Copy link
Copy Markdown
Member Author

For further reference: here is what happens for now when you open the scikit-learn folder in VSCode (on this PR branch). If you don't take any action the dev container is not used which is what you want.

image

If you click on "Don't show again" you will never see this popup again. There is also a setting remote.containers.showReloadPrompt to influence this, see https://github.com/orgs/devcontainers/discussions/138.

I would guess that not too many people are likely to click "Reopen in Container" and be confused in case it is broken, but maybe I am wrong ...

I guess @betatim clicked "Don't show again" which is why he doesn't see the popup.

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try it, use PyData sprinters as testers and see what we think

@StefanieSenger

Copy link
Copy Markdown
Member

This will be a nice tool for new and occasional contributors, thanks @lesteve!

I think we can add

pip install --editable . \
   --verbose --no-build-isolation \
   --config-settings editable-verbose=true

to the shell file, so that users get a ready to use setup, no?

@lesteve

lesteve commented Oct 1, 2025 •

Copy link
Copy Markdown
Member Author

Interesting suggestion @StefanieSenger, I did not think about this at all.

A Part of me likes it:

  • less work to do for the people using the codespace
  • meson editable install should just make it work in principle, i.e. rebuilding what needs to be rebuild when you change some files.

A part of me doesn't like it so much

  • it will add ~7 minutes to the container build time. That means the first time you create your codespace it will go to ~3 minutes to ~10 minutes. Note that in the future, there are strategies to mitigate this through prebuilds as mentioned in RFC set up Codespaces to ease contributor experience especially during sprints? #31091 (comment).
  • it if fails, it will be harder to find the build log I think. Needs to be double-checked.
  • I somehow think as building scikit-learn as an "important" part of contributing and somehow I feel a bit unsure about hiding it.

@betatim

betatim commented Oct 1, 2025

Copy link
Copy Markdown
Member

Maybe we can print a message with the command when the container starts or somehow display it? Or even more adventurous: can we run the install command but have meson do nothing until the package gets installed the first time?

I think I'd use codespaces mostly for making small typo fixes or similar "small things" - in those cases having to wait for it to start is annoying.

@lesteve

lesteve commented Oct 1, 2025 •

Copy link
Copy Markdown
Member Author

Yeah there is definitely room for improvements in the future.

Here is my current plan:

@StefanieSenger

Copy link
Copy Markdown
Member

I agree with the argument that building the package is an important part of contributing.

So this comes down to not build automatically, but to have beginner-friendly documentation for it. Maybe a small section in the contribution guide that introduces codespaces as an alternative for beginners that explains how to build from source (because it won't be obvious to people) and also how to see the build docs, which one needs to expose a port for (python -m http.server --directory doc/_build/html/stable 8000).

@glemaitre
glemaitre self-requested a review October 1, 2025 21:01
@glemaitre

Copy link
Copy Markdown
Member

I have some weird experience but I'm using cursor:

  • When opening in container for the first time, it seems that it hangs. Opening the same container seems to work
  • When trying to launch bash, it does not activate the micromamba environment. Calling micromamba by hands lead to a Permission denied.

I'm not going to merge right away but we can quickly check before the sprint.

@lesteve

lesteve commented Oct 2, 2025

Copy link
Copy Markdown
Member Author

When opening in container for the first time, it seems that it hangs.

Basically the first time you need to wait ~3 minutes for the container to build. In VSCode there is a small popup pointing to the build log when it starts to build. We probably want to look at this and see whether there is any relevant information in there.

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I was not patient enough apparently. It would be nice to have the output of the setup.sh. So we can see how to improve further.

@glemaitre
glemaitre merged commit fe1ff2f into scikit-learn:main Oct 2, 2025
@glemaitre

Copy link
Copy Markdown
Member

Actually, testing in VS code with @rouk1, he got the output of the setup.sh. So maybe my extension via cursor is not working as good as the bare vs code. So it is good.

@lesteve

lesteve commented Oct 17, 2025

Copy link
Copy Markdown
Member Author

FYI: the VSCode popup situation and how to remove it was summarized in #32516 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants