How to use the pyhocon.ConfigTree.merge_configs function in pyhocon

To help you get started, we’ve selected a few pyhocon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chimpler / pyhocon / tests / test_config_parser.py View on Github external
config1 = ConfigFactory.parse_string(
            """
            x : { v1: 1 }
            b1 : {v2: 2 }
            b = [${b1}]
            """,
            resolve=False
        )
        config2 = ConfigFactory.parse_string(
            """
            b2 : ${x} {v2: 3}
            b += [${b2}]
            """,
            resolve=False
        )
        merged = ConfigTree.merge_configs(config1, config2)
        ConfigParser.resolve_substitutions(merged)
        b = merged.get("b")
        assert len(b) == 2
        assert b[0] == {'v2': 2}
        assert b[1] == {'v1': 1, 'v2': 3}
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
def test_self_merge_ref_substitutions_object3(self):
        config1 = ConfigFactory.parse_string(
            """
            b1 : { v1: 1 }
            b = [${b1}]
            """,
            resolve=False
        )
        config2 = ConfigFactory.parse_string(
            """
            b1 : { v1: 2, v2: 3 }
            """,
            resolve=False
        )
        merged = ConfigTree.merge_configs(config1, config2)
        resolved = ConfigParser.resolve_substitutions(merged)
        assert resolved.get("b1") == {"v1": 2, "v2": 3}
        b = resolved.get("b")
        assert len(b) == 1
        assert b[0] == {"v1": 2, "v2": 3}
github chimpler / pyhocon / tests / test_config_parser.py View on Github external
config1 = ConfigFactory.parse_string(
            """
            a : { }
            b : 1
            c : ${a} { d : [ ${b} ] }
            """,
            resolve=False
        )
        config2 = ConfigFactory.parse_string(
            """
            e : ${a} {
            }
            """,
            resolve=False
        )
        merged = ConfigTree.merge_configs(config1, config2)
        resolved = ConfigParser.resolve_substitutions(merged)
        assert resolved.get("c.d") == [1]
github allegroai / trains-agent / trains_agent / commands / worker.py View on Github external
def parse_requirements(self, reqs_file=None, overrides=None):
        os = None
        session = self._session
        if overrides:
            overrides = ConfigFactory.parse_string("\n".join(overrides))
            os = overrides.pop("os", None)
            ConfigTree.merge_configs(session.config, overrides)
        if reqs_file:
            contents = Path(reqs_file).read_text()
        else:
            contents = ensure_text(sys.stdin.read())
        session.finalize_config(session.config)
        requirements_manager = self._get_requirements_manager(os_override=os)
        requirements_manager.translator.enabled = False
        print(requirements_manager.replace(contents))
github stanfordnlp / wge / gtd / utils.py View on Github external
    @classmethod
    def merge(cls, configs):
        for c in configs:
            assert isinstance(c, Config)

        ctree = configs[0]._config_tree
        for c in configs[1:]:
            ctree = ConfigTree.merge_configs(ctree, c._config_tree)

        return cls(ctree)