Skip to content

Allow plans with Concrete/non-Protocol parameters - #131

Closed
DiamondJoseph wants to merge 6 commits into
DiamondLightSource:mainfrom
DiamondJoseph:DAQ-4637
Closed

DiamondJoseph wants to merge 6 commits into
DiamondLightSource:mainfrom
DiamondJoseph:DAQ-4637

Conversation

@DiamondJoseph

Copy link
Copy Markdown
Contributor

Closes #117

Ware, Joseph (DLSLtd,RAL,LSCI) added 2 commits April 20, 2023 13:15
- Replace use of Protocols that extend HasName with HasName
- Use BaseModel.parse_obj instead of parse_obj_as
- Spelling, grammar
@codecov

codecov Bot commented Apr 20, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #131 (3745fc7) into main (90b4710) will increase coverage by 0.94%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
+ Coverage   74.52%   75.47%   +0.94%     
==========================================
  Files          37       37              
  Lines        1048     1060      +12     
==========================================
+ Hits          781      800      +19     
+ Misses        267      260       -7     
Impacted Files Coverage Δ
src/blueapi/core/context.py 86.30% <100.00%> (+9.25%) ⬆️
src/blueapi/utils/base_model.py 100.00% <100.00%> (ø)
src/blueapi/utils/serialization.py 87.50% <100.00%> (ø)
src/blueapi/worker/task.py 79.31% <100.00%> (+5.97%) ⬆️

... and 1 file with indirect coverage changes

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

@callumforrester callumforrester left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, one minor nitpick and you can probably remove the TODOs, as explained in comments.

Comment thread src/blueapi/core/context.py Resolved
Comment thread src/blueapi/core/context.py Resolved
Comment thread src/blueapi/core/context.py Resolved
@@ -0,0 +1,216 @@
from typing import Any, Dict, Generator, List, Mapping, Optional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this file is better off in tests/core since the code it is testing is in src/core

elif is_bluesky_compatible_device_type(field_type):
yield get_validator(plan_arg, field_type)

for k, v in Signature.from_callable(plan).parameters.items():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will fail if a plan has two arguments of the same type because utils.type_validator doesn't allow it. Example test case:

def concrete_plan_multi_arg(
    motor_1: DelegatingNamedMovable,
    motor_2: DelegatingNamedMovable,
) -> MsgGenerator:  # type: ignore
    ...

Presumably some sort of caching is needed

Comment on lines +176 to +183
def get_validators(
plan_arg: str, field_type: Type
) -> Iterable[TypeValidatorDefinition]:
if isinstance(field_type, _GenericAlias):
for arg in get_args(field_type):
yield from get_validators(plan_arg, arg)
elif is_bluesky_compatible_device_type(field_type):
yield get_validator(plan_arg, field_type)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It feels like there should be a way to write a generic version of this in utils.type_validator, but I think it's fine to consider that out of scope. Mind making a ticket for it?


for proto in BLUESKY_PROTOCOLS:
yield TypeValidatorDefinition(proto, get_device)
def plan_validators(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this function may grow and change and possibly be split up and recombined in all sorts of ways as we add more fancy plan parameter processing. Could we rename it to _plan_validators to discourage it's use outside this module for now?

@DiamondJoseph

Copy link
Copy Markdown
Contributor Author

Superceded by #154

@DiamondJoseph
DiamondJoseph deleted the DAQ-4637 branch May 12, 2023 13:21
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.

Pass concrete device types as plan parameters

2 participants