Ruff Python Linter

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Ruff Python Linter

Post by jussij »

Ruff is a linter for the Python language and can be found here: https://github.com/astral-sh/ruff

More details on how to configure Ruff can be found here: https://docs.astral.sh/ruff

To use this linter inside Zeus do the following:

1. Download the Linter
Go to the releases page and select the ruff-x86_64-pc-windows-msvc.zip asset.

The releases page is found here: https://github.com/astral-sh/ruff/releases

2. Ruff Installation
The installation is as simple as extracting the executable from the zip file, however the location of that executable will need to be in the PATH.

The easiest option is to unzip the file into this Zeus directory as this will mean the executable is automatically in the PATH:

Code: Select all

Zeus (x64)\zGNU
3. Zeus Configuration - Ruff Formatting
To use Ruff as a formatting tool refer to this link: https://www.zeusedit.com/phpBB3/viewtopic.php?t=8408

4. Zeus Configuration - Ruff Linting
Ruff can be run inside Zeus as a Python tool, which can be done by using the Options, Document Types menu, editing the Python Document Type and adding the tool using the Tools panel.

However, another option is to configure Ruff as the compiler for the Python Document Type.

This is done be editing the Python Document Type and then adding Ruff to the Compiler panel rather than the Tools panel.

In that compiler panel set the following values:

Code: Select all

Command Line: ruff.exe check "$f"

Errors Regex: Error:|error:|File .*, line [0-9]+

Warnings Regex: :[0-9]+:[0-9]+:

[x] Capture Standard Output   [x] Capture Standard Error

(o) Display on any output
These changes should look like this:
ruff-compile.png
ruff-compile.png (148.57 KiB) Viewed 9 times
5. Using Ruff Inside Zeus
Once configured, Ruff can be used to check a file using the Compiler, Compile menu.

For example, assume the following Example.py file is open in Zeus:

Code: Select all

from typing import Iterable

import os

def sum_even_numbers(numbers: Iterable[int]) -> int:
    """Given an iterable of integers, return the sum of all even numbers in the iterable."""
    return sum(
        num for num in numbers
        if num % 2 == 0
    )
With this file as the active document, using the Compiler, Compile menu will result in the following output:
ruff-output.png
ruff-output.png (55 KiB) Viewed 9 times
Clicking on the warning message found in that output window will navigate back to the file, to the line that has the issue.

Jussi
Post Reply