Skip to content

Commit

Permalink
Merge e64d115 into 907f2b4
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Apr 13, 2022
2 parents 907f2b4 + e64d115 commit 4b8a173
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 41 deletions.
2 changes: 1 addition & 1 deletion armi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ def configure(app: Optional[apps.App] = None, permissive=False):
_ARMI_CONFIGURE_CONTEXT = "".join(traceback.format_stack())

_app = app
context.APP_NAME = app.name

if _liveInterpreter():
runLog.LOG.startLog(name=f"interactive-{app.name}")
cli.splash()

pm = app.pluginManager
context.APP_NAME = app.name
parameters.collectPluginParameters(pm)
parameters.applyAllParameters()
flags.registerPluginFlags(pm)
Expand Down
58 changes: 41 additions & 17 deletions armi/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from typing import Dict, Optional, Tuple, List
import collections

from armi import plugins, pluginManager, meta, settings
from armi import context, plugins, pluginManager, meta, settings
from armi.reactor import parameters
from armi.settings import Setting
from armi.settings import fwSettings
Expand Down Expand Up @@ -96,10 +96,16 @@ def __init__(self):
self._paramRenames: Optional[Tuple[Dict[str, str], int]] = None

@property
def pluginManager(self) -> pluginManager.ArmiPluginManager:
"""
Return the App's PluginManager.
def version(self) -> str:
"""Grab the version of this app (defaults to ARMI version).
NOTE: This is designed to be over-ridable by Application developers.
"""
return meta.__version__

@property
def pluginManager(self) -> pluginManager.ArmiPluginManager:
"""Return the App's PluginManager."""
return self._pm

def getSettings(self) -> Dict[str, Setting]:
Expand Down Expand Up @@ -221,19 +227,37 @@ def splashText(self):
Return a textual splash screen.
Specific applications will want to customize this, but by default the ARMI one
is produced.
is produced, with extra data on the App name and version, if available.
"""
# Don't move the triple quotes from the beginning of the line
return r"""
---------------------------------------------------
| _ ____ __ __ ___ |
| / \ | _ \ | \/ | |_ _| |
| / _ \ | |_) | | |\/| | | | |
| / ___ \ | _ < | | | | | | |
| /_/ \_\ |_| \_\ |_| |_| |___| |
| Advanced Reactor Modeling Interface |
---------------------------------------------------
Version {0:10s}
""".format(
# typical ARMI splash text
splash = r"""
+===================================================+
| _ ____ __ __ ___ |
| / \ | _ \ | \/ | |_ _| |
| / _ \ | |_) | | |\/| | | | |
| / ___ \ | _ < | | | | | | |
| /_/ \_\ |_| \_\ |_| |_| |___| |
| Advanced Reactor Modeling Interface |
| |
| version {0:10s} |
| |""".format(
meta.__version__
)

# add the name/version of the current App, if it's not the default
if context.APP_NAME != "armi":
# pylint: disable=import-outside-toplevel # avoid cyclic import
from armi import getApp

splash += r"""
|---------------------------------------------------|
| {0:>17s} app version {1:10s} |""".format(
context.APP_NAME, getApp().version
)

# bottom border of the splash
splash += r"""
+===================================================+
"""

return splash
8 changes: 3 additions & 5 deletions armi/cases/inputModifiers/tests/test_inputModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def setUpClass(cls):
bp._prepConstruction(cs)
cls.baseCase = cases.Case(cs=cs, bp=bp, geom=geom)

def test_SmearDensityFail(self):
def test_smearDensityFail(self):
builder = suiteBuilder.FullFactorialSuiteBuilder(self.baseCase)

builder.addDegreeOfFreedom(
Expand All @@ -137,7 +137,7 @@ def test_SmearDensityFail(self):
with self.assertRaisesRegex(RuntimeError, "before .*SmearDensityModifier"):
builder.buildSuite()

def test_example(self):
def test_settingsModifier(self):
builder = suiteBuilder.SeparateEffectsSuiteBuilder(self.baseCase)
builder.addDegreeOfFreedom(
inputModifiers.SettingsModifier("fpModel", v)
Expand All @@ -164,11 +164,9 @@ def test_example(self):

self.assertTrue(os.path.exists("case-suite"))

def test_BluePrintBlockModifier(self):
def test_bluePrintBlockModifier(self):
"""test BluePrintBlockModifier with build suite naming function argument"""

case_nbr = 1

builder = suiteBuilder.FullFactorialSuiteBuilder(self.baseCase)

builder.addDegreeOfFreedom(
Expand Down
19 changes: 14 additions & 5 deletions armi/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self):
group = parser.add_mutually_exclusive_group()

group.add_argument(
"-v", "--version", action="version", version="%(prog)s " + armi.__version__
"-v", "--version", action="store_true", help="display the version"
)

group.add_argument(
Expand All @@ -143,6 +143,15 @@ def __init__(self):

self.parser = parser

def showVersion(self):
"""Print the App name and version on the command line"""
prog = armi.context.APP_NAME
app = armi.getApp()
if app is None or prog == "armi":
print("{0} {1}".format(prog, armi.__version__))
else:
print("{0} {1}".format(prog, app.version))

def listCommands(self):
"""List commands with a short description."""
splash()
Expand Down Expand Up @@ -176,12 +185,12 @@ def run(self) -> Optional[int]:

if args.list_commands:
self.listCommands()

return 0

if args.command == "help":
elif args.version:
self.showVersion()
return 0
elif args.command == "help":
self.parser.print_help()

return 0

return self.executeCommand(args.command, args.args)
Expand Down
18 changes: 18 additions & 0 deletions armi/cli/tests/test_runSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,26 @@ def test_listCommand(self):
cli.listCommands()
finally:
sys.stdout = origout

self.assertIn("run-suite", out.getvalue())

def test_showVersion(self):
"""Test the ArmiCLI.showVersion method"""
from armi import cli, meta

cli = cli.ArmiCLI()

origout = sys.stdout
try:
out = io.StringIO()
sys.stdout = out
cli.showVersion()
finally:
sys.stdout = origout

self.assertIn("armi", out.getvalue())
self.assertIn(meta.__version__, out.getvalue())


if __name__ == "__main__":
unittest.main()
40 changes: 27 additions & 13 deletions armi/tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Tests for the App class.
"""
"""Tests for the App class."""

