def parse_json_sweep()

in egg/nest/common.py [0:0]


def parse_json_sweep(config):
    config = {k: v if type(v) is list else [v] for k, v in config.items()}
    perms = list(itertools.product(*config.values()))

    def to_arg(k, v):
        if type(v) in (int, float):
            return f"--{k}={v}"
        elif type(v) is bool:
            return f"--{k}" if v else ""
        elif type(v) is str:
            assert (
                '"' not in v
            ), f"Key {k} has string value {v} which contains forbidden quotes."
            return f"--{k}={v}"
        else:
            raise Exception(f"Key {k} has value {v} of unsupported type {type(v)}.")

    commands = []
    for p in perms:
        args = [to_arg(k, p[i]) for i, k in enumerate(config.keys()) if to_arg(k, p[i])]
        commands.append(args)
    return commands