[Python] Configure ruff to ignore environment-provided globals

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    How can we configure the Ruff linter to ignore environment-provided global variables?

    I have a python codebase which contains notebooks, that run in a databricks environment. The environment provides globals such as spark.

    A perfectly valid example in that context would be:

    # Databricks notebook source
    df = spark.sql("SELECT 'hello world'")
    df.show()


    ruff check raises a F821 undefined-name error on this minimal example.

    We could circumvent the problem by

    • Explicitly loading the specific globals. This adds unnecessary complexity since the code will only ever run where the globals are present.
    • Clutter the code with # noqa: F821

    Are there other options?

    Continue reading...

Compartilhe esta Página