Description
Until now, Python code formatting used to be performed with isort
and black
, while flake8
was used for linting.
Moving forward, we might want to adopt ruff
for both tasks and no longer use the currently employed tools.
ruff
is an extremely fast Python linter and code formatter, that integrates the functionalities of several tools behind a single, common interface (https://docs.astral.sh/ruff/).
A first step in migrating the project towards using ruff
is to introduce a minimal configuration for this tool (and apply it to the project files accordingly), while simultaneously dropping isort
, black
and flake8
.
This is what PR ansys/pyaedt#6157 is aiming at on the pyaedt project.
Subsequent steps to complete the setup of ruff
shall aim at incrementally adding rules that the first minimal configuration will be ignoring, fixing the related linting/formatting errors in the Python files appropriately.
For this task, a useful command-line instruction can be used, which will return the number of errors flagged for each selected rule as well as the availability of automatic fixes: ruff check . --statistics
.
To restrict the analysis of project files by ruff
to a specific rule, so that reported errors can be reviewed on a rule by rule basis (which in turn should allow adding rules to the "select" list with greater granularity), the following command-line instruction can be used: ruff check . --select <rule code>
.