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

Add isConfigured() function #16

Merged
merged 3 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions armi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,20 @@ def cleanTempDirs(olderThanDays=None):
"""
Clean up temporary files after a run.

Parameters
----------
olderThanDays: int, optional
If provided, deletes other ARMI directories if they are older than the requested
time.

The Windows HPC system sends a SIGBREAK signal when the user cancels a job, which
is NOT handled by ``atexit``. Notably SIGBREAK doesn't exist off Windows.
For the SIGBREAK signal to work with a Microsoft HPC, the ``TaskCancelGracePeriod``
option must be configured to be non-zero. This sets the period between SIGBREAK
and SIGTERM/SIGINT. To do cleanups in this case, we must use the ``signal`` module.
Actually, even then it does not work because MS ``mpiexec`` does not pass signals
through. """
through.

Parameters
----------
olderThanDays: int, optional
If provided, deletes other ARMI directories if they are older than the requested
time.
"""
disconnectAllHdfDBs()

if os.path.exists(FAST_PATH):
Expand Down Expand Up @@ -288,6 +289,12 @@ def getDefaultPluginManager() -> pluggy.PluginManager:
return pm


def isConfigured():
"""
Returns whether ARMI has been configured with an App.
"""
return _app is not None

def getPluginManager() -> Optional[pluggy.PluginManager]:
"""
Return the plugin manager, if there is one.
Expand Down Expand Up @@ -331,6 +338,20 @@ def _cleanupOnCancel(signum, _frame):
def configure(app: apps.App):
"""
Set the plugin manager for the Framework and configure internals to those plugins.

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.
"""
assert not armi.context.BLUEPRINTS_IMPORTED, (
"ARMI can no longer be configured after blueprints have been imported. "
Expand Down
14 changes: 14 additions & 0 deletions armi/tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ def test_getParamRenames(self):
plugins.PluginError, ".*currently-defined parameters.*"
):
app.getParamRenames()


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

def test_getDefaultPlugMan(self):
from armi import cli
pm = armi.getDefaultPluginManager()
pm2 = armi.getDefaultPluginManager()

self.assertTrue(pm is not pm2)
self.assertIn(cli.EntryPointsPlugin, pm.get_plugins())