MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / build_doc_index

Function build_doc_index

tensorflow/tools/docs/generate_lib.py:335–365  ·  view source on GitHub ↗

Build an index from a keyword designating a doc to _DocInfo objects.

(src_dir)

Source from the content-addressed store, hash-verified

333
334
335def build_doc_index(src_dir):
336 """Build an index from a keyword designating a doc to _DocInfo objects."""
337 doc_index = {}
338 if not os.path.isabs(src_dir):
339 raise ValueError("'src_dir' must be an absolute path.\n"
340 " src_dir='%s'" % src_dir)
341
342 if not os.path.exists(src_dir):
343 raise ValueError("'src_dir' path must exist.\n"
344 " src_dir='%s'" % src_dir)
345
346 for dirpath, _, filenames in os.walk(src_dir):
347 suffix = os.path.relpath(path=dirpath, start=src_dir)
348 for base_name in filenames:
349 if not base_name.endswith('.md'):
350 continue
351 title_parser = _GetMarkdownTitle()
352 title_parser.process(os.path.join(dirpath, base_name))
353 if title_parser.title is None:
354 msg = ('`{}` has no markdown title (# title)'.format(
355 os.path.join(dirpath, base_name)))
356 raise ValueError(msg)
357 key_parts = os.path.join(suffix, base_name[:-3]).split('/')
358 if key_parts[-1] == 'index':
359 key_parts = key_parts[:-1]
360 doc_info = _DocInfo(os.path.join(suffix, base_name), title_parser.title)
361 doc_index[key_parts[-1]] = doc_info
362 if len(key_parts) > 1:
363 doc_index['/'.join(key_parts[-2:])] = doc_info
364
365 return doc_index
366
367
368class _GuideRef(object):

Callers 1

buildMethod · 0.85

Calls 6

_GetMarkdownTitleClass · 0.85
_DocInfoClass · 0.85
processMethod · 0.65
joinMethod · 0.45
formatMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected