Skip to content

Conversation

@FBumann
Copy link
Member

@FBumann FBumann commented Nov 25, 2025

Description

Re-add mistakenly removed method for loading a config from file

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring

Related Issues

Closes #(issue number)

Testing

  • I have tested my changes
  • Existing tests still pass

Checklist

  • My code follows the project style
  • I have updated documentation if needed
  • I have added tests for new functionality (if applicable)

Summary by CodeRabbit

  • New Features
    • Configuration can now be loaded from YAML files.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR re-adds the CONFIG.load_from_file() method, which reads YAML configuration files, validates existence, and applies parsed configuration to the CONFIG class. An internal helper method _apply_config_dict() updates nested configuration attributes and top-level configuration settings, with proper error handling for missing files.

Changes

Cohort / File(s) Summary
Changelog documentation
CHANGELOG.md
Added release notes for version 4.1.3 documenting the re-addition of CONFIG.load_from_file() method
Configuration loading feature
flixopt/config.py
Added public classmethod load_from_file(config_file) to load and parse YAML config files, and internal classmethod _apply_config_dict(config_dict) to apply parsed config to CONFIG class attributes with nested configuration support

Sequence Diagram

sequenceDiagram
    participant Caller
    participant CONFIG
    participant IO Module
    participant YAML Parser

    Caller->>CONFIG: load_from_file(config_file)
    CONFIG->>IO Module: read file
    IO Module-->>CONFIG: file content or FileNotFoundError
    CONFIG->>YAML Parser: parse YAML
    YAML Parser-->>CONFIG: config_dict
    CONFIG->>CONFIG: _apply_config_dict(config_dict)
    CONFIG->>CONFIG: update Modeling, Solving, Plotting, etc.
    CONFIG-->>Caller: CONFIG class (for chaining)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Review focus areas:
    • Validation logic for file existence and YAML parsing correctness
    • Nested attribute update mechanism in _apply_config_dict() to ensure all configuration categories (Modeling, Solving, Plotting) are properly handled
    • Error handling for missing files and malformed YAML

Possibly related PRs

  • flixOpt/flixopt#385: Directly related as it modifies the same CONFIG API by introducing load_from_file() and _apply_config_dict() methods with identical functionality

Poem

🐰 A config file lost, now returns with care,
Load from YAML, apply with flair,
Nested settings bloom, validation's there,
Chaining methods dance through the air! 📋✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/load-config-from-file

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b10dfe8 and a1929ac.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • flixopt/config.py (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@FBumann FBumann merged commit 4fb6ea9 into main Nov 25, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants