Skip to content

Commit 2c20e8d

Browse files
RSDK-9778: add resource base stubs to python modules (viamrobotics#4742)
1 parent 93eea2e commit 2c20e8d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cli/module_generate/scripts/generate_stubs.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import sys
55
from importlib import import_module
6-
from typing import List, Set
6+
from typing import List, Set, Union
77

88

99
def return_attribute(value: str, attr: str) -> ast.Attribute:
@@ -155,6 +155,25 @@ def main(
155155
)
156156
abstract_methods.append(indented_code)
157157

158+
type_module = import_module(f"viam.{resource_type}s.{resource_type}_base")
159+
with open(type_module.__file__, "r") as f:
160+
tree = ast.parse(f.read())
161+
for stmt in tree.body:
162+
if isinstance(stmt, ast.ClassDef):
163+
for cstmt in stmt.body:
164+
if isinstance(cstmt, ast.AsyncFunctionDef):
165+
replace_async_func("", cstmt, [])
166+
indented_code = '\n'.join(
167+
[' ' + line for line in ast.unparse(cstmt).splitlines()]
168+
)
169+
abstract_methods.append(indented_code)
170+
if cstmt.name == "do_command":
171+
imports.append("from typing import Optional")
172+
imports.append("from viam.utils import ValueTypes")
173+
elif cstmt.name == "get_geometries":
174+
imports.append("from typing import List, Optional")
175+
imports.append("from viam.proto.common import Geometry")
176+
158177
model_name_pascal = "".join(
159178
[word.capitalize() for word in slugify(model_name).split("-")]
160179
)

0 commit comments

Comments
 (0)