Skip to content

Commit

Permalink
Merge 960aa5f into a8e7328
Browse files Browse the repository at this point in the history
  • Loading branch information
youngmit authored Apr 6, 2020
2 parents a8e7328 + 960aa5f commit 374d69e
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 122 deletions.
25 changes: 18 additions & 7 deletions armi/cases/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def run(self):

def initializeOperator(self, r=None):
"""Creates and returns an Operator."""
with DirectoryChanger(self.cs.inputDirectory):
with DirectoryChanger(self.cs.inputDirectory, dumpOnException=False):
self._initBurnChain()
o = operators.factory(self.cs)
if not r:
Expand Down Expand Up @@ -465,7 +465,7 @@ def summarizeDesign(self, generateFullCoreMap=True, showBlockAxialMesh=True):
"""Uses the ReportInterface to create a fancy HTML page describing the design inputs."""
settings.setMasterCs(self.cs)
o = self.initializeOperator()
with DirectoryChanger(self.cs.inputDirectory):
with DirectoryChanger(self.cs.inputDirectory, dumpOnException=False):
# There are global variables that are modified when a report is
# generated, so reset it all
six.moves.reload_module(report) # pylint: disable=too-many-function-args
Expand Down Expand Up @@ -566,9 +566,18 @@ def clone(self, additionalFiles=None, title=None, modifiedSettings=None):
copyInterfaceInputs(self.cs, clone.cs.inputDirectory)

with open(self.cs["loadingFile"], "r") as f:
for includePath, mark in textProcessors.findYamlInclusions(
f, root=pathlib.Path(self.cs.inputDirectory)
):
# The root for handling YMAL includes is relative to the YAML file, not the
# settings file
root = (
pathlib.Path(self.cs.inputDirectory)
/ pathlib.Path(self.cs["loadingFile"]).parent
)
cloneRoot = (
pathlib.Path(clone.cs.inputDirectory)
/ pathlib.Path(clone.cs["loadingFile"]).parent
)
for includePath, mark in textProcessors.findYamlInclusions(f, root=root):
includePath = root / includePath
if not includePath.exists():
raise OSError(
"The input file file `{}` referenced at {} does not exist.".format(
Expand All @@ -580,7 +589,7 @@ def clone(self, additionalFiles=None, title=None, modifiedSettings=None):
includePath, mark
),
fromPath(includePath),
clone.cs.inputDirectory,
cloneRoot,
)

