Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-9778: add resource base stubs to python modules #4742

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion cli/module_generate/scripts/generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import sys
from importlib import import_module
from typing import List, Set
from typing import List, Set, Union


def return_attribute(value: str, attr: str) -> ast.Attribute:
Expand Down Expand Up @@ -155,6 +155,25 @@ def main(
)
abstract_methods.append(indented_code)

type_module = import_module(f"viam.{resource_type}s.{resource_type}_base")
with open(type_module.__file__, "r") as f:
tree = ast.parse(f.read())
for stmt in tree.body:
if isinstance(stmt, ast.ClassDef):
for cstmt in stmt.body:
if isinstance(cstmt, ast.AsyncFunctionDef):
replace_async_func("", cstmt, [])
indented_code = '\n'.join(
[' ' + line for line in ast.unparse(cstmt).splitlines()]
)
abstract_methods.append(indented_code)
if cstmt.name == "do_command":
imports.append("from typing import Optional")
imports.append("from viam.utils import ValueTypes")
elif cstmt.name == "get_geometries":
imports.append("from typing import List, Optional")
imports.append("from viam.proto.common import Geometry")

model_name_pascal = "".join(
[word.capitalize() for word in slugify(model_name).split("-")]
)
Expand Down
Loading