def validate()

in lib/metric-config-parser/metric_config_parser/cli.py [0:0]


def validate(path: Iterable[os.PathLike], config_repos, private_config_repos):
    """Validate config files."""
    dirty = False
    config_collection = ConfigCollection.from_github_repos(config_repos).from_github_repos(
        private_config_repos, is_private=True
    )

    # get updated definition files
    for config_file in path:
        config_file = Path(config_file)
        if not config_file.is_file():
            continue
        if ".example" in config_file.suffixes:
            print(f"Skipping example config {config_file}")
            continue

        if config_file.parent.name == DEFINITIONS_DIR:
            entity = entity_from_path(config_file)
            try:
                if isinstance(entity, Outcome):
                    entity.validate(config_collection)
                elif not isinstance(entity, FunctionsSpec):
                    entity.validate(config_collection, None)  # type: ignore
            except Exception as e:
                dirty = True
                print(e)
            else:
                print(f"{config_file} OK")

            if isinstance(entity, DefinitionConfig):
                config_collection.definitions.append(entity)

    for config_file in path:
        config_file = Path(config_file)
        if config_file.parent.name == DEFINITIONS_DIR:
            continue
        if not config_file.is_file():
            continue
        if ".example" in config_file.suffixes:
            print(f"Skipping example config {config_file}")
            continue
        print(f"Evaluating {config_file}...")
        entity = entity_from_path(config_file)
        try:
            if not isinstance(entity, FunctionsSpec) and not isinstance(entity, Outcome):
                entity.validate(config_collection, None)  # type: ignore
        except Exception as e:
            dirty = True
            print(e)
        else:
            print(f"{config_file} OK")

    sys.exit(1 if dirty else 0)