Project: QGIS

Version: 3.32

Feature: Reformat code action for code editors

A "format code" action has been added to the Python Console Editor which allows for the automated linting/ pretty printing of code in line with the capabilities of modern code editors.
Additional configuration settings for this action include:

  • Format on save: if enabled, formatting is applied just before saving the script
  • Sort imports: Sort import statements using isort
  • Max line length: Control how the formatter will wrap the lines, and controls the editor ruler

The Formatter options allow for a selection between the autopep8 or black linting tools and provide the following additional options:
- Level (autopep8 only) See Autopep8 aggressiveness level
- Normalize quotes (black only): Replace all single quotes with double quotes if possible
Sorting operations are provided using isort, which will allow for sorting import statements in three different groups:

  • standard library imports (re, os, sys, json, ...)
  • third-party modules (PyQt5, pandas, dateutil, ...)
  • first-party modules (qgis, processing, ...)

These operations will facilitate consistent development in line with industry best practices and improve code quality, consistency, readability, and operational efficiency (especially when coupled with version control systems).

This feature was developed by Yoann Quenach de Quivillic