Skip to content

Instantly share code, notes, and snippets.

@IzzleNizzle
Last active December 31, 2022 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IzzleNizzle/997f36145db751ca6f340af8e5dde07c to your computer and use it in GitHub Desktop.
Save IzzleNizzle/997f36145db751ca6f340af8e5dde07c to your computer and use it in GitHub Desktop.
Configure Formatter and Linter for a Python Dev Container using VSCode
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker
{
"name": "Python Dev Container w/ Linter & Formatter",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"postCreateCommand": {
"installLint": "pip install flake8",
"installFormatter": "pip install black",
"installDeps": "pip install -r ${containerWorkspaceFolder}/app/requirements.txt",
"installApp": "pip install -e ${containerWorkspaceFolder}/"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/devcontainers/features/python:1": {}
},
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.formatting.provider": "black",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"python.linting.flake8Enabled": true,
// https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
"python.linting.flake8Args": [
"--ignore=E203",
"--max-line-length=88"
]
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python"
]
}
},
// Set container env variables as desired
"remoteEnv": {}
}
// this installs formatter,linter before installing the project dependancies.
...
"postCreateCommand": {
"installLint": "pip install flake8",
"installFormatter": "pip install black",
"installDeps": "pip install -r ${containerWorkspaceFolder}/app/requirements.txt",
"installApp": "pip install -e ${containerWorkspaceFolder}/"
},
...
// This part is for specifying how tools operate
...
"customizations": {
"vscode": {
"settings": {
"python.formatting.provider": "black",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"python.linting.flake8Enabled": true,
// https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
"python.linting.flake8Args": ["--ignore=E203", "--max-line-length=88"]
},
...
}
},
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment