fix(config.py): fix crashes if settings.yml is not up to date by electron271 · Pull Request #887 · allthingslinux/tux

Reviewer's Guide

Auto-merges missing config keys from settings.yml.example to prevent crashes and replaces manual ALLOW_SYSADMINS_EVAL fallback with a direct merged config lookup.

Sequence Diagram for Configuration Loading and Merging

sequenceDiagram
    participant App as Application
    participant CPY as "config.py module"
    participant UserConfig as "settings.yml (user)"
    participant DefaultConfig as "settings.yml.example (default)"
    participant LoggerSvc as "Logger"

    App->>CPY: Starts (imports config.py)
    CPY->>UserConfig: Reads data (config_file.read_text())
    UserConfig-->>CPY: Returns user_data
    CPY->>DefaultConfig: Reads data (config_file_example.read_text())
    DefaultConfig-->>CPY: Returns default_data

    CPY->>CPY: Calls merge_defaults(user_data, default_data)
    activate CPY
    loop For each key, default_value in default_data
        alt key not in user_data
            Note over CPY: user_data[key] = default_value
            CPY->>LoggerSvc: logger.warning(f"Added missing config key: {key}")
        else key is in user_data AND user_data[key] is dict AND default_value is dict
            CPY->>CPY: merge_defaults(user_data[key], default_value) // Recursive call
        end
    end
    deactivate CPY

    Note over CPY: Module-level 'config' dictionary is now merged

    App->>CPY: Access Config.ALLOW_SYSADMINS_EVAL
    CPY-->>App: Returns value from merged 'config' dictionary
Loading

File-Level Changes

Change Details Files
Merge missing settings with defaults to prevent crashes at runtime
  • Load settings.yml.example alongside settings.yml
  • Define recursive merge_defaults to fill missing keys with defaults and warn
  • Invoke merge_defaults(config, config_example) before using config
tux/utils/config.py
Simplify ALLOW_SYSADMINS_EVAL retrieval to use merged config
  • Remove manual fallback logic and associated warning for ALLOW_SYSADMINS_EVAL
  • Assign ALLOW_SYSADMINS_EVAL directly from merged config
tux/utils/config.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help