Esempio n. 1
0
def merge_overrides(args: argparse.Namespace, config: ns.Namespace):
    """Merge command line overrides into configuration"""

    config.no_gui = args.no_gui
    for arg in ARGS:
        value = getattr(args, cast(str, arg['name']))
        if not value:
            continue
        ns.set_in_path(config, cast(str, arg['path']), value)
Esempio n. 2
0
def merge_augmented_settings(config: ns.Namespace):
    """ Merges settings from file in setting augment_from, if any """

    local = ns.get_section(config, 'Local')
    if local is None:
        return
    fname = local._get('augment_from')
    if fname is None:
        return
    if not isabs(fname):
        fname = join(config.cfgdir, fname)
    if not exists(fname):
        raise ConfigurationError(
            f"augment_from file {local._get('augment_from')} not found")
    cs = ns.dict2ns(toml.load(fname))
    # Add/override each key/value in augment_from
    for k, v in cs._flattened():
        ns.set_in_path(config, k, v)
def test_set_in_path():
    cfg = ns.Namespace()
    ns.set_in_path(cfg, 'Testing.One.Two.Three.name', '42')
    assert cfg.Testing.One.Two.Three.name == '42'
def test_set_in_path_section_exists():
    cfg = ns.Namespace()
    cfg.Section = ns.Namespace()
    ns.set_in_path(cfg, "Section.name", '42')
    assert cfg.Section.name == '42'
def test_set_in_path_section_is_value():
    cfg = ns.Namespace()
    cfg.Section = ''
    with pytest.raises(ns.ConfigurationError):
        ns.set_in_path(cfg, "Section.name", '42')