def load_docstring_conf(docstring_conf_path: str) -> dict:
    """ Load a Yaml format docstring configuration """
    try:
        logging.info(
            f'Load docstring configuration from {docstring_conf_path}')
        with open(docstring_conf_path, 'r') as fd:
            return yaml.load(fd)
    except yaml.YAMLError as e:
        raise MlVToolConfException(
            f'Cannot load docstring conf {docstring_conf_path}. Format error {e}.'
        ) from e
    except IOError as e:
        raise MlVToolConfException(
            f'Cannot load file {docstring_conf_path}. IOError {e}') from e
 def top_directory_exists(cls, value, values, config, field):
     if not exists(value):
         raise MlVToolConfException(
             f'Configuration error {field.name}, can not find top directory {value}'
         )
     cls.top_directory = value
     return value
 def load_from_file(file_path: str, working_directory) -> 'MlVToolConf':
     try:
         with open(file_path, 'r') as fd:
             conf_raw_data = json.load(fd)
         conf_raw_data.update(
             MlVToolConf.get_top_directory_raw_data(working_directory))
         return MlVToolConf.parse_obj(conf_raw_data)
     except JSONDecodeError as e:
         raise MlVToolConfException(
             f'Cannot load conf from file {file_path}. Wrong format') from e
     except ValidationError as e:
         raise MlVToolConfException(
             f'Cannot load conf from file {file_path}. Validation error'
         ) from e
     except IOError as e:
         raise MlVToolConfException(
             f'Cannot load conf from file {file_path}') from e
Пример #4
0
 def directories_exits(cls, value):
     for field in value.fields:
         path = getattr(value, field)
         if not exists(join(cls.top_directory, path)):
             raise MlVToolConfException(
                 f'Configuration error {field}, can not find directory {path}'
             )
     return value
 def directories_exists(cls, values):
     paths = values["path"]
     if not paths:
         return values
     top_directory = values["top_directory"]
     for field in paths.fields:
         path = getattr(paths, field)
         if not exists(join(top_directory, path)):
             raise MlVToolConfException(
                 f'Configuration error {field}, can not find directory {path}'
             )
     return values
 def is_valid_var_name(cls, value, values, config, field):
     if not re.match(r'^[a-zA-Z]\w*$', value):
         raise MlVToolConfException(
             f'Configuration error {field.name} must be a valid bash variable name : {value}'
         )
     return value