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

Remove public fields of BlueskyContext and replace with methods #174

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

Conversation

callumforrester
Copy link
Collaborator

It seems more sustainable to use private fields and access them via methods. The device and plan dictionaries and run engine are now hidden behind methods.

@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #174 (a6646e7) into main (6557da5) will increase coverage by 0.05%.
The diff coverage is 86.84%.

❗ Current head a6646e7 differs from pull request most recent head b8761c8. Consider uploading reports for the commit b8761c8 to get more accurate results

@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   83.00%   83.06%   +0.05%     
==========================================
  Files          39       39              
  Lines        1024     1045      +21     
==========================================
+ Hits          850      868      +18     
- Misses        174      177       +3     
Impacted Files Coverage Δ
src/blueapi/core/bluesky_types.py 88.88% <ø> (ø)
src/blueapi/service/app.py 40.35% <0.00%> (ø)
src/blueapi/worker/task.py 96.87% <83.33%> (-3.13%) ⬇️
src/blueapi/core/context.py 94.39% <93.33%> (-1.07%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@tpoliaw tpoliaw left a comment

Choose a reason for hiding this comment

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

There are a few docs changes here not related to replacing fields with methods. Is it picky to suggest these are committed/merged as separate commits when the PR is merged?

src/blueapi/core/context.py Outdated Show resolved Hide resolved
src/blueapi/core/context.py Outdated Show resolved Hide resolved
def find_plan_metadata(self, name: str) -> Optional[Plan]:
return self._plans.get(name)

def all_devices(self) -> Iterable[Device]:
Copy link
Contributor

Choose a reason for hiding this comment

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

worth making these two properties as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or not having any properties... I'm always on the fence between the potential for confusion and the nice read-only-ness

func = ctx.plan_functions[self.name]
sanitized_params = _lookup_params(ctx, plan, self.params)
plan_generator = func(**sanitized_params.dict())
metadata = ctx.find_plan_metadata(self.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

If these two functions are only ever called together and both have to be present, it'd be clearer to have a single find_plan(name) -> Optional[(Plan, PlanFunc)]. Probably suggests plans and plan_functions should be merged into a single field in the context as well. Maybe a dict of name -> (Plan, func)?

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.

None yet

2 participants