Monday, October 17, 2022

A template for new Python projects with devcontainer support

I've recently been learning more about devcontainers, Codespaces, and Github templates, and just put together a project using them all.

A devcontainer is a way to use a Docker container as a development environment. The container can already be initialized with all the necessary environment dependencies, like the right version of Python and the desired development tools, so you can get to work immediately inside the container. As Python developers, we often achieve a similar outcome using virtual environments (venv) but devcontainers work for any development environment, and can specify more than just the language and package dependencies. A devcontainer can even describe desired settings for the editor.

VS Code has support for devcontainers via the Dev Containers extension. Github Codespaces is built around the idea of containers, since it's basically a VS Code editor that opens up the devcontainer for the given repository.

Since there was a lot of interest in my post on setting up a Python project, I've made a devcontainer version of my standard Python project setup:

You can open that repository in Codespaces immediately to see what it's like (by clicking the Code dropdown), or you can make a new repository based off that repository (since I've marked it as a template), and start writing your own code inside it.

I personally make a lot of new Python projects lately, since I'm experimenting with so much Python for my job, so I'm looking forward to having a 1-click project setup with all my favorite tools for code quality and testing baked right in. Yay for programmer productivity! 🎉

No comments: