-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Dev Container configuration #8024
base: main
Are you sure you want to change the base?
Changes from 15 commits
69431ef
712ab6b
98e917d
caf1e7a
6cb73a7
1c43a32
e287fb9
9cbb6b6
844f788
f3e3d65
0d8845b
9fc341f
7076013
ff80d37
4372fdc
025ae58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||
FROM mcr.microsoft.com/devcontainers/python:3-bookworm | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
RUN export DEBIAN_FRONTEND=noninteractive \ | ||||||||||||||||||||||||||||||||||||||||
&& apt-get update && apt-get install -y xdg-utils \ | ||||||||||||||||||||||||||||||||||||||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this might relate to devcontainers/images#885 (not sure how VSCode wires that up -- maybe a script that emits an escape sequence?)... I'd rather let upstream figure this out (if we keep the Microsoft image) than try and solve it downstream. |
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
ENV POETRY_HOME="/opt/poetry" | ||||||||||||||||||||||||||||||||||||||||
ENV PATH="$POETRY_HOME/bin:$PATH" | ||||||||||||||||||||||||||||||||||||||||
RUN curl -sSL https://install.python-poetry.org | python3 - | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+3
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't really want to depend on the script here, and we're not actively encourage it's use either. Instead a manual install flow is perfectly suitable, in my opinion:
Suggested change
This way we have a virtualenv holding Poetry (like the script creates, but explicitly controlled), and a separate virtual env for the project. This is a generic template following our recommendations that can be duplicated by other projects making use of Poetry + Dev Containers as well. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "Poetry", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"context": ".." | ||
}, | ||
"postCreateCommand": "bash .devcontainer/setup.sh", | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"python.formatting.blackPath": "black", | ||
"python.formatting.provider": "black", | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.pytestPath": "pytest", | ||
"python.editor.codeActionsOnSave": { | ||
"source.fixAll": true | ||
}, | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
] | ||
}, | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.black-formatter", | ||
"charliermarsh.ruff" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
poetry install | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know the Devcontainer workflow. The poetry run pre-commit install confuse me. I don't know if the purpose of setup.sh is run before start working in the new feature/bug/etc, in that way the pre-commit install make sense for me, but the other commands don't. In any case, I like this idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the The commands in this script are those which are denoted in https://python-poetry.org/docs/contributing/#local-development. You probably don't need to run This script/configuration doesn't change anything about the core development workflow as prescribed in the docs today. |
||
poetry run pytest | ||
poetry run mypy | ||
poetry run pre-commit install | ||
Comment on lines
+2
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should drop these lines; if the project is in a failing state we shouldn't cause issues with Dev Container creation... Imagine if a user modifies some files such that ruff is not happy, and then tries to activate Dev Containers with their editor -- now they have to stash or similar to avoid a failure here (and not all users will understand that). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance we can use a standard
library/python
base image here? If not, what does the Microsoft-supplied base image add that enhances use of Dev Containers?mcr.microsoft.com
tends to be pretty slow for users in different parts of the world, compared to Docker Hub; though this is a secondary concern for me.