1# Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Specifies sources of doc strings for API modules.""" 16from tensorflow.python.util import tf_export 17 18 19class DocSource(object): 20 """Specifies docstring source for a module. 21 22 Only one of docstring or docstring_module_name should be set. 23 * If docstring is set, then we will use this docstring when 24 for the module. 25 * If docstring_module_name is set, then we will copy the docstring 26 from docstring source module. 27 """ 28 29 def __init__(self, docstring=None, docstring_module_name=None): 30 self.docstring = docstring 31 self.docstring_module_name = docstring_module_name 32 33 if self.docstring is not None and self.docstring_module_name is not None: 34 raise ValueError('Only one of `docstring` or `docstring_module_name` can ' 35 'be set.') 36 37 38_TENSORFLOW_DOC_SOURCES = { 39 'app': 40 DocSource(docstring_module_name='platform.app'), 41 'bitwise': 42 DocSource(docstring_module_name='ops.bitwise_ops'), 43 'compat': 44 DocSource(docstring_module_name='util.compat'), 45 'distribute': 46 DocSource(docstring_module_name='distribute.distribute_lib'), 47 'distributions': 48 DocSource(docstring_module_name='ops.distributions.distributions'), 49 'errors': 50 DocSource(docstring_module_name='framework.errors'), 51 'experimental.numpy': 52 DocSource(docstring_module_name='ops.numpy_ops'), 53 'gfile': 54 DocSource(docstring_module_name='platform.gfile'), 55 'graph_util': 56 DocSource(docstring_module_name='framework.graph_util'), 57 'image': 58 DocSource(docstring_module_name='ops.image_ops'), 59 'linalg': 60 DocSource(docstring_module_name='ops.linalg_ops'), 61 'logging': 62 DocSource(docstring_module_name='ops.logging_ops'), 63 'losses': 64 DocSource(docstring_module_name='ops.losses.losses'), 65 'manip': 66 DocSource(docstring_module_name='ops.manip_ops'), 67 'math': 68 DocSource(docstring_module_name='ops.math_ops'), 69 'metrics': 70 DocSource(docstring_module_name='ops.metrics'), 71 'nest': 72 DocSource(docstring_module_name='util.nest'), 73 'nn': 74 DocSource(docstring_module_name='ops.nn_ops'), 75 'nn.rnn_cell': 76 DocSource(docstring_module_name='ops.rnn_cell'), 77 'python_io': 78 DocSource(docstring_module_name='lib.io.python_io'), 79 'ragged': 80 DocSource(docstring_module_name='ops.ragged'), 81 'resource_loader': 82 DocSource(docstring_module_name='platform.resource_loader'), 83 'sets': 84 DocSource(docstring_module_name='ops.sets'), 85 'signal': 86 DocSource(docstring_module_name='ops.signal.signal'), 87 'sparse': 88 DocSource(docstring_module_name='ops.sparse_ops'), 89 'strings': 90 DocSource(docstring_module_name='ops.string_ops'), 91 'summary': 92 DocSource(docstring_module_name='summary.summary'), 93 'sysconfig': 94 DocSource(docstring_module_name='platform.sysconfig'), 95 'test': 96 DocSource(docstring_module_name='platform.test'), 97 'train': 98 DocSource(docstring_module_name='training.training'), 99} 100 101_ESTIMATOR_DOC_SOURCES = { 102 'estimator': DocSource( 103 docstring_module_name='estimator_lib'), 104 'estimator.export': DocSource( 105 docstring_module_name='export.export_lib'), 106 'estimator.inputs': DocSource( 107 docstring_module_name='inputs.inputs'), 108} 109 110_KERAS_DOC_SOURCES = { 111 'keras.optimizers.experimental': 112 DocSource(docstring_module_name='optimizers.optimizer_experimental') 113} 114 115 116def get_doc_sources(api_name): 117 """Get a map from module to a DocSource object. 118 119 Args: 120 api_name: API you want to generate (e.g. `tensorflow` or `estimator`). 121 122 Returns: 123 Map from module name to DocSource object. 124 """ 125 if api_name == tf_export.TENSORFLOW_API_NAME: 126 return _TENSORFLOW_DOC_SOURCES 127 if api_name == tf_export.ESTIMATOR_API_NAME: 128 return _ESTIMATOR_DOC_SOURCES 129 if api_name == tf_export.KERAS_API_NAME: 130 return _KERAS_DOC_SOURCES 131 return {} 132