Skip to content

RSDK-7732 EasyResource mixin #643

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

Merged
merged 17 commits into from
Jun 14, 2024
Merged

RSDK-7732 EasyResource mixin #643

merged 17 commits into from
Jun 14, 2024

Conversation

abe-winter
Copy link
Member

@abe-winter abe-winter commented Jun 13, 2024

What changed

  • add EasyResource mixin class for shorter model classes
  • run_from_registry and run_with_models entrypoints in Module class
  • docstrings, tests, example

Why

Reduce friction to create new models + get started with our platform.

Checklist

  • resolve + remove todo(review) comments

@abe-winter abe-winter requested a review from a team as a code owner June 13, 2024 00:58
Copy link
Member

@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 awesome

won't call it directly.
"""
logger.debug('registering %s %s', cls.SUBTYPE, cls.MODEL)
# note: this would pass if EasyResource inherited ResourceBase, but that crashes in the mro() walk in ResourceManager.register.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment mean? What would "pass"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass pyright I mean (not tests)

the ResourceCreatorRegistration wants cls.new to return a ResourceBase

for a while I had ResourceBase as a base class for EasyResource, but it crashed in the mro walk here

could potentially tweak the types / stubs a bit to get this working without the pyright-ignore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha 👍

module = cls(args.socket_path, log_level=args.log_level)
for model in models:
# todo(review): the pyright ignore below is for ResourceBase.MODEL. Is this not a required field? Should I not rely on it?
module.add_model_from_registry(model.SUBTYPE, model.MODEL) # pyright: ignore [reportAttributeAccessIssue]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceBase does not have a MODEL field at all, since MODELs are for implementation of a ResourceBase, and ResourceBase is for creating the resource definition/interface. This would fail in the possible event that someone passes Arm as the param instead of MyModuleArm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would be useful to maybe do a hasattr here and fail if someone doesn't pass the correct type. And also add that disclaimer to the docstring

Copy link
Member Author

@abe-winter abe-winter Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added hasattr check w/ helpful error

I didn't expand docstring because when I started writing it I was saying 'the provided resources have to be complete + runnable' and it felt weird. but can add something if you think it's helpful

args = parse_module_args()
module = cls(args.socket_path, log_level=args.log_level)
for key in Registry.REGISTERED_RESOURCE_CREATORS().keys():
# todo(review): this would be cleaner if resource creator key became a tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, seems like it'd be easy but it is technically a breaking change, but I don't know anyone who would be using the Registry externally like that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-breaking middle ground: REGISTERED_RESOURCE_CREATORS() transforms the tuple key to a string key, have another getter that provides access to the tuple?

module = cls(args.socket_path, log_level=args.log_level)
for key in Registry.REGISTERED_RESOURCE_CREATORS().keys():
# todo(review): this would be cleaner if resource creator key became a tuple
module.add_model_from_registry(*key.split('/')) # pyright: ignore [reportArgumentType]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dislike the disable pyright here but also seems dumb to create a Subtype just to stringify it again in the next method call. No action needed, just writing it down

@abe-winter abe-winter requested a review from njooma June 13, 2024 21:32
@abe-winter abe-winter merged commit c2098a3 into main Jun 14, 2024
12 checks passed
@abe-winter abe-winter deleted the easy-resource branch June 14, 2024 15:35
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.

2 participants