Skip to content

Commit

Permalink
fix: stop making app.reports a property - when FLEXMEASURES_PLUGINS i…
Browse files Browse the repository at this point in the history
…s set, app.reports.update fails otherwise

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Aug 8, 2023
1 parent c392ccc commit a4e1593
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions flexmeasures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def create( # noqa C901
) # use copy to avoid mutating app.reporters
app.data_generators["scheduler"] = schedulers

# deprecation of app.reporters
# deprecated: app.reporters and app.schedulers
app.reporters = reporters
app.schedulers = schedulers

Expand All @@ -143,7 +143,7 @@ def get_reporters():
)
return app.data_generators["reporter"]

setattr(app, "reporters", property(get_reporters))
setattr(app, "reporters", get_reporters())

# add auth policy

Expand Down
15 changes: 8 additions & 7 deletions flexmeasures/utils/plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from flexmeasures.utils.coding_utils import get_classes_module


def register_plugins(app: Flask):
def register_plugins(app: Flask): # noqa: C901
"""
Register FlexMeasures plugins as Blueprints.
This is configured by the config setting FLEXMEASURES_PLUGINS.
Expand Down Expand Up @@ -113,13 +113,14 @@ def register_plugins(app: Flask):
plugin_reporters = get_classes_module(module.__name__, Reporter)
plugin_schedulers = get_classes_module(module.__name__, Scheduler)

# for legacy, we keep reporters and schedulers
app.reporters.update(plugin_reporters)
app.schedulers.update(plugin_schedulers)

# add DataGenerators
app.data_generators["scheduler"].update(plugin_schedulers)
app.data_generators["reporter"].update(plugin_reporters)
# for legacy, we still maintain app.reporters and app.schedulers
if plugin_reporters:
app.data_generators["reporter"].update(plugin_reporters)
app.reporters.update(plugin_reporters)
if plugin_schedulers:
app.data_generators["scheduler"].update(plugin_schedulers)
app.schedulers.update(plugin_schedulers)

app.config["LOADED_PLUGINS"][plugin_name] = plugin_version
app.logger.info(f"Loaded plugins: {app.config['LOADED_PLUGINS']}")
Expand Down

0 comments on commit a4e1593

Please sign in to comment.