This is how I do Python development today.
blackformatting source filesisortto organize importsmypystatic type checkingpylintlinting errorspoetryfor package managementpyproject.tomlcentralizes all tooling config
To run this, you first need to install these tools:
- pyenv https://github.com/pyenv/pyenv
- pipx https://pipx.pypa.io/stable/installation/
- poetry https://python-poetry.org/
- make https://www.gnu.org/software/make/
- MS Python Extension [link]
- Mypy for type checking (I use the pre-release version) [link]
- Black for formatting [link]
- Isort for sorting imports [link]
- Pylint for linting [link]
Note: if you clone this repository and open with VSCode, the .vscode/extensions.json file should suggest you to install them.
{
// makes the project tree cleaner by hiding pycache and other files
"files.exclude": {
"**/.classpath": true,
"**/.factorypath": true,
"**/.project": true,
"**/.pytest_cache": true,
"**/.settings": true,
"**/__pycache__": true
},
// makes the project tree cleaner by adding newlines at the end of files and removing trailing whitespace
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
// shows in-line suggestions as you type
"editor.inlineSuggest.enabled": true,
// sets black as the formatter
"editor.defaultFormatter": "ms-python.black-formatter",
// runs black whenever you save a file
"editor.formatOnSave": true,
// defines a ruler at 120 characters (matches the configuration in pyproject.toml for black)
"editor.rulers": [
120
],
// enables isort
"isort.check": true,
// uses isort from the active .venv
"isort.importStrategy": "fromEnvironment",
// runs isort whenever you save a file
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
// configure cache settings for mypy (faster execution) and force mypy to check untyped definitions
"mypy-type-checker.args": [
"--cache-dir=.mypy_cache/.vscode",
"--check-untyped-defs"
],
// uses mypy from the active .venv
"mypy-type-checker.importStrategy": "fromEnvironment",
// mypy runs on workspace (nice to know if you're breaking things elsewhere) but only recommended for smaller repos as it gets slower with larger code bases
"mypy-type-checker.reportingScope": "workspace",
"mypy-type-checker.severity": {
"error": "Error",
"note": "Information"
},
// disables pylint on typing (defaults to lint on save, which is faster)
"pylint.lintOnChange": false,
// uses pylint from the active .venv
"pylint.path": [
"pylint"
],
// visual aid when reading code by showing function return types, variable types and call argument names
"python.analysis.inlayHints.callArgumentNames": "all",
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.inlayHints.variableTypes": true,
// enables pytest and disables unittest when collecting and running tests from the workspace
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}