-
Notifications
You must be signed in to change notification settings - Fork 0
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-8557: test module generator output #4
RSDK-8557: test module generator output #4
Conversation
if isinstance(arg.annotation.slice, ast.Subscript): | ||
if isinstance(arg.annotation.slice.slice, ast.Name) and arg.annotation.slice.slice.id in nodes: | ||
arg.annotation.slice.slice = return_attribute(resource_name, arg.annotation.slice.slice.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some instances where we have Subscript
's in Subscript
's (i.e. Dict[str, List[str]]
). Since that exists in our Python SDK, I wanted to protect us if it ever happened with a custom class. There is however, the unfortunate truth that if someone decides to put a custom class nested a third time, it will fail. But thankfully this test will fail if that happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good use case for recursion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is dope. This is a good use case for recursion to do infinite subscript depth, but i think we can write a ticket for that and do it later. better to get it out now and optimize some other time
cli/module_generate.go
Outdated
IsPublic: false, | ||
Namespace: "my-org", | ||
Language: "python", | ||
Resource: resourceSubtype + resourceType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it matters since it's unused, but doesn't this require a space
in between?
if isinstance(arg.annotation.slice, ast.Subscript): | ||
if isinstance(arg.annotation.slice.slice, ast.Name) and arg.annotation.slice.slice.id in nodes: | ||
arg.annotation.slice.slice = return_attribute(resource_name, arg.annotation.slice.slice.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good use case for recursion
{{ if eq .ResourceSubtype "mlmodel" }} | ||
viam-sdk[mlmodel] | ||
{{ end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an if/else: either we do viam-sdk
or we do viam-sdk[mlmodel]
, but i don't think we need both?
resource = getattr(module, resource_name) | ||
methods = inspect.getmembers(resource, predicate=inspect.isfunction) | ||
|
||
imports = [] | ||
abstract_methods = [] | ||
for name, method in methods: | ||
for _, method in methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this? Can we get all the imports we need from the AST?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is something I was wondering and wanted to take out.
AST doesn't seem to show where the types are from. So for example, Vector3
and GeoPoint
don't tell us if it's from _pb2
module or not. But I'm not sure how useful this is in the first place because from the limited testing I've done, I saw that these types are usually exported in the __init__.py
file so it would be included when we from <component> import *
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I'll take it out and see what happens
cli/module_generate.go
Outdated
var err error | ||
resourceSubtype := cCtx.String(moduleFlagResourceSubtype) | ||
resourceType := cCtx.String(moduleFlagResourceType) | ||
if resourceSubtype != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check that both resourceType and resourceSubtype are available
cli/module_generate.go
Outdated
resourceSubtype := cCtx.String(moduleFlagResourceSubtype) | ||
resourceType := cCtx.String(moduleFlagResourceType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] extremely minor but could you swap these two lines? i like it so that the broader category (type) comes above the detailed category (subtype)
Also, |
Changes:
module generate
command: resource subtype and resource typeinput
,SLAM
, andMLModel
ast
instead ofinspect
sensors service
from user prompt as it is deprecatedboard component
to user prompt (possible due to theast
change!)mlmodel
NOTE:
motion
andboard
fail in the github workflow. These were tested locally with the changes in this PR, and they work. The tests should pass automatically once the changes are in and the version is updated.