Skip to content

Commit

Permalink
UserPlugins can't define Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Nov 17, 2022
1 parent 36fe1bc commit d3f8a2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion armi/plugins.py
Expand Up @@ -639,6 +639,9 @@ def __enforceLimitations(self):
corral their side effects during a run.
"""
if issubclass(self.__class__, UserPlugin):
assert (
len(self.__class__.defineParameters()) == 0
), "UserPlugins cannot define parameters, consider using an ArmiPlugin."
assert (
len(self.__class__.defineParameterRenames()) == 0
), "UserPlugins cannot define parameter renames, consider using an ArmiPlugin."
Expand All @@ -651,6 +654,23 @@ def __enforceLimitations(self):
self.defineSettings = lambda: []
self.defineSettingsValidators = lambda: []

@staticmethod
@HOOKSPEC
def defineParameters():
"""
Prevents defining additional parameters.
.. warning:: This is not overridable.
Notes
-----
It is a designed limitation of user plugins that they not define parameters.
Parameters are defined when the App() is read in, which is LONG before the settings
file has been read. So the parameters are defined before we discover the user plugin.
If this is a feature you need, just use an ArmiPlugin.
"""
return {}

@staticmethod
@HOOKSPEC
def defineParameterRenames():
Expand All @@ -662,7 +682,9 @@ def defineParameterRenames():
Notes
-----
It is a designed limitation of user plugins that they not generate parameter renames,
so that they are able to be added to the plugin stack during run time.
Parameters are defined when the App() is read in, which is LONG before the settings
file has been read. So the parameters are defined before we discover the user plugin.
If this is a feature you need, just use a normal Plugin.
"""
return {}

Expand Down
1 change: 1 addition & 0 deletions doc/tutorials/making_your_first_app.rst
Expand Up @@ -410,6 +410,7 @@ In most ways, ``UserPluginExample`` above is just a normal
:py:class:`UserPlugin <armi.plugins.UserPlugin>` class is more limited than a
regular plugin though, you cannot implement:

* :py:meth:`armi.plugins.ArmiPlugin.defineParameters`
* :py:meth:`armi.plugins.ArmiPlugin.defineParameterRenames`
* :py:meth:`armi.plugins.ArmiPlugin.defineSettings`
* :py:meth:`armi.plugins.ArmiPlugin.defineSettingsValidators`
Expand Down

0 comments on commit d3f8a2c

Please sign in to comment.