Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default check to register #271

Merged
merged 11 commits into from
Jun 15, 2020
33 changes: 33 additions & 0 deletions strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,39 @@ def register(self, plugin_class):
for p in plugin_class.provides:
self._plugin_class_registry[p] = plugin_class

already_seen = []
WenzDaniel marked this conversation as resolved.
Show resolved Hide resolved
for provides, plugin in self._plugin_class_registry.items():
WenzDaniel marked this conversation as resolved.
Show resolved Hide resolved

if plugin in already_seen:
continue
already_seen.append(plugin)

for option, items in plugin.takes_config.items():
try:
# Looping over the options of the new plugin and check if
# they can be found in the already registered plugins:
for new_option, new_items in plugin_class.takes_config.items():
if not new_option == option:
continue
default = items.get_default('1') # Have to pass will be changed.
new_default = new_items.get_default('1')
WenzDaniel marked this conversation as resolved.
Show resolved Hide resolved
if default == new_default:
continue
else:
mes = ''.join((f'Two plugins have a different default value',
WenzDaniel marked this conversation as resolved.
Show resolved Hide resolved
f' for the same option. The option',
f' "{new_option}" in "{plugin.__name__}" takes',
f' as a default "{default}" while in',
f' "{plugin_class.__name__}" the default value'
f' is set to "{new_default}". Please change'
' one of the defaults.'
))
raise ValueError(mes)

except strax.InvalidConfiguration:
WenzDaniel marked this conversation as resolved.
Show resolved Hide resolved
# These are option which are inherited from context options.
pass

return plugin_class

def search_field(self, pattern):
Expand Down