import copy
import unittest
Expand All @@ -34,9 +32,7 @@ def defineParameterRenames():


class TestPlugin2(plugins.ArmiPlugin):
"""
This should lead to an error if it coexists with Plugin1.
"""
"""This should lead to an error if it coexists with Plugin1."""

@staticmethod
@plugins.HOOKIMPL
Expand All @@ -55,7 +51,8 @@ def defineParameterRenames():

class TestPlugin4(plugins.ArmiPlugin):
"""This should be fine on its own, and safe to merge with TestPlugin1. And would
make for a pretty good rename IRL."""
make for a pretty good rename IRL.
"""

@staticmethod
@plugins.HOOKIMPL
Expand All @@ -64,9 +61,7 @@ def defineParameterRenames():


class TestApps(unittest.TestCase):
"""
Test the base apps.App interfaces.
"""
"""Test the base apps.App interfaces."""

def setUp(self):
"""Manipulate the standard App. We can't just configure our own, since the
Expand Down Expand Up @@ -105,11 +100,30 @@ def test_getParamRenames(self):
):
app.getParamRenames()

def test_version(self):
app = armi.getApp()
ver = app.version
self.assertEqual(ver, armi.meta.__version__)

def test_getSettings(self):
app = armi.getApp()
settings = app.getSettings()

self.assertGreater(len(settings), 100)
self.assertEqual(settings["numProcessors"].value, 1)
self.assertEqual(settings["nCycles"].value, 1)

def test_splashText(self):
app = armi.getApp()
splash = app.splashText
self.assertIn("========", splash)
self.assertIn("Advanced", splash)
self.assertIn("version", splash)
self.assertIn(armi.meta.__version__, splash)


class TestArmi(unittest.TestCase):
"""
Tests for functions in the ARMI __init__ module.
"""
"""Tests for functions in the ARMI __init__ module."""

def test_getDefaultPlugMan(self):
from armi import cli
Expand Down

0 comments on commit 4b8a173

Please sign in to comment.