35
35
36
36
import astor
37
37
38
+ from tensorflow_docs .api_generator import config
38
39
from tensorflow_docs .api_generator import doc_controls
39
40
from tensorflow_docs .api_generator import doc_generator_visitor
40
41
from tensorflow_docs .api_generator import public_api
@@ -71,42 +72,6 @@ def get_obj_type(py_obj: Any) -> ObjType:
71
72
return ObjType .OTHER
72
73
73
74
74
- class ParserConfig (object ):
75
- """Stores all indexes required to parse the docs."""
76
-
77
- def __init__ (self , reference_resolver , duplicates , duplicate_of , tree , index ,
78
- reverse_index , base_dir , code_url_prefix ):
79
- """Object with the common config for docs_for_object() calls.
80
-
81
- Args:
82
- reference_resolver: An instance of ReferenceResolver.
83
- duplicates: A `dict` mapping fully qualified names to a set of all aliases
84
- of this name. This is used to automatically generate a list of all
85
- aliases for each name.
86
- duplicate_of: A map from duplicate names to preferred names of API
87
- symbols.
88
- tree: A `dict` mapping a fully qualified name to the names of all its
89
- members. Used to populate the members section of a class or module page.
90
- index: A `dict` mapping full names to objects.
91
- reverse_index: A `dict` mapping object ids to full names.
92
- base_dir: A base path that is stripped from file locations written to the
93
- docs.
94
- code_url_prefix: A Url to pre-pend to the links to file locations.
95
- """
96
- self .reference_resolver = reference_resolver
97
- self .duplicates = duplicates
98
- self .duplicate_of = duplicate_of
99
- self .tree = tree
100
- self .reverse_index = reverse_index
101
- self .index = index
102
- self .base_dir = base_dir
103
- self .code_url_prefix = code_url_prefix
104
-
105
- def py_name_to_object (self , full_name ):
106
- """Return the Python object for a Python symbol name."""
107
- return self .index [full_name ]
108
-
109
-
110
75
@dataclasses .dataclass
111
76
class _FileLocation (object ):
112
77
"""This class indicates that the object is defined in a regular file.
@@ -918,7 +883,7 @@ class _DocstringInfo(typing.NamedTuple):
918
883
919
884
def _get_other_member_doc (
920
885
obj : Any ,
921
- parser_config : ParserConfig ,
886
+ parser_config : config . ParserConfig ,
922
887
extra_docs : Optional [Dict [int , str ]],
923
888
) -> str :
924
889
"""Returns the docs for other members of a module."""
@@ -981,7 +946,7 @@ def _get_other_member_doc(
981
946
def _parse_md_docstring (
982
947
py_object : Any ,
983
948
full_name : str ,
984
- parser_config : ParserConfig ,
949
+ parser_config : config . ParserConfig ,
985
950
extra_docs : Optional [Dict [int , str ]] = None ,
986
951
) -> _DocstringInfo :
987
952
"""Parse the object's docstring and return a `_DocstringInfo`.
@@ -994,7 +959,7 @@ def _parse_md_docstring(
994
959
or module).
995
960
full_name: (optional) The api path to the current object, so replacements
996
961
can depend on context.
997
- parser_config: An instance of `ParserConfig`.
962
+ parser_config: An instance of `config. ParserConfig`.
998
963
extra_docs: Extra docs for symbols like public constants(list, tuple, etc)
999
964
that need to be added to the markdown pages created.
1000
965
@@ -1156,7 +1121,7 @@ class FormatArguments(object):
1156
1121
def __init__ (
1157
1122
self ,
1158
1123
type_annotations : Dict [str , str ],
1159
- parser_config : ParserConfig ,
1124
+ parser_config : config . ParserConfig ,
1160
1125
func_full_name : str ,
1161
1126
) -> None :
1162
1127
self ._type_annotations = type_annotations
@@ -1403,7 +1368,7 @@ class FuncType(enum.Enum):
1403
1368
1404
1369
def generate_signature (
1405
1370
func : Any ,
1406
- parser_config : ParserConfig ,
1371
+ parser_config : config . ParserConfig ,
1407
1372
func_full_name : str ,
1408
1373
func_type : FuncType ,
1409
1374
) -> _SignatureComponents :
@@ -1417,7 +1382,7 @@ def generate_signature(
1417
1382
1418
1383
Args:
1419
1384
func: A function, method, or functools.partial to extract the signature for.
1420
- parser_config: `ParserConfig` for the method/function whose signature is
1385
+ parser_config: `config. ParserConfig` for the method/function whose signature is
1421
1386
generated.
1422
1387
func_full_name: The full name of a function whose signature is generated.
1423
1388
func_type: Type of the current `func`. This is required because there isn't
@@ -1740,7 +1705,7 @@ def collect_docs(self, parser_config):
1740
1705
Mainly this is details about the function signature.
1741
1706
1742
1707
Args:
1743
- parser_config: The ParserConfig for the module being documented.
1708
+ parser_config: The config. ParserConfig for the module being documented.
1744
1709
"""
1745
1710
1746
1711
assert self .signature is None
@@ -1855,7 +1820,7 @@ def collect_docs(self, parser_config) -> None:
1855
1820
```
1856
1821
1857
1822
Args:
1858
- parser_config: The ParserConfig for the module being documented.
1823
+ parser_config: The config. ParserConfig for the module being documented.
1859
1824
"""
1860
1825
assert self .signature is None
1861
1826
@@ -1958,7 +1923,7 @@ def _set_bases(self, parser_config):
1958
1923
doc pages for the class' parents.
1959
1924
1960
1925
Args:
1961
- parser_config: An instance of `ParserConfig`.
1926
+ parser_config: An instance of `config. ParserConfig`.
1962
1927
"""
1963
1928
bases = []
1964
1929
for base in self .py_object .__mro__ [1 :]:
@@ -2016,13 +1981,13 @@ def _add_method(
2016
1981
self ,
2017
1982
member_info : MemberInfo ,
2018
1983
defining_class : Optional [type ], # pylint: disable=g-bare-generic
2019
- parser_config : ParserConfig ) -> None :
1984
+ parser_config : config . ParserConfig ) -> None :
2020
1985
"""Adds a `MethodInfo` entry to the `methods` list.
2021
1986
2022
1987
Args:
2023
1988
member_info: a `MemberInfo` describing the method.
2024
1989
defining_class: The `type` object where this method is defined.
2025
- parser_config: A `ParserConfig`.
1990
+ parser_config: A `config. ParserConfig`.
2026
1991
"""
2027
1992
if defining_class is None :
2028
1993
return
@@ -2119,7 +2084,7 @@ def _add_member(
2119
2084
self ,
2120
2085
member_info : MemberInfo ,
2121
2086
defining_class : Optional [type ], # pylint: disable=g-bare-generic
2122
- parser_config : ParserConfig ,
2087
+ parser_config : config . ParserConfig ,
2123
2088
) -> None :
2124
2089
"""Adds a member to the class page."""
2125
2090
obj_type = get_obj_type (member_info .py_object )
@@ -2147,7 +2112,7 @@ def collect_docs(self, parser_config):
2147
2112
Mainly, this is details about the class's members.
2148
2113
2149
2114
Args:
2150
- parser_config: An instance of ParserConfig.
2115
+ parser_config: An instance of config. ParserConfig.
2151
2116
"""
2152
2117
py_class = self .py_object
2153
2118
@@ -2359,7 +2324,7 @@ def collect_docs(self, parser_config):
2359
2324
Mainly this is information about the members of the module.
2360
2325
2361
2326
Args:
2362
- parser_config: An instance of ParserConfig.
2327
+ parser_config: An instance of config. ParserConfig.
2363
2328
"""
2364
2329
2365
2330
member_names = parser_config .tree .get (self .full_name , [])
@@ -2392,7 +2357,7 @@ def collect_docs(self, parser_config):
2392
2357
def docs_for_object (
2393
2358
full_name : str ,
2394
2359
py_object : Any ,
2395
- parser_config : ParserConfig ,
2360
+ parser_config : config . ParserConfig ,
2396
2361
extra_docs : Optional [Dict [int , str ]] = None ,
2397
2362
) -> PageInfo :
2398
2363
"""Return a PageInfo object describing a given object from the TF API.
@@ -2412,7 +2377,7 @@ def docs_for_object(
2412
2377
full_name: The fully qualified name of the symbol to be documented.
2413
2378
py_object: The Python object to be documented. Its documentation is sourced
2414
2379
from `py_object`'s docstring.
2415
- parser_config: A ParserConfig object.
2380
+ parser_config: A config. ParserConfig object.
2416
2381
extra_docs: Extra docs for symbols like public constants(list, tuple, etc)
2417
2382
that need to be added to the markdown pages created.
2418
2383
@@ -2477,13 +2442,14 @@ def _unwrap_obj(obj):
2477
2442
return obj
2478
2443
2479
2444
2480
- def _get_defined_in (py_object : Any ,
2481
- parser_config : ParserConfig ) -> Optional [_FileLocation ]:
2445
+ def _get_defined_in (
2446
+ py_object : Any ,
2447
+ parser_config : config .ParserConfig ) -> Optional [_FileLocation ]:
2482
2448
"""Returns a description of where the passed in python object was defined.
2483
2449
2484
2450
Args:
2485
2451
py_object: The Python object.
2486
- parser_config: A ParserConfig object.
2452
+ parser_config: A config. ParserConfig object.
2487
2453
2488
2454
Returns:
2489
2455
A `_FileLocation`
0 commit comments