Minimal VSCode settings and extensions configuration for Python with ruff
Contents
This morning while working on my AoC submission, I wondered what the simplest procedure was for sharing a minimal setup for editing Python in Visual Studio Code using ruff for formatting, linting and import sorting, and doing all of that automatically on save.
It turns out that you can just store the following extensions.json
and settings.json
in the .vscode
sub-directory of your source directory, and all of the above will be done. As a bonus, you can use the ruff.toml
example below to customise your ruff setup.
This is an opinionated little setup that will:
- Suggest installing the oficial ruff formatter and linter extension;
- Configure some extra mostly docstring-related checks for ruff;
- Format all files in this project automatically, when you save;
- Organize Python imports when you save;
- Activate PyLance, the Python type-checker that comes with the Python extension.
If you are working with others on the same project, and you’re not using devcontainers, you could consider checking these in to git.
extensions.json
This goes in ${workspaceFolder}/.vscode/extensions.json
or merge with whatever you have there:
|
|
settings.json
The following goes in ${workspaceFolder}/.vscode/settings.json
, or merge with whatever you have there.
|
|
ruff.toml
This goes in ${workspaceFolder}/ruff.toml
.
I deviate from the standard 88 characters per line, and I strongly prefer the numpydoc-style docstrings (readability, easy conversion to markdown for openapi.json, numpy familiarity), but you can of course customize to your liking.
|
|