def load_module_with_error_messages(module_type, predefined_f, name, metadata_schema=None): custom = not predefined_module(name) template = "custom {} at path '{}'" if custom else "predefined {} '{}'" msg = template.format(module_type, name) path = Path(name) if custom else predefined_f(name) try: module = load_module(path) except IOError: raise ModuleNotFoundError("Requested {} does not exist".format(msg)) # have a module loaded - has a metadata check been requested? if metadata_schema is not None: # Yes - grab the metadata try: metadata = getattr(module, 'metadata') except AttributeError: raise MissingMetadataError(msg) else: if not schema_is_valid(metadata_schema, metadata): # there is something incorrect about the metadata - try and # print a helpful message. report = schema_error_report(metadata_schema, metadata) raise SchemaError('metadata', msg, report) else: return module, metadata else: return module
def save_custom_config(c, validate_schema=True): from menpobench.utils import save_yaml, load_yaml if custom_config_path().exists(): # Update existing config file with new information config = load_yaml(custom_config_path()) config.update(c) else: config = c if validate_schema: # validate the config against the schema s = config_schema() if not schema_is_valid(s, config): report = schema_error_report(s, config) raise SchemaError('configuration', 'user', report) save_yaml(config, custom_config_path())
def validate_experiment_def(config): s = experiment_schema() if not schema_is_valid(s, config): report = schema_error_report(s, config) raise SchemaError(config, "experiment", report)