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-8557: test module generator output #4

Conversation

purplenicole730
Copy link
Collaborator

@purplenicole730 purplenicole730 commented Oct 2, 2024

Changes:

  • introduce two new flags with the module generate command: resource subtype and resource type
  • set the resource_name generated in the main file to be correct for input, SLAM, and MLModel
  • generate method stubs by using ast instead of inspect
  • remove sensors service from user prompt as it is deprecated
  • add board component to user prompt (possible due to the ast change!)
  • adjust imports if resource is mlmodel

NOTE:

  • The two new flags were for the purpose of the test, and any further work is out of scope of this ticket
  • Currently, motion and board 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.

Comment on lines 97 to 99
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)
Copy link
Collaborator Author

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.

Copy link

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

@purplenicole730 purplenicole730 marked this pull request as ready for review October 7, 2024 20:24
Copy link

@njooma njooma left a 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

IsPublic: false,
Namespace: "my-org",
Language: "python",
Resource: resourceSubtype + resourceType,
Copy link

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?

Comment on lines 97 to 99
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)
Copy link

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

Comment on lines 3 to 5
{{ if eq .ResourceSubtype "mlmodel" }}
viam-sdk[mlmodel]
{{ end }}
Copy link

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:
Copy link

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?

Copy link
Collaborator Author

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 *.

Copy link
Collaborator Author

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

var err error
resourceSubtype := cCtx.String(moduleFlagResourceSubtype)
resourceType := cCtx.String(moduleFlagResourceType)
if resourceSubtype != "" {
Copy link

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

Comment on lines 81 to 82
resourceSubtype := cCtx.String(moduleFlagResourceSubtype)
resourceType := cCtx.String(moduleFlagResourceType)
Copy link

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)

@njooma
Copy link

njooma commented Oct 8, 2024

Also, board doesn't quite work -- board requires the implementation of additional abstract classes (Board.Analog, Board.GPIOPin, Board.DigitalInterrupt). I would remove board for now, and we can add it in another time

@purplenicole730 purplenicole730 requested a review from njooma October 8, 2024 18:33
@purplenicole730 purplenicole730 merged commit 6ff8ea8 into gloriacai01:module-generation-cli Oct 8, 2024
@purplenicole730 purplenicole730 deleted the RSDK-8557-test-module-generator-output branch October 8, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants