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

Improve error handling when importing fuel handlers #69

Merged
merged 1 commit into from
May 6, 2020
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
11 changes: 11 additions & 0 deletions armi/physics/fuelCycle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ def defineSettingsValidators(inspector):
Implementation of settings inspections for fuel cycle settings.
"""
queries = []

queries.append(settingsValidation.Query(
lambda: bool(inspector.cs["shuffleLogic"]) ^
bool(inspector.cs["fuelHandlerName"]),
"A value was provided for `fuelHandlerName` or `shuffleLogic`, but not "
"the other. Either both `fuelHandlerName` and `shuffleLogic` should be "
"defined, or neither of them.",
"",
inspector.NO_ACTION,
))

# Check for code fixes for input code on the fuel shuffling outside the version control of ARMI
# These are basically auto-migrations for untracked code using
# the ARMI API. (This may make sense at a higher level)
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/fuelCycle/fuelHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def fuelHandlerFactory(operator):

# User did request a custom fuel handler. We must go find and import it
# from the input directory.
with directoryChangers.DirectoryChanger(cs.inputDirectory):
with directoryChangers.DirectoryChanger(cs.inputDirectory, dumpOnException=False):
try:
module = pathTools.importCustomPyModule(fuelHandlerModulePath)

Expand Down
27 changes: 15 additions & 12 deletions armi/utils/pathTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ def getModAndClassFromPath(path):
def separateModuleAndAttribute(pathAttr):
"""
Return True of the specified python module, and attribute of the module exist.


Parameters
----------
pathAttr : str
Path to a python module followed by the desired attribute.
e.g.: `/path/to/my/thing.py:MyClass`

Notes
-----
The attribute of the module could be a class, function, variable, etc.

Raises
------
ValueError:
Expand All @@ -190,17 +190,20 @@ def separateModuleAndAttribute(pathAttr):
def importCustomPyModule(modulePath):
"""
Dynamically import a custom module.

Parameters
----------
modulePath : str
Path to a python module.

Returns
-------
userSpecifiedModule : module
The imported python module.
"""
modulePath = pathlib.Path(modulePath)
if not modulePath.exists() or not modulePath.is_file():
raise IOError(r"Cannot import module from the given path: `{modulePath}`")
_dir, moduleName = os.path.split(modulePath)
moduleName = os.path.splitext(moduleName)[0] # take off the extension
spec = importlib.util.spec_from_file_location(moduleName, modulePath)
Expand All @@ -212,19 +215,19 @@ def importCustomPyModule(modulePath):
def moduleAndAttributeExist(pathAttr):
"""
Return True if the specified python module, and attribute of the module exist.


Parameters
----------
pathAttr : str
Path to a python module followed by the desired attribute.
e.g.: `/path/to/my/thing.py:MyClass`
Returns

Returns
-------
bool
bool
True if the specified python module, and attribute of the module exist.

Notes
-----
The attribute of the module could be a class, function, variable, etc.
Expand Down