MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / get_api

Function get_api

python/oneflow/test/gen_ops_process.py:22–80  ·  view source on GitHub ↗

Extract operator names from rst files. `currentmodule` is not regarded as operators. `autoclass` and `automodule` are regarded as operators in the absence of `members`.

(rst_dir)

Source from the content-addressed store, hash-verified

20
21
22def get_api(rst_dir):
23 """
24 Extract operator names from rst files.
25
26 `currentmodule` is not regarded as operators.
27 `autoclass` and `automodule` are regarded as operators in the absence of `members`.
28 """
29 op_files = glob.glob(rst_dir + "/*.rst")
30 op_files.remove(rst_dir + "/graph.rst")
31 op_files.remove(rst_dir + "/index.rst")
32 api_list = []
33 api_str = ""
34 for op_file in op_files:
35 with open(op_file, "r") as f:
36 line = f.readline()
37 pre = ""
38 while line:
39 skip = False
40 if ".. currentmodule::" in line:
41 pre = line.strip().replace(".. currentmodule::", "") + "."
42 elif ".. autofunction::" in line:
43 if "oneflow" not in line:
44 api_str += pre
45 api_str += line.replace(".. autofunction::", "")
46 elif (
47 ".. autosummary::" in line
48 or ".. autoclass::" in line
49 or ":toctree:" in line
50 or ":nosignatures:" in line
51 or ":template:" in line
52 ):
53 if ":nosignatures:" in line:
54 line = f.readline()
55 if ":template:" in line:
56 line = f.readline()
57 line = f.readline()
58 while line and len(line.replace(" ", "")) > 1:
59 if "oneflow" not in line:
60 api_str += pre
61 api_str += line
62 line = f.readline()
63 elif ".. automodule::" in line:
64 pre_a = line.replace(".. automodule:: ", "")
65 line = f.readline()
66 skip = True
67 if ":members:" in line and len(line) > 14:
68 pre_a = pre_a.strip() + "."
69 api_str += pre_a + line.replace(":members:", "")
70 line = f.readline()
71 while (
72 line and ":" not in line and len(line.replace(" ", "")) > 1
73 ):
74 api_str += pre_a + line
75 line = f.readline()
76 if not skip:
77 line = f.readline()
78
79 api_list = api_str.strip().replace(" ", "").replace(",", "").split("\n")

Callers 1

gen_ops_process.pyFile · 0.85

Calls 2

splitMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected