def validate_documentation_files()

in tools/validator.py [0:0]


def validate_documentation_files(validation_config: ValidationConfig,
                                 root_dir: str,
                                 files_to_validate: MutableSequence[str],
                                 relative_docs_path: str = DOCS_PATH) -> None:
  """Validate specified Markdown documentation files.

  Args:
    validation_config: TestConfig specifying whether the "asset-path" tag should
      be validated and the remote path be downloaded.
    root_dir: Absolute path to the top-level dir that contains Markdown files
      and YAML config files.
    files_to_validate: List of file paths in `root_dir` that should be
      validated.
    relative_docs_path: Relative path under `root_dir` containing the Markdown
      files. Defaults to "assets/docs".

  Raises:
    MarkdownDocumentationError: if invalid Markdown files have been found.
  """
  documentation_dir = os.path.join(root_dir, relative_docs_path)
  # Passing this map prevents re-initializing the needed parsers for each
  # document, which would be IO heavy due to reading configs from YAML files.
  yaml_parser_by_tag_name = {
      tag_name:
      yaml_parser_lib.AbstractYamlParser.from_tag_name(root_dir, tag_name)
      for tag_name in yaml_parser_lib.TAG_TO_YAML_MAP
  }
  logging.info("Going to validate files %s in documentation directory %s.",
               files_to_validate, documentation_dir)
  validated = 0
  file_to_error = dict()

  for file_path in files_to_validate:
    logging.info("Validating %s.", file_path)
    documentation_parser = DocumentationParser(root_dir, documentation_dir,
                                               yaml_parser_by_tag_name)
    try:
      absolute_path = os.path.join(documentation_dir, file_path)
      documentation_parser.validate(validation_config, absolute_path)
      validated += 1
    except MarkdownDocumentationError as e:
      file_to_error[file_path] = str(e)
  if not validation_config.do_smoke_test:
    logging.info(
        "No models were smoke tested. To download and smoke test a specific "
        "model, specify files directly in the command line, for example: "
        "'python tools/validator.py vtab/models/wae-ukl/1.md'")
  if file_to_error:
    raise MarkdownDocumentationError(
        f"Found the following errors: {file_to_error}")
  logging.info("Found %d matching files - all validated successfully.",
               validated)