From d3f8a2c0442c0fd66153d3bf2f73cf14a628a249 Mon Sep 17 00:00:00 2001 From: jstilley Date: Thu, 17 Nov 2022 11:54:28 -0800 Subject: [PATCH] UserPlugins can't define Parameters --- armi/plugins.py | 24 +++++++++++++++++++++++- doc/tutorials/making_your_first_app.rst | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/armi/plugins.py b/armi/plugins.py index 97f913390..cccfe58b1 100644 --- a/armi/plugins.py +++ b/armi/plugins.py @@ -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." @@ -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(): @@ -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 {} diff --git a/doc/tutorials/making_your_first_app.rst b/doc/tutorials/making_your_first_app.rst index cc94066bc..bac09592a 100644 --- a/doc/tutorials/making_your_first_app.rst +++ b/doc/tutorials/making_your_first_app.rst @@ -410,6 +410,7 @@ In most ways, ``UserPluginExample`` above is just a normal :py:class:`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`