def validate_config()

in dynalab_cli/utils.py [0:0]


    def validate_config(self):
        config = self.load_config()
        contained_fields = set()
        key = "exclude"
        assert key in config, f"Missing config field {key}"
        excluded_files = set()
        if config[key]:
            files = config[key]
            for f in files:
                assert check_path(
                    os.path.join(self.root_dir, f),
                    root_dir=self.root_dir,
                    is_file=False,
                    allow_empty=True,
                ), f"{f} is not a valid path"
                excluded_files.add(f)
            config[key] = ",".join(excluded_files)
        for key in config.keys():
            assert key in self.config_fields, f"Invalid config field {key}"
            assert key not in contained_fields, f"Repeated config field {key}"
            contained_fields.add(key)
            if key == "task":
                _, task_codes = get_tasks()
                assert config[key] in task_codes, f"Invalid task name {config[key]}"
            elif key in ("checkpoint", "handler"):
                assert check_path(
                    os.path.join(self.root_dir, config[key]),
                    root_dir=self.root_dir,
                    allow_empty=False,
                ), f"{config[key]} is empty or not a valid path"
                assert (
                    config[key] not in excluded_files
                ), f"{key} file {config[key]} cannot be excluded"
                if key == "handler":
                    assert config[key].endswith(".py"), f"Handler must be a Python file"
            elif key == "model_files":
                if config[key]:
                    files = config[key]
                    for f in files:
                        assert check_path(
                            os.path.join(self.root_dir, f),
                            root_dir=self.root_dir,
                            allow_empty=False,
                        ), f"{key} path {f} is empty or not a valid path"
                        assert (
                            f not in excluded_files
                        ), f"{key} file {f} cannot be excluded"
            elif key in ("requirements", "setup"):
                assert isinstance(
                    config[key], bool
                ), f"{key.capitalize()} field must be a boolean true/false"
                if config[key]:
                    assert check_path(
                        os.path.join(self.root_dir, default_filename(key)),
                        root_dir=self.root_dir,
                        allow_empty=False,
                    ), (
                        f"Cannot install {key} without or with empty "
                        f"./{default_filename(key)}"
                    )

        for field in self.config_fields:
            assert field in contained_fields, f"Missing config field {key}"