[docs]defvalidate(self)->None:logger.debug("Validating MLproject at %s and backend config at %s",self.mlproject_path.as_posix(),self.config_absolute_path.as_posix(),)ifnotself.mlproject_path.is_absolute():raiseexceptions.ConfigValidationError("ML project path must be an absolute path, "f"but {self.mlproject_path.as_posix()!r} was given.")ifnotself.mlproject_path.is_dir():raiseexceptions.ConfigValidationError("ML project path not found at "f"{self.mlproject_path.as_posix()!r}, ""check that the given path is correct.")ifnotself.config_absolute_path.is_file():raiseexceptions.ConfigValidationError("Config not found at "f"{self.config_absolute_path.as_posix()!r}, ""check that the given path is correct.")ifnot(self.mlproject_pathinself.config_absolute_path.parents):raiseexceptions.ConfigValidationError("Config file is not in the ML project directory, ""check that the given paths are correct:\n"f"Config file: {self.config_absolute_path.as_posix()!r}\n"f"ML project directory: {self.mlproject_path.as_posix()!r}")ifself.config.execution_environment_given():self._validate_execution_path(self.config.environment.execution)logger.debug("Validating MLproject configuration.")self._validate_ml_project_file()self._validate_config_not_in_exclude()
def_validate_execution_path(self,execution:executable.Execution):ifexecution.path_has_to_be_checked:execution_absolute_path=self.mlproject_path/execution.pathifnotexecution_absolute_path.is_file():raiseexceptions.ConfigValidationError(f"The path {execution_absolute_path.as_posix()!r} given ""as execution environment was not found, ""check that the given path is correct. ""The path must be relative to the ML project path.")def_validate_ml_project_file(self)->None:try:importmlflowexceptModuleNotFoundError:logger.warning(("Cannot validate MLproject file since mlflow package ""is not installed. Either install the supported version "'via `pip install "mantik[mlflow]"` or install a '"desired MLflow version manually."),exc_info=True,)else:mlflow.projects.utils.fetch_and_validate_project(uri=self.mlproject_path.as_posix(),version=None,entry_point=self.entry_point,parameters=self.mlflow_parameters,)def_validate_config_not_in_exclude(self)->None:ifupload.file_matches_exclude_pattern(path=self.config_absolute_path,project_dir=self.mlproject_path,exclude=self.config.files_to_exclude,):raiseexceptions.ConfigValidationError(f"Config file '{self.config_path.name}' cannot be excluded, "f"check config 'Exclude' section")