Beispiel #1
0
def _validate_script_path(
    path: tfds.core.ReadOnlyPath, ) -> Optional[tfds.core.ReadOnlyPath]:
    """Validates and returns the `dataset.py` generation script path."""
    if path.suffix != '.py':
        raise ValueError(f'Expected `.py` file. Invalid dataset path: {path}.')
    if not path.exists():
        raise FileNotFoundError(
            f'Could not find dataset generation script: {path}. ')
    return path
def _save_table_of_content(
    catalog_dir: tfds.core.ReadWritePath,
    section_to_builder_docs: Dict[str,
                                  List[document_datasets.BuilderDocumentation]],
    toc_relative_path: str,
    index_template: tfds.core.ReadOnlyPath,
    index_filename: str,
) -> None:
  """Builds and saves the table of contents (`_toc.yaml` and `overview.md`)."""
  # For _toc.yaml
  toc_yaml = {
      'toc': [{
          'title': 'Overview',
          'path': os.path.join(toc_relative_path, 'overview'),
      }]
  }
  # For overview.md
  toc_overview = []

  # All builder documented, save the table of content
  for section, builder_docs in sorted(section_to_builder_docs.items()):
    builder_docs = sorted(builder_docs, key=lambda doc: doc.name)
    # `object_detection` -> `Object detection`
    section_str = section.replace('_', ' ').capitalize()

    # Add `_toc.yaml` section
    sec_dict = {'title': section_str, 'section': []}
    for doc in builder_docs:
      sidebar_item = {
          'path': os.path.join(toc_relative_path, doc.filestem),
          'title': doc.name + (' (manual)' if doc.is_manual else '')
      }
      if doc.is_nightly:
        sidebar_item['status'] = 'nightly'
      sec_dict['section'].append(sidebar_item)
    toc_yaml['toc'].append(sec_dict)

    # Add `overview.md` section
    toc_overview.append(_create_section_toc(section_str, builder_docs))

  # Write the `overview.md` page
  index_str = index_template.read_text().format(toc='\n'.join(toc_overview))
  catalog_dir.joinpath(index_filename).write_text(index_str)

  # Write the `_toc.yaml` TF documentation navigation bar
  with catalog_dir.joinpath('_toc.yaml').open('w') as f:
    yaml.dump(toc_yaml, f, default_flow_style=False)