for fileName in additionalFiles or []:
Expand Down Expand Up @@ -652,7 +661,9 @@ def writeInputs(self, sourceDir: Optional[str] = None):
Similar to this but doesn't let you write out new/modified
geometry or blueprints objects
"""
with ForcedCreationDirectoryChanger(self.cs.inputDirectory):
with ForcedCreationDirectoryChanger(
self.cs.inputDirectory, dumpOnException=False
):
# trick: these seemingly no-ops load the bp and geom via properties if
# they are not yet initialized.
self.bp
Expand Down
4 changes: 3 additions & 1 deletion armi/cases/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def clone(self, oldRoot=None):
newDir = os.path.dirname(os.path.relpath(case.cs.path, oldRoot))
else:
newDir = case.title
with ForcedCreationDirectoryChanger(newDir, clean=True):
with ForcedCreationDirectoryChanger(
newDir, clean=True, dumpOnException=False
):
clone.add(case.clone(modifiedSettings=modifiedSettings))
return clone

Expand Down
4 changes: 3 additions & 1 deletion armi/operators/settingsValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ def _csRelativePath(self, filename):

def _setGeomType(self):
if self.cs["geomFile"]:
with directoryChangers.DirectoryChanger(self.cs.inputDirectory):
with directoryChangers.DirectoryChanger(
self.cs.inputDirectory, dumpOnException=False
):
geom = geometry.SystemLayoutInput()
geom.readGeomFromFile(self.cs["geomFile"])

Expand Down
9 changes: 3 additions & 6 deletions armi/reactor/blueprints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import traceback
import typing

import ruamel
import tabulate
import yamlize
import yamlize.objects
Expand Down Expand Up @@ -108,12 +107,10 @@ def loadFromCs(cs):
# pylint: disable=import-outside-toplevel; circular import protection
from armi.utils import directoryChangers

textProcessors.registerYamlIncludeConstructor()

with directoryChangers.DirectoryChanger(cs.inputDirectory):
with directoryChangers.DirectoryChanger(cs.inputDirectory, dumpOnException=False):
with open(cs["loadingFile"], "r") as bpYaml:
# Make sure that the !include constructor is registered
bpYaml = textProcessors.resolveMarkupInclusions(bpYaml)
root = pathlib.Path(cs["loadingFile"]).parent.absolute()
bpYaml = textProcessors.resolveMarkupInclusions(bpYaml, root)
try:
bp = Blueprints.load(bpYaml)
except yamlize.yamlizing_error.YamlizingError as err:
Expand Down
8 changes: 8 additions & 0 deletions armi/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import shutil
from typing import Union

from ruamel import yaml

import armi
from armi import runLog
from armi.localization import exceptions
Expand Down Expand Up @@ -120,6 +122,12 @@ def recursivelyLoadSettingsFiles(
runLog.extra("loaded {}".format(possibleSettingsFile))
except exceptions.InvalidSettingsFileError as ee:
runLog.info("skipping {}\n {}".format(possibleSettingsFile, ee))
except yaml.composer.ComposerError as ee:
runLog.info(
"skipping {}; it appears to be an incomplete YAML snippet\n {}".format(
possibleSettingsFile, ee
)
)
except Exception as ee:
runLog.error(
"Failed to parse {}.\nIt looked like a settings file but gave this exception:\n{}: {}".format(
Expand Down
5 changes: 4 additions & 1 deletion armi/settings/settingsIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def readFromFile(self, path, handleInvalids=True):
self.format = self.FORMAT_FROM_EXT[ext]
self.inputPath = path
with open(path, "r") as f:
self.readFromStream(f, handleInvalids, self.format)
try:
self.readFromStream(f, handleInvalids, self.format)
except Exception as ee:
raise exceptions.InvalidSettingsFileError(path, str(ee))

def readFromStream(self, stream, handleInvalids=True, fmt=SettingsInputFormat.YAML):
"""Read from a file-like stream."""
Expand Down
3 changes: 2 additions & 1 deletion armi/tests/refSmallReactor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,5 @@ grids:
lattice pitch:
x: 50.0
y: 50.0
grid contents: !include sfpGeom.yaml
grid contents:
!include sfpGeom.yaml
3 changes: 2 additions & 1 deletion armi/tests/tutorials/anl-afci-177-blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ systems:
y: 0.0
z: 0.0
grids:
core: !include anl-afci-177-coreMap.yaml
core:
!include anl-afci-177-coreMap.yaml

# end-systems-section

2 changes: 1 addition & 1 deletion armi/utils/tests/resources/includeA.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# some comment in includeA
full_name: Jennifer Person
# some comment in includeA
children:
!include includeB.yaml
1 change: 1 addition & 0 deletions armi/utils/tests/resources/root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bobby: &bobby

billy:
full_name: William Person
# comment
children:
- *bobby
- !include includeA.yaml
8 changes: 5 additions & 3 deletions armi/utils/tests/test_textProcessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


class YamlIncludeTest(unittest.TestCase):
def testIncludeCtor(self):
def testResolveIncludes(self):
with open(os.path.join(RES_DIR, "root.yaml")) as f:
resolved = textProcessors.resolveMarkupInclusions(
f, root=pathlib.Path(RES_DIR)
Expand Down Expand Up @@ -66,9 +66,11 @@ def testIncludeCtor(self):
self.assertTrue(anchorFound)

def testFindIncludes(self):
includes = textProcessors.findYamlInclusions(pathlib.Path(RES_DIR) / "root.yaml")
includes = textProcessors.findYamlInclusions(
pathlib.Path(RES_DIR) / "root.yaml"
)
for i, _mark in includes:
self.assertTrue(i.exists())
self.assertTrue((RES_DIR/i).exists())

self.assertEqual(len(includes), 2)

Expand Down
Loading

0 comments on commit 374d69e

Please sign in to comment.