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

Create ControllerAPI class to decouple transport from Controller #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GDYendell
Copy link
Contributor

@GDYendell GDYendell commented Nov 20, 2024

This changes a few key parts of the internal logic to make the static typing more robust and to improve the driver API.

It is now possible to dynamically create Methods as well as Attributes. This is shown in the new test here where a Command is added to a Controller during initialise.

The new Command, Put and Scan methods enable decoupling the Controller from the transport layer via a new ControllerAPI class, which replaces and extends the old SingleMapping class. The differences being:

  • ControllerAPI doesn't need a reference to the Controller - it is entirely self contained because the methods are dynamically bound to the controller instance and can be called outside the context of the class.
  • ControllerAPI maintains the tree structure from the Controllers where SingleMappingflattened it

Summary of changes:

  • Controller.get_controller_mappings -> ControllerAPI.walk_api
  • SingleMapping.{attributes,command_methods,put_methods,scan_methods} -> ControllerAPI.{attributes,command_methods,put_methods,scan_methods}
  • SingleMapping.Controller.path -> ControllerAPI.path
  • {Command,Put,Scan}.fn is now callable directly. Don't do MethodType(method, controller) or getattr(controller, method.__name__)().
  • for Controller in SingleMapping.Controller.get_sub_controllers() -> for ControllerAPI in ControllerAPI.sub_apis()

Fixes #74
Fixes #60
Fixes #93
Fixes #62

@GDYendell
Copy link
Contributor Author

GDYendell commented Jan 23, 2025

  • Update Command and BoundCommand to UnboundCommand and Command.

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 96.70782% with 8 lines in your changes missing coverage. Please review.

Project coverage is 89.00%. Comparing base (88f80a2) to head (973d2bf).

Files with missing lines Patch % Lines
src/fastcs/backend.py 91.30% 2 Missing ⚠️
src/fastcs/transport/epics/adapter.py 50.00% 2 Missing ⚠️
src/fastcs/controller_api.py 97.29% 1 Missing ⚠️
src/fastcs/transport/epics/docs.py 66.66% 1 Missing ⚠️
src/fastcs/transport/epics/gui.py 88.88% 1 Missing ⚠️
src/fastcs/wrappers.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   87.84%   89.00%   +1.16%     
==========================================
  Files          33       34       +1     
  Lines        1456     1519      +63     
==========================================
+ Hits         1279     1352      +73     
+ Misses        177      167      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GDYendell GDYendell force-pushed the dynamic-methods branch 3 times, most recently from 07d6568 to 31e8269 Compare March 4, 2025 13:28
@GDYendell GDYendell requested review from marcelldls, evalott100 and jsouter and removed request for marcelldls and evalott100 March 4, 2025 13:43
@GDYendell GDYendell marked this pull request as ready for review March 4, 2025 13:43
@GDYendell GDYendell mentioned this pull request Mar 4, 2025
@GDYendell GDYendell changed the title Dynamic methods Create ControllerAPI class to decouple transport from Controller Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Next Sprint
1 participant