Skip to content

Commit d129d7f

Browse files
fix docs generation
1 parent 1256929 commit d129d7f

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

docs/stubs_to_sources.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
PACKAGE = (Path(__file__) / "../../zenoh").resolve()
3030
__INIT__ = PACKAGE / "__init__.py"
31+
EXT = PACKAGE / "ext.py"
3132

3233

3334
def _unstable(item):
@@ -74,7 +75,8 @@ def visit_FunctionDef(self, node: ast.FunctionDef):
7475
node.decorator_list.clear()
7576
if node.name not in ("recv", "try_recv", "__iter__"):
7677
# retrieve the handled type (Scout/Reply/etc.) from the return type
77-
assert isinstance(node.returns, ast.Subscript)
78+
if not isinstance(node.returns, ast.Subscript):
79+
continue
7880
if isinstance(node.returns.slice, ast.Subscript):
7981
# `Subscriber[Handler[Sample]]` case
8082
tp = node.returns.slice.slice
@@ -98,23 +100,26 @@ def visit_FunctionDef(self, node: ast.FunctionDef):
98100

99101

100102
def main():
101-
# remove __init__.pyi
102-
__INIT__.unlink()
103+
fnames = [__INIT__, EXT]
104+
for fname in fnames:
105+
# remove *.py
106+
fname.unlink()
103107
# rename stubs
104108
for entry in PACKAGE.glob("*.pyi"):
105109
entry.rename(PACKAGE / f"{entry.stem}.py")
106-
# read stub code
107-
with open(__INIT__) as f:
108-
stub: ast.Module = ast.parse(f.read())
109-
# replace _unstable
110-
for i, stmt in enumerate(stub.body):
111-
if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable":
112-
stub.body[i] = ast.parse(inspect.getsource(_unstable))
113-
# remove overload
114-
stub = RemoveOverload().visit(stub)
115-
# write modified code
116-
with open(__INIT__, "w") as f:
117-
f.write(ast.unparse(stub))
110+
for fname in fnames:
111+
# read stub code
112+
with open(fname) as f:
113+
stub: ast.Module = ast.parse(f.read())
114+
# replace _unstable
115+
for i, stmt in enumerate(stub.body):
116+
if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable":
117+
stub.body[i] = ast.parse(inspect.getsource(_unstable))
118+
# remove overload
119+
stub = RemoveOverload().visit(stub)
120+
# write modified code
121+
with open(fname, "w") as f:
122+
f.write(ast.unparse(stub))
118123

119124

120125
if __name__ == "__main__":

0 commit comments

Comments
 (0)