Пример #1
0
 def testHaveDocstringOrDocstringModule(self):
   for module_name, docsrc in doc_srcs.get_doc_sources(FLAGS.api_name).items():
     self.assertFalse(
         docsrc.docstring and docsrc.docstring_module_name,
         msg=('%s contains DocSource has both a docstring and a '
              'docstring_module_name. Only one of "docstring" or '
              '"docstring_module_name" should be set.') % (module_name))
Пример #2
0
 def testHaveDocstringOrDocstringModule(self):
     for module_name, docsrc in doc_srcs.get_doc_sources(
             FLAGS.api_name).items():
         self.assertFalse(
             docsrc.docstring and docsrc.docstring_module_name,
             msg=('%s contains DocSource has both a docstring and a '
                  'docstring_module_name. Only one of "docstring" or '
                  '"docstring_module_name" should be set.') % (module_name))
Пример #3
0
 def testDocstringModulesAreValidModules(self):
   for _, docsrc in doc_srcs.get_doc_sources(FLAGS.api_name).items():
     if docsrc.docstring_module_name:
       doc_module_name = '.'.join([
           FLAGS.package, docsrc.docstring_module_name])
       self.assertIn(
           doc_module_name, sys.modules,
           msg=('docsources_module %s is not a valid module under %s.' %
                (docsrc.docstring_module_name, FLAGS.package)))
Пример #4
0
 def testDocstringModulesAreValidModules(self):
     for _, docsrc in doc_srcs.get_doc_sources(FLAGS.api_name).items():
         if docsrc.docstring_module_name:
             doc_module_name = '.'.join(
                 [FLAGS.package, docsrc.docstring_module_name])
             self.assertIn(
                 doc_module_name,
                 sys.modules,
                 msg=('docsources_module %s is not a valid module under %s.'
                      % (docsrc.docstring_module_name, FLAGS.package)))
Пример #5
0
    def testModulesAreValidAPIModules(self):
        for module_name in doc_srcs.get_doc_sources(FLAGS.api_name):
            # Convert module_name to corresponding __init__.py file path.
            file_path = module_name.replace('.', '/')
            if file_path:
                file_path += '/'
            file_path += '__init__.py'

            self.assertIn(file_path,
                          FLAGS.outputs,
                          msg='%s is not a valid API module' % module_name)
Пример #6
0
  def testModulesAreValidAPIModules(self):
    for module_name in doc_srcs.get_doc_sources(FLAGS.api_name):
      # Convert module_name to corresponding __init__.py file path.
      file_path = module_name.replace('.', '/')
      if file_path:
        file_path += '/'
      file_path += '__init__.py'

      self.assertIn(
          file_path, FLAGS.outputs,
          msg='%s is not a valid API module' % module_name)
Пример #7
0
def get_module_docstring(module_name, package, api_name):
    """Get docstring for the given module.

  This method looks for docstring in the following order:
  1. Checks if module has a docstring specified in doc_srcs.
  2. Checks if module has a docstring source module specified
     in doc_srcs. If it does, gets docstring from that module.
  3. Checks if module with module_name exists under base package.
     If it does, gets docstring from that module.
  4. Returns a default docstring.

  Args:
    module_name: module name relative to tensorflow (excluding 'tensorflow.'
      prefix) to get a docstring for.
    package: Base python package containing python with target tf_export
      decorators.
    api_name: API you want to generate (e.g. `tensorflow` or `estimator`).

  Returns:
    One-line docstring to describe the module.
  """
    # Get the same module doc strings for any version. That is, for module
    # 'compat.v1.foo' we can get docstring from module 'foo'.
    for version in _API_VERSIONS:
        compat_prefix = _COMPAT_MODULE_TEMPLATE % version
        if module_name.startswith(compat_prefix):
            module_name = module_name[len(compat_prefix):].strip('.')

    # Module under base package to get a docstring from.
    docstring_module_name = module_name

    doc_sources = doc_srcs.get_doc_sources(api_name)

    if module_name in doc_sources:
        docsrc = doc_sources[module_name]
        if docsrc.docstring:
            return docsrc.docstring
        if docsrc.docstring_module_name:
            docstring_module_name = docsrc.docstring_module_name

    if package != 'keras':
        docstring_module_name = package + '.' + docstring_module_name
    if (docstring_module_name in sys.modules
            and sys.modules[docstring_module_name].__doc__):
        return sys.modules[docstring_module_name].__doc__

    return 'Public API for tf.%s namespace.' % module_name
Пример #8
0
def get_module_docstring(module_name, package, api_name):
  """Get docstring for the given module.

  This method looks for docstring in the following order:
  1. Checks if module has a docstring specified in doc_srcs.
  2. Checks if module has a docstring source module specified
     in doc_srcs. If it does, gets docstring from that module.
  3. Checks if module with module_name exists under base package.
     If it does, gets docstring from that module.
  4. Returns a default docstring.

  Args:
    module_name: module name relative to tensorflow
      (excluding 'tensorflow.' prefix) to get a docstring for.
    package: Base python package containing python with target tf_export
      decorators.
    api_name: API you want to generate (e.g. `tensorflow` or `estimator`).

  Returns:
    One-line docstring to describe the module.
  """
  # Get the same module doc strings for any version. That is, for module
  # 'compat.v1.foo' we can get docstring from module 'foo'.
  for version in _API_VERSIONS:
    compat_prefix = _COMPAT_MODULE_TEMPLATE % version
    if module_name.startswith(compat_prefix):
      module_name = module_name[len(compat_prefix):].strip('.')

  # Module under base package to get a docstring from.
  docstring_module_name = module_name

  doc_sources = doc_srcs.get_doc_sources(api_name)

  if module_name in doc_sources:
    docsrc = doc_sources[module_name]
    if docsrc.docstring:
      return docsrc.docstring
    if docsrc.docstring_module_name:
      docstring_module_name = docsrc.docstring_module_name

  docstring_module_name = package + '.' + docstring_module_name
  if (docstring_module_name in sys.modules and
      sys.modules[docstring_module_name].__doc__):
    return sys.modules[docstring_module_name].__doc__

  return 'Public API for tf.%s namespace.' % module_name
Пример #9
0
def get_module_docstring(module_name, package, api_name):
  """Get docstring for the given module.

  This method looks for docstring in the following order:
  1. Checks if module has a docstring specified in doc_srcs.
  2. Checks if module has a docstring source module specified
     in doc_srcs. If it does, gets docstring from that module.
  3. Checks if module with module_name exists under base package.
     If it does, gets docstring from that module.
  4. Returns a default docstring.

  Args:
    module_name: module name relative to tensorflow
      (excluding 'tensorflow.' prefix) to get a docstring for.
    package: Base python package containing python with target tf_export
      decorators.
    api_name: API you want to generate (e.g. `tensorflow` or `estimator`).

  Returns:
    One-line docstring to describe the module.
  """
  # Module under base package to get a docstring from.
  docstring_module_name = module_name

  doc_sources = doc_srcs.get_doc_sources(api_name)

  if module_name in doc_sources:
    docsrc = doc_sources[module_name]
    if docsrc.docstring:
      return docsrc.docstring
    if docsrc.docstring_module_name:
      docstring_module_name = docsrc.docstring_module_name

  docstring_module_name = package + '.' + docstring_module_name
  if (docstring_module_name in sys.modules and
      sys.modules[docstring_module_name].__doc__):
    return sys.modules[docstring_module_name].__doc__

  return 'Public API for tf.%s namespace.' % module_name
Пример #10
0
def get_module_docstring(module_name, package, api_name):
    """Get docstring for the given module.

  This method looks for docstring in the following order:
  1. Checks if module has a docstring specified in doc_srcs.
  2. Checks if module has a docstring source module specified
     in doc_srcs. If it does, gets docstring from that module.
  3. Checks if module with module_name exists under base package.
     If it does, gets docstring from that module.
  4. Returns a default docstring.

  Args:
    module_name: module name relative to tensorflow
      (excluding 'tensorflow.' prefix) to get a docstring for.
    package: Base python package containing python with target tf_export
      decorators.
    api_name: API you want to generate (e.g. `tensorflow` or `estimator`).

  Returns:
    One-line docstring to describe the module.
  """
    # Module under base package to get a docstring from.
    docstring_module_name = module_name

    doc_sources = doc_srcs.get_doc_sources(api_name)

    if module_name in doc_sources:
        docsrc = doc_sources[module_name]
        if docsrc.docstring:
            return docsrc.docstring
        if docsrc.docstring_module_name:
            docstring_module_name = docsrc.docstring_module_name

    docstring_module_name = package + '.' + docstring_module_name
    if (docstring_module_name in sys.modules
            and sys.modules[docstring_module_name].__doc__):
        return sys.modules[docstring_module_name].__doc__

    return 'Public API for tf.%s namespace.' % module_name