MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / document_module

Function document_module

docs/generate.py:98–171  ·  view source on GitHub ↗
(module, module_path, module_map, output_dir)

Source from the content-addressed store, hash-verified

96
97
98def document_module(module, module_path, module_map, output_dir):
99 if not module_is_public(module):
100 return []
101 modules = [module_path]
102 submodules = []
103 classes = []
104 functions = []
105 constants = []
106 for symbol_name in dir(module):
107 if symbol_name.startswith("_"):
108 continue
109 symbol = getattr(module, symbol_name)
110 symbol_path = "%s.%s" % (module_path, symbol_name)
111 if inspect.isclass(symbol):
112 classes.append((symbol, symbol_path))
113 elif (
114 inspect.isfunction(symbol)
115 or inspect.ismethod(symbol)
116 or inspect.isroutine(symbol)
117 ):
118 functions.append(symbol_path)
119 elif inspect.ismodule(symbol):
120 submodules.append((symbol_path, symbol))
121 elif isinstance(symbol, (numbers.Number, str)):
122 constants.append(symbol_path)
123
124 with open(os.path.join(output_dir, "%s.rst" % module_path), "w") as doc:
125 doc.write("%s\n" % module_path)
126 doc.write("=" * (len(module_path)))
127 doc.write("\n\n")
128 doc.write(".. automodule:: %s\n\n" % module_path)
129
130 doc.write(".. toctree::\n\n")
131
132 if classes:
133 for class_info in annotate_classes(classes):
134 base = class_info["parent"]
135 base_path = module_map.get(
136 base, "%s.%s" % (base.__module__, base.__name__)
137 )
138 children_paths = class_info["children"]
139 if children_paths:
140 children_paths = [
141 module_map.get(
142 child, "%s.%s" % (child.__module__, child.__name__)
143 )
144 for child in children_paths
145 ]
146 class_path = class_info["path"]
147 doc.write(" %s\n" % class_path)
148 document_class(
149 class_info["cls"],
150 output_dir,
151 class_path,
152 base_path=base_path,
153 children_paths=children_paths,
154 )
155

Callers 1

generate.pyFile · 0.85

Calls 6

module_is_publicFunction · 0.85
annotate_classesFunction · 0.85
document_classFunction · 0.85
document_functionFunction · 0.85
joinMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected