Skip to content

Commit 493ca97

Browse files
authored
Feature/Improve Configuration options and handling (#385)
* Refactor configuration management: remove dataclass-based schema and simplify CONFIG structure. * Refactor configuration loading: switch from `os` to `pathlib`, streamline YAML loading logic. * Refactor logging setup: split handler creation into dedicated functions, simplify configuration logic. * Improve logging configurability and safety - Add support for `RotatingFileHandler` to prevent large log files. - Introduce `console` flag for optional console logging. - Default to `NullHandler` when no handlers are configured for better library behavior. * Temp * Temp * Temp * Temp * Temp * Temp * Refactor configuration and logging: remove unused `merge_configs` function, streamline logging setup, and encapsulate `_setup_logging` as an internal function. * Remove unused `change_logging_level` import and export. * Add tests for config.py * Expand `config.py` test coverage: add tests for custom config loading, logging setup, dict roundtrip, and attribute modification. * Expand `test_config.py` coverage: add modeling config persistence test, refine logging reset, and improve partial config load assertions. * Expand `test_config.py` coverage: add teardown for state cleanup and reset modeling config in setup. * Add `CONFIG.reset()` method and expand test coverage to verify default restoration * Refactor `CONFIG` to centralize defaults in `_DEFAULTS` and ensure `reset()` aligns with them; add test to verify consistency. * Refactor `_DEFAULTS` to use `MappingProxyType` for immutability, restructure config hierarchy, and simplify `reset()` implementation for maintainability; update tests accordingly. * Mark `TestConfigModule` tests to run in a single worker with `@pytest.mark.xdist_group` to prevent global config interference. * Add default log file * Update CHANGELOG.md * Readd change_logging_level() for backwards compatability * Add more options to config.py * Add a docstring to config.y * Add a docstring to config.y * rename parameter message_format * Improve color config * Improve color config * Update CHANGELOG.md * Improve color handling * Improve color handling * Remove console Logging explicityl from examples * Make log to console the default * Make log to console the default * Add individual level parameters for console and file * Add extra Handler section * Use dedicated levels for both handlers * Switch back to not use Handlers * Revert "Switch back to not use Handlers" This reverts commit 05bbccb. * Revert "Use dedicated levels for both handlers" This reverts commit ed0542b. * Revert "Add extra Handler section" This reverts commit a133cc8. * Revert "Add individual level parameters for console and file" This reverts commit 19f81c9. * Fix CHANGELOG.md
1 parent 5e66d50 commit 493ca97

9 files changed

Lines changed: 995 additions & 223 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,23 @@ Please keep the format of the changelog consistent with the other releases, so t
4242
## [Unreleased] - ????-??-??
4343
4444
### ✨ Added
45+
- Added `CONFIG.reset()` method to restore configuration to default values
46+
- Added configurable log file rotation settings: `CONFIG.Logging.max_file_size` and `CONFIG.Logging.backup_count`
47+
- Added configurable log format settings: `CONFIG.Logging.date_format` and `CONFIG.Logging.format`
48+
- Added configurable console settings: `CONFIG.Logging.console_width` and `CONFIG.Logging.show_path`
49+
- Added `CONFIG.Logging.Colors` nested class for customizable log level colors using ANSI escape codes (works with both standard and Rich handlers)
4550
4651
### 💥 Breaking Changes
4752
4853
### ♻️ Changed
49-
- Using `h5netcdf` instead of `netCDF4` for dataset I/O operations. This follows the update in `xarray==2025.09.01`
54+
- Logging and Configuration management changed
5055
5156
### 🗑️ Deprecated
57+
- `change_logging_level()` function is now deprecated in favor of `CONFIG.Logging.level` and `CONFIG.apply()`. Will be removed in version 3.0.0.
5258
5359
### 🔥 Removed
60+
- Removed unused `config.merge_configs` function from configuration module
61+
5462
5563
### 🐛 Fixed
5664
@@ -61,6 +69,8 @@ Please keep the format of the changelog consistent with the other releases, so t
6169
### 📝 Docs
6270
6371
### 👷 Development
72+
- Greatly expanded test coverage for `config.py` module
73+
- Added `@pytest.mark.xdist_group` to `TestConfigModule` tests to prevent global config interference
6474
6575
### 🚧 Known Issues
6676
@@ -78,6 +88,7 @@ Until here -->
7888

7989
### 📦 Dependencies
8090
- Updated `renovate.config` to treat CalVer packages (xarray and dask) with more care
91+
- Updated packaging configuration
8192

8293
---
8394

flixopt/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,3 @@
3535
results,
3636
solvers,
3737
)
38-
39-
CONFIG.load_config()

flixopt/calculation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ def main_results(self) -> dict[str, Scalar | dict]:
9191
model.label_of_element: float(model.size.solution)
9292
for component in self.flow_system.components.values()
9393
for model in component.model.all_sub_models
94-
if isinstance(model, InvestmentModel) and float(model.size.solution) >= CONFIG.modeling.EPSILON
94+
if isinstance(model, InvestmentModel) and float(model.size.solution) >= CONFIG.Modeling.epsilon
9595
},
9696
'Not invested': {
9797
model.label_of_element: float(model.size.solution)
9898
for component in self.flow_system.components.values()
9999
for model in component.model.all_sub_models
100-
if isinstance(model, InvestmentModel) and float(model.size.solution) < CONFIG.modeling.EPSILON
100+
if isinstance(model, InvestmentModel) and float(model.size.solution) < CONFIG.Modeling.epsilon
101101
},
102102
},
103103
'Buses with excess': [

0 commit comments

Comments
 (0)