Пример #1
0
    def testIncludeCtor(self):
        with open(os.path.join(RES_DIR, "root.yaml")) as f:
            resolved = textProcessors.resolveMarkupInclusions(
                f, root=pathlib.Path(RES_DIR))

        # Make sure that there aren't any !include tags left in the converted stream
        anyIncludes = False
        for l in resolved:
            if "!include" in l:
                anyIncludes = True
        self.assertFalse(anyIncludes)

        # Re-parse the resolved stream, make sure that we included the stuff that we
        # want
        resolved.seek(0)
        data = ruamel.yaml.YAML().load(resolved)
        self.assertEqual(data["billy"]["children"][1]["full_name"],
                         "Jennifer Person")
        self.assertEqual(
            data["billy"]["children"][1]["children"][0]["full_name"],
            "Elizabeth Person")

        # Check that we preserved other round-trip data
        resolved.seek(0)
        commentFound = False
        anchorFound = False
        for l in resolved:
            if l.strip() == "# some comment in includeA":
                commentFound = True
            if "*bobby" in l:
                anchorFound = True

        self.assertTrue(commentFound)
        self.assertTrue(anchorFound)
Пример #2
0
    def invoke(self):
        p = pathlib.Path(self.args.blueprints)
        if not p.exists():
            runLog.error("Blueprints file `{}` does not exist".format(str(p)))
            return 1
        stream = resolveMarkupInclusions(p)
        sys.stdout.write(stream.read())

        return None
Пример #3
0
    def setUpClass(cls):
        cls.cs = settings.Settings()
        cls.directoryChanger = directoryChangers.DirectoryChanger(TEST_ROOT)
        cls.directoryChanger.open()

        y = textProcessors.resolveMarkupInclusions(
            pathlib.Path(os.getcwd()) / "refSmallReactor.yaml")
        cls.blueprints = blueprints.Blueprints.load(y)
        cls.blueprints._prepConstruction(cls.cs)
Пример #4
0
    def setUpClass(cls):
        cls.cs = settings.Settings()
        cls.directoryChanger = directoryChangers.DirectoryChanger(TEST_ROOT)
        cls.directoryChanger.open()
        isotopicDepletion.applyDefaultBurnChain()

        with open("refSmallReactor.yaml", "r") as y:
            y = textProcessors.resolveMarkupInclusions(y)
            cls.blueprints = blueprints.Blueprints.load(y)
            cls.blueprints._prepConstruction(cls.cs)
Пример #5
0
    def _setup_blueprints(self):
        # need this for the getAllNuclides call
        with directoryChangers.DirectoryChanger(TEST_ROOT):
            self.cs["loadingFile"] = "refSmallReactor.yaml"
            with open(self.cs["loadingFile"], "r") as y:
                y = textProcessors.resolveMarkupInclusions(
                    y, pathlib.Path(self.cs.inputDirectory))
                self.r.blueprints = blueprints.Blueprints.load(y)

            self.r.blueprints._prepConstruction(self.cs)
Пример #6
0
    def invoke(self):
        from armi.bookkeeping.db.database3 import Database3

        if all(
            li is None
            for li in [self.args.blueprints, self.args.geom, self.args.settings]
        ):
            runLog.error(
                "No settings, blueprints, or geometry files specified; "
                "nothing to do."
            )
            return -1

        bp = None
        settings = None
        geom = None

        if self.args.blueprints is not None:
            bp = resolveMarkupInclusions(pathlib.Path(self.args.blueprints)).read()

        if self.args.geom is not None:
            with open(self.args.geom, "r") as f:
                geom = f.read()

        if self.args.settings is not None:
            settings = resolveMarkupInclusions(pathlib.Path(self.args.settings)).read()

        db = Database3(self.args.h5db, "a")

        with db:
            # Not calling writeInputsToDb, since it makes too many assumptions about
            # where the inputs are coming from, and which ones we want to write.
            # Instead, we assume that we know where to store them, and do it ourselves.
            for data, key in [
                (bp, "blueprints"),
                (geom, "geomFile"),
                (settings, "settings"),
            ]:
                if data is not None:
                    dSetName = "inputs/" + key
                    if dSetName in db.h5db:
                        del db.h5db[dSetName]
                    db.h5db[dSetName] = data
Пример #7
0
def loadFromCs(cs):
    """
    Function to load Blueprints based on supplied ``CaseSettings``.
    """
    # pylint: disable=import-outside-toplevel; circular import protection
    from armi.utils import directoryChangers

    with directoryChangers.DirectoryChanger(cs.inputDirectory,
                                            dumpOnException=False):
        with open(cs["loadingFile"], "r") as 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:
                if "cross sections" in err.args[0]:
                    runLog.error(
                        "The loading file {} contains invalid `cross sections` input. "
                        "Please run the `modify` entry point on this case to automatically convert."
                        "".format(cs["loadingFile"]))
                raise
    return bp
Пример #8
0
def loadFromCs(cs):
    """
    Function to load Blueprints based on supplied ``CaseSettings``.
    """
    # pylint: disable=import-outside-toplevel; circular import protection
    from armi.utils import directoryChangers

    textProcessors.registerYamlIncludeConstructor()

    with directoryChangers.DirectoryChanger(cs.inputDirectory):
        with open(cs["loadingFile"], "r") as bpYaml:
            # Make sure that the !include constructor is registered
            bpYaml = textProcessors.resolveMarkupInclusions(bpYaml)
            try:
                bp = Blueprints.load(bpYaml)
            except yamlize.yamlizing_error.YamlizingError as err:
                if "cross sections" in err.args[0]:
                    runLog.error(
                        "The loading file {} contains invalid `cross sections` input. "
                        "Please run the `modify` entry point on this case to automatically convert."
                        "".format(cs["loadingFile"]))
                raise
    return bp