From afaf658dda9479c9921e67ee1176df5c8dea343e Mon Sep 17 00:00:00 2001 From: Keith Ralphs Date: Wed, 10 Jul 2024 08:10:56 +0000 Subject: [PATCH 1/2] Convert Lists to Sets --- src/dls_bluesky_core/plans/scanspec.py | 8 ++++---- src/dls_bluesky_core/plans/wrapped.py | 17 ++++++++--------- tests/plans/test_scanspec_metadata.py | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/dls_bluesky_core/plans/scanspec.py b/src/dls_bluesky_core/plans/scanspec.py index 50ae0a1..2fbfcf2 100644 --- a/src/dls_bluesky_core/plans/scanspec.py +++ b/src/dls_bluesky_core/plans/scanspec.py @@ -1,6 +1,6 @@ import operator from functools import reduce -from typing import Any, List, Mapping, Optional +from typing import Any, Mapping, Optional import bluesky.plans as bp from bluesky.protocols import Movable, Readable @@ -17,7 +17,7 @@ def scan( - detectors: List[Readable], + detectors: set[Readable], axes_to_move: Mapping[str, Movable], spec: Spec[str], metadata: Optional[Mapping[str, Any]] = None, @@ -26,7 +26,7 @@ def scan( Scan wrapping `bp.scan_nd` Args: - detectors: List of readable devices, will take a reading at + detectors: Set of readable devices, will take a reading at each point axes_to_move: All axes involved in this scan, names and objects @@ -44,7 +44,7 @@ def scan( _md = { "plan_args": { - "detectors": list(map(repr, detectors)), + "detectors": set(map(repr, detectors)), "axes_to_move": {k: repr(v) for k, v in axes_to_move.items()}, "spec": repr(spec), }, diff --git a/src/dls_bluesky_core/plans/wrapped.py b/src/dls_bluesky_core/plans/wrapped.py index 5d914fd..041880b 100644 --- a/src/dls_bluesky_core/plans/wrapped.py +++ b/src/dls_bluesky_core/plans/wrapped.py @@ -11,7 +11,7 @@ def count( - detectors: List[Readable], + detectors: set[Readable], num: int = 1, delay: Optional[Union[float, List[float]]] = None, metadata: Optional[Mapping[str, Any]] = None, @@ -20,7 +20,7 @@ def count( Take `n` readings from a device Args: - detectors (List[Readable]): Readable devices to read + detectors (Set[Readable]): Readable devices to read num (int, optional): Number of readings to take. Defaults to 1. delay (Optional[Union[float, List[float]]], optional): Delay between readings. Defaults to None. @@ -34,13 +34,12 @@ def count( Yields: Iterator[MsgGenerator]: _description_ """ - plan_args = ( - { # If bp.count added delay to plan_args, we could remove all md handling - "detectors": list(map(repr, detectors)), - "num": num, - "delay": delay, - } - ) + plan_args = { + # If bp.count added delay to plan_args, we could remove all md handling + "detectors": set(map(repr, detectors)), + "num": num, + "delay": delay, + } _md = { "plan_args": plan_args, diff --git a/tests/plans/test_scanspec_metadata.py b/tests/plans/test_scanspec_metadata.py index 9d502e5..3d14dae 100644 --- a/tests/plans/test_scanspec_metadata.py +++ b/tests/plans/test_scanspec_metadata.py @@ -57,7 +57,7 @@ def test_metadata_of_simple_spec(run_engine, x, loop): plan_args = start_document["plan_args"] assert len(plan_args) == 3 - assert plan_args["detectors"] == [repr(det)] + assert plan_args["detectors"] == {repr(det)} assert plan_args["spec"] == repr(spec) assert plan_args["axes_to_move"] == { x.name: repr(x), @@ -89,7 +89,7 @@ def test_metadata_of_spiral_spec(run_engine, x, y, loop): plan_args = start_document["plan_args"] assert len(plan_args) == 3 - assert plan_args["detectors"] == [repr(det)] + assert plan_args["detectors"] == {repr(det)} assert plan_args["spec"] == repr(spec) assert plan_args["axes_to_move"] == {x.name: repr(x), y.name: repr(y)} From 79cb84d07f236284425ee0d5825af4ee83bba518 Mon Sep 17 00:00:00 2001 From: Keith Ralphs Date: Wed, 10 Jul 2024 09:53:27 +0000 Subject: [PATCH 2/2] Remove unnecessary code affecting coverage --- src/dls_bluesky_core/plans/wrapped.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/dls_bluesky_core/plans/wrapped.py b/src/dls_bluesky_core/plans/wrapped.py index 041880b..14d2b09 100644 --- a/src/dls_bluesky_core/plans/wrapped.py +++ b/src/dls_bluesky_core/plans/wrapped.py @@ -34,16 +34,5 @@ def count( Yields: Iterator[MsgGenerator]: _description_ """ - plan_args = { - # If bp.count added delay to plan_args, we could remove all md handling - "detectors": set(map(repr, detectors)), - "num": num, - "delay": delay, - } - - _md = { - "plan_args": plan_args, - **(metadata or {}), - } - - yield from bp.count(detectors, num, delay=delay, md=_md) + + yield from bp.count(detectors, num, delay=delay, md=metadata or {})