def generateTable(klass, fwParams, app=None): """ Return a string containing one or more restructured text list tables containing parameter descriptions for the passed ArmiObject class. Parameters ---------- klass : ArmiObject subclass The Class for which parameter tables should be generated fwParams : ParameterDefinitionCollection A parameter definition collection containing the parameters that are always defined for the passed ``klass``. The rest of the parameters come from the plugins registered with the passed ``app`` app : App, optional The ARMI-based application to draw plugins from. """ from armi import apps if app is None: app = apps.App() defs = {None: fwParams} app = apps.App() for plugin in app.pluginManager.get_plugins(): plugParams = plugin.defineParameters() if plugParams is not None: pDefs = plugParams.get(klass, None) if pDefs is not None: defs[plugin] = pDefs header_content = """ .. list-table:: {} Parameters from {{}} :header-rows: 1 :widths: 30 40 30 * - Name - Description - Units """.format(klass.__name__) content = "" for plugin, pdefs in defs.items(): srcName = plugin.__name__ if plugin is not None else "Framework" pluginContent = header_content.format(srcName) for pd in pdefs: pluginContent += f""" * - {pd.name} - {pd.description} - {pd.units} """ content += pluginContent + "\n\n" return content
def main(): # Main entry point into ARMI try: armi.configure(apps.App()) code = ArmiCLI().run() # sys exit interprets None as 0 sys.exit(code) except Exception as ee: # pylint: disable=broad-except import traceback # TODO: change to critical after critical no longer throws an exception. print( "[CRIT {:03} ] Unhandled exception in __main__ on {}.".format( armi.MPI_RANK, armi.MPI_NODENAME), file=sys.__stderr__, ) print( "[CRIT {:03} ] Stack trace: {}".format(armi.MPI_RANK, traceback.format_exc()), file=sys.__stderr__, ) if armi.MPI_SIZE > 1: print( "[CRIT {:03} ] killing all MPI tasks from __main__.\n".format( armi.MPI_RANK), file=sys.__stderr__, ) # cleanTempDirs has @atexit.register so it should be called at the end, but mpi.Abort in main # will not allow for @atexit.register or except/finally code to be called so calling here as well armi.cleanTempDirs() # .Abort will not allow for @atexit.register or except/finally code to be called armi.MPI_COMM.Abort(errorcode=-1) raise SystemExit(1)
def configure(app: Optional[apps.App] = None, permissive=False): """ Set the plugin manager for the Framework and configure internals to those plugins. Parameters ---------- app : An :py:class:`armi.apps.App` instance with which the framework is to be configured. If it is not provided, then the default ARMI App will be used. permissive : Whether or not an error should be produced if ``configure`` is called more than once. This should only be set to ``True`` under testing or demonstration purposes, where the contents of otherwise independent scripts need to be run under the same python instance. Important --------- Since this affects the behavior of several modules at their import time, it is generally not safe to re-configure the ARMI framework once it has been configured. Therefore this will raise an ``OverConfiguredError`` if such a re-configuration is attempted, unless ``permissive`` is set to ``True``. Notes ----- We are planning on encapsulating much of the global ARMI state that gets configured with an App into the App object itself (with some other things going into the Case object). This will provide a number of benefits, the main one being that it will become trivial to re-configure the framework, which is currently not possible. """ global _app global _ARMI_CONFIGURE_CONTEXT if _ignoreConfigures: return app = app or apps.App() if _app is not None: if permissive and type(_app) is type(app): return else: raise exceptions.OverConfiguredError(_ARMI_CONFIGURE_CONTEXT) assert not context.BLUEPRINTS_IMPORTED, ( "ARMI can no longer be configured after blueprints have been imported. " "Blueprints were imported from:\n{}".format( context.BLUEPRINTS_IMPORT_CONTEXT)) _ARMI_CONFIGURE_CONTEXT = "".join(traceback.format_stack()) _app = app if _liveInterpreter(): cli.splash() pm = app.pluginManager context.APP_NAME = app.name parameters.collectPluginParameters(pm) parameters.applyAllParameters() flags.registerPluginFlags(pm)
def pytest_sessionstart(session): import armi from armi import apps print("Initializing generic ARMI Framework application") armi.configure(apps.App()) cs = caseSettings.Settings() settings.setMasterCs(cs)
def configure(app: Optional[apps.App] = None): """ Set the plugin manager for the Framework and configure internals to those plugins. Parameters ---------- app : An :py:class:`armi.apps.App` instance with which the framework is to be configured. If it is not provided, then the default ARMI App will be used. Important --------- Since this affects the behavior of several modules at their import time, it is generally not safe to re-configure the ARMI framework once it has been configured. Therefore this will raise an ``AssertionError`` if such a re-configuration is attempted. Notes ----- We are planning on encapsulating much of the global ARMI state that gets configured with an App into the App object itself (with some other things going into the Case object). This will provide a number of benefits, the main one being that it will become trivial to re-configure the framework, which is currently not possible. """ global _app global _ARMI_CONFIGURE_CONTEXT if _ignoreConfigures: return if _app is not None: # ARMI cannot be reconfigured! raise exceptions.OverConfiguredError(_ARMI_CONFIGURE_CONTEXT) assert not armi.context.BLUEPRINTS_IMPORTED, ( "ARMI can no longer be configured after blueprints have been imported. " "Blueprints were imported from:\n{}".format( armi.context.BLUEPRINTS_IMPORT_CONTEXT ) ) _ARMI_CONFIGURE_CONTEXT = "".join(traceback.format_stack()) app = app or apps.App() _app = app pm = app.pluginManager armi.context.APP_NAME = app.name parameters.collectPluginParameters(pm) parameters.applyAllParameters() flags.registerPluginFlags(pm) if MPI_RANK == 0: runLog.raw(app.splashText)
def pytest_sessionstart(session): import armi from armi import apps from armi.nucDirectory import nuclideBases print("Initializing generic ARMI Framework application") armi.configure(apps.App()) cs = caseSettings.Settings() settings.setMasterCs(cs) # Need to init burnChain. # see armi.cases.case.Case._initBurnChain with open(cs["burnChainFileName"]) as burnChainStream: nuclideBases.imposeBurnChain(burnChainStream)
# serve to show the default. import pathlib import re import warnings import sphinx_rtd_theme import armi from armi.context import RES from armi import apps from armi.bookkeeping import tests as bookkeepingTests from armi.utils.dochelpers import * # Configure the baseline framework "App" for framework doc building armi.configure(apps.App()) # some examples have import armi;armi.configure() in them that are intended # to be copy/pasted by new users. However, armi will crash with param locks if it is # configured twice. We often use if armi.isConfigured() to guard against # issues here, but prefer not to highlight that somewhat confusing # conditional if a user is just copy pasting fresh code # ("How on Earth," they might wonder "would it already be configured!?"). Thus, # we tell armi to simply disable future configure calls with this advanced flag armi._ignoreConfigures = True APIDOC_REL = ".apidocs" SOURCE_DIR = os.path.join("..", "armi") APIDOC_DIR = APIDOC_REL _TUTORIAL_FILES = [ pathlib.Path(SOURCE_DIR) / "tests" / "tutorials" / fName
def generateParamTable(klass, fwParams, app=None): """ Return a string containing one or more restructured text list tables containing parameter descriptions for the passed ArmiObject class. Parameters ---------- klass : ArmiObject subclass The Class for which parameter tables should be generated fwParams : ParameterDefinitionCollection A parameter definition collection containing the parameters that are always defined for the passed ``klass``. The rest of the parameters come from the plugins registered with the passed ``app`` app : App, optional The ARMI-based application to draw plugins from. Notes ----- It would be nice to have better section labels between the different sources but this cannot be done withing an ``exec`` directive in Sphinx so we settle for just putting in anchors for hyperlinking to. """ from armi import apps if app is None: app = apps.App() defs = {None: fwParams} app = apps.App() for plugin in app.pluginManager.get_plugins(): plugParams = plugin.defineParameters() if plugParams is not None: pDefs = plugParams.get(klass, None) if pDefs is not None: defs[plugin] = pDefs headerContent = """ .. list-table:: {} Parameters from {{}} :header-rows: 1 :widths: 30 40 30 * - Name - Description - Units """.format(klass.__name__) content = [] for plugin, pdefs in defs.items(): srcName = plugin.__name__ if plugin is not None else "Framework" content.append(f".. _{srcName}-{klass.__name__}-param-table:") pluginContent = headerContent.format(srcName) for pd in pdefs: pluginContent += f""" * - {pd.name} - {pd.description} - {pd.units} """ content.append(pluginContent + "\n") return "\n".join(content)
def pytest_sessionstart(session): print("Initializing generic ARMI Framework application") configure(apps.App()) bootstrapArmiTestEnv()
sys.path.insert(0, PYTHONPATH) # Also add to os.environ which will be used by the nbsphinx extension environment os.environ["PYTHONPATH"] = PYTHONPATH from armi import apps from armi import configure as armi_configure from armi import context from armi import disableFutureConfigures from armi import meta from armi.bookkeeping import tests as bookkeepingTests from armi.utils.dochelpers import * context.Mode.setMode(context.Mode.BATCH) # Configure the baseline framework "App" for framework doc building armi_configure(apps.App()) disableFutureConfigures() APIDOC_REL = ".apidocs" SOURCE_DIR = os.path.join("..", "armi") _TUTORIAL_FILES = [ pathlib.Path(SOURCE_DIR) / "tests" / "tutorials" / fName for fName in bookkeepingTests.TUTORIAL_FILES if "ipynb" not in fName ] class PatchedPythonDomain(PythonDomain): def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): if "refspecific" in node: del node["refspecific"]