-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add devcontainer #3556
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
base: main
Are you sure you want to change the base?
Add devcontainer #3556
Conversation
|
@dsfaccini In the beginning, I had thought accessing the Ollama host instance with
Thanks for your good comments so far. Hope together we can find a stable and minimal dev container setup. Would be helpful for new contributers to get started. |
.devcontainer/Dockerfile
Outdated
| @@ -0,0 +1,27 @@ | |||
| ARG PYTHON_VERSION=3.11 | |||
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.
Let's use 3.12 as in .python-version
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.
Ok. Changed to 3.12.
.devcontainer/Dockerfile
Outdated
| # Enable Docker BuildKit for cache mounts | ||
| ENV DOCKER_BUILDKIT=1 | ||
|
|
||
| # Install system dependencies with cache mount for faster rebuilds (pinned versions) |
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.
Pinning means we'll probably never update these; could we not pin even if that means the cache would be invalidated more often?
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.
No. Unrelated to cache. This was for sake of reproducibility and avoid "works on my machine" issues.
I have changed the pinned to latest versions. Less maintenance. I do not expect problems here.
.devcontainer/README.md
Outdated
| @@ -0,0 +1,36 @@ | |||
| ## Requirements | |||
|
|
|||
| Please ensure that both [Docker](https://docs.docker.com/desktop/) and optionally [Ollama](https://ollama.com/download) are installed and running on the host machine. To configure your IDE, mount your own `.vscode/` or `.cursor/` folders by uncommenting the `mounts` section in `devcontainer.json`. | |||
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.
"ensure that both X and optionally Y" is a bit contradictory :) I'd rather have hard requirements, and then some section on optional things
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.
Good point. Fixed.
.devcontainer/README.md
Outdated
|
|
||
| The dev container is built using a hybrid approach: the `Dockerfile` provides low-level customization, while `devcontainer.json` is used for fine-tuning and IDE integration. Minor changes to `devcontainer.json` do not require a full rebuild of the entire image, which speeds up the development workflow. | ||
|
|
||
| 1. The `Dockerfile` is based on Microsoft's Debian-style [Bookworm image for Python 3.11](https://hub.docker.com/r/microsoft/devcontainers-python). It uses a non-root user named `vscode` and installs system dependencies and `uv`. |
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.
3.12 please!
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.
Fixed.
.devcontainer/devcontainer.json
Outdated
| // For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
| // README at: https://github.com/devcontainers/templates/tree/main/src/python | ||
| { | ||
| "name": "Python 3", |
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.
Pydantic AI?
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.
Fixed.
| # ============================================================================ | ||
|
|
||
| # OpenAI (Required for: OpenAI models, OpenAI-compatible providers) | ||
| # Get your key at: https://platform.openai.com/api-keys |
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.
This will get outdated, I'd rather just link to the docs for the provider in question
|
|
||
| # Brave Search (Optional - for web search tools) | ||
| # Get your key at: https://brave.com/search/api/ | ||
| # BRAVE_API_KEY= |
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.
We don't have anything Brave related in Pydantic AI
| # GitHub Personal Access Token (Optional - for MCP GitHub server) | ||
| # Create at: https://github.com/settings/tokens | ||
| # Needs: repo, read:org scopes | ||
| # GITHUB_PERSONAL_ACCESS_TOKEN= |
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.
We don't auto install this so we shouldn't have this
|
|
||
| # PostgreSQL with pgvector (Optional - for RAG examples) | ||
| # Default when using docker-compose pgvector service: | ||
| # PGVECTOR_DATABASE_URL=postgresql://postgres:postgres@localhost:54321/postgres |
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.
I'd rather this file stick to the point, so we don't have to struggle to keep it up to date when we add examples etc. If the example docs states to set a given env var, the user can figure out how to do that in the devcontainer.
For maintenance burden reasons, let's limit this file to the most popular providers; the user can figure out how to set the rest.
| # - For testing, use test models or Ollama to avoid API costs | ||
| # - Never commit this file with real API keys | ||
| # - Add .env to .gitignore (already done in this project) | ||
| # - See README.md for detailed setup instructions per provider |
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.
This should direct them to the docs shouldn't it?
| make lint | ||
| make typecheck | ||
| make test | ||
| echo "Dev container built and run successfully" |
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.
As it stands, this CI step will always succeed, even if any of the steps above failed.
For example, on this PR the output currently shows this error, even though the step shows as green:
Coverage failure: total of 99.99 is less than fail-under=100.00
- Can we please fix this job to fail when any of the steps fail?
- Can we get coverage to 100%? (or mark the uncovered lines as
pragma: lax no coverif we can't)
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.
The CI job can now fail, see set -o errexit. Coverage is now 100%.
|
@DouweM Thanks for the helpful comments. They resulted in some major changes. The biggest is the switch from a For |
The pull request adds a new dev container for
pydantic-ai. It is built using a hybrid approach: theDockerfileprovides low-level customization, whiledevcontainer.jsonis used for fine-tuning and IDE integration. Minor changes todevcontainer.jsondo not require a full rebuild of the entire image, which speeds up the development workflow.The
Dockerfileis based on Microsoft's Debian-style Trixie image for Python 3.12. It uses a non-root user namedvscodeand installs system dependencies,uv, and the Ollama client. Note that the Ollama instance runs on the host machine for performance reasons.The
devcontainer.jsonis based on Microsoft's dev container template for Python 3. It installs additional development tools viafeatures, sets important environment variables, and runsuv sync. The container does not enforce any specific IDE configuration; developers are encouraged to mount their own.vscode/or.cursor/folders externally.Added
Dockerfileanddevcontainer.json