|
|
@@ -23,6 +23,13 @@ def _colored_string(string: str, color: str or int) -> str: |
|
|
|
return "\033[%dm%s\033[0m" % (color, string) |
|
|
|
|
|
|
|
|
|
|
|
def gr(string, flag): |
|
|
|
if flag: |
|
|
|
return _colored_string(string, "green") |
|
|
|
else: |
|
|
|
return _colored_string(string, "red") |
|
|
|
|
|
|
|
|
|
|
|
def find_all_modules(): |
|
|
|
modules = {} |
|
|
|
children = {} |
|
|
@@ -79,20 +86,46 @@ def create_rst_file(modules, name, children): |
|
|
|
|
|
|
|
|
|
|
|
def check_file(m, name): |
|
|
|
names = name.split('.') |
|
|
|
test_name = "test." + ".".join(names[1:-1]) + ".test_" + names[-1] |
|
|
|
try: |
|
|
|
__import__(test_name) |
|
|
|
tm = sys.modules[test_name] |
|
|
|
except ModuleNotFoundError: |
|
|
|
tm = None |
|
|
|
tested = tm is not None |
|
|
|
funcs = {} |
|
|
|
classes = {} |
|
|
|
for item, obj in inspect.getmembers(m): |
|
|
|
if inspect.isclass(obj) and obj.__module__ == name: |
|
|
|
print(obj) |
|
|
|
if inspect.isfunction(obj) and obj.__module__ == name: |
|
|
|
print("FUNC", obj) |
|
|
|
if inspect.isclass(obj) and obj.__module__ == name and not obj.__name__.startswith('_'): |
|
|
|
this = (obj.__doc__ is not None, tested and obj.__name__ in dir(tm), {}) |
|
|
|
for i in dir(obj): |
|
|
|
func = getattr(obj, i) |
|
|
|
if inspect.isfunction(func) and not i.startswith('_'): |
|
|
|
this[2][i] = (func.__doc__ is not None, False) |
|
|
|
classes[obj.__name__] = this |
|
|
|
if inspect.isfunction(obj) and obj.__module__ == name and not obj.__name__.startswith('_'): |
|
|
|
this = (obj.__doc__ is not None, tested and obj.__name__ in dir(tm)) # docs |
|
|
|
funcs[obj.__name__] = this |
|
|
|
return funcs, classes |
|
|
|
|
|
|
|
|
|
|
|
def check_files(modules): |
|
|
|
def check_files(modules, out=sys.stdout): |
|
|
|
for name in sorted(modules.keys()): |
|
|
|
if name == 'fastNLP.core.utils': |
|
|
|
check_file(modules[name], name) |
|
|
|
print(name, file=out) |
|
|
|
funcs, classes = check_file(modules[name], name) |
|
|
|
for f in funcs: |
|
|
|
print("%-30s \t %s \t %s" % (f, gr("文档", funcs[f][0]), gr("测试", funcs[f][1])), file=out) |
|
|
|
for c in classes: |
|
|
|
print("%-30s \t %s \t %s" % (c, gr("文档", classes[c][0]), gr("测试", classes[c][1])), file=out) |
|
|
|
methods = classes[c][2] |
|
|
|
for f in methods: |
|
|
|
print(" %-28s \t %s" % (f, gr("文档", methods[f][0])), file=out) |
|
|
|
print(file=out) |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
sys.path.append("..") |
|
|
|
print(_colored_string('Getting modules...', "Blue")) |
|
|
|
modules, to_doc, children = find_all_modules() |
|
|
|
print(_colored_string('Done!', "Green")) |
|
|
|