From 3d46efad0aee2b26ecd0a94133663077fa96946b Mon Sep 17 00:00:00 2001 From: Callum Forrester Date: Mon, 21 Oct 2024 11:23:19 +0100 Subject: [PATCH] Remove references to inject --- docs/explanations/lifecycle.md | 16 +++++++--------- docs/how-to/write-plans.md | 20 ++++---------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/docs/explanations/lifecycle.md b/docs/explanations/lifecycle.md index d11d607f7..99db5d8cb 100644 --- a/docs/explanations/lifecycle.md +++ b/docs/explanations/lifecycle.md @@ -4,16 +4,16 @@ The following demonstrates exactly what the code does with a plan through its li of being written, loaded and run. Take the following plan. ```python +import bluesky.plans as bp + from typing import Any, List, Mapping, Optional, Union -import bluesky.plans as bp from blueapi.core import MsgGenerator -from dls_bluesky_core.core import inject from bluesky.protocols import Readable - +from dodal.beamlines import my_beamline def count( - detectors: List[Readable] = [inject("det")], # default valid for Blueapi only + detectors: List[Readable] = [my_beamline.det(connect_immediately=False)], num: int = 1, delay: Optional[Union[float, List[float]]] = None, metadata: Optional[Mapping[str, Any]] = None, @@ -56,9 +56,10 @@ like this: ```python from pydantic import BaseModel +from dodal.beamlines import my_beamline class CountParameters(BaseModel): - detectors: List[Readable] = [inject("det")] + detectors: List[Readable] = [my_beamline.det(connect_immediately=False)] num: int = 1 delay: Optional[Union[float, List[float]]] = None metadata: Optional[Mapping[str, Any]] = None @@ -68,10 +69,7 @@ class CountParameters(BaseModel): validate_all = True ``` -This is for illustrative purposes only, this code is not actually generated, but an object -resembling this class is constructed in memory. -The default arguments will be validated by the context to inject the "det" device when the -plan is run. The existence of the "det" default device is not checked until this time. The model is also stored in the context. +This is for illustrative purposes only, this code is not actually generated, but an object resembling this class is constructed in memory. The default arguments will be validated by the context when the plan is run. `my_beamline.det(connect_immediately=False)` evaluates to a lazily created singleton device. The model is also stored in the context. ## Startup diff --git a/docs/how-to/write-plans.md b/docs/how-to/write-plans.md index 90c66a27e..48a20e0f7 100644 --- a/docs/how-to/write-plans.md +++ b/docs/how-to/write-plans.md @@ -32,21 +32,9 @@ The type annotations (e.g. `: str`, `: int`, `-> MsgGenerator`) are required as **Input annotations should be as broad as possible**, the least specific implementation that is sufficient to accomplish the requirements of the plan. For example, if a plan is written to drive a specific motor (`MyMotor`), but only uses the general methods on the [`Movable` protocol](https://blueskyproject.io/bluesky/main/hardware.html#bluesky.protocols.Movable), it should take `Movable` as a parameter annotation rather than `MyMotor`. -## Injecting defaults +## Injecting Devices -Some plans are created for specific sets of devices, or will almost always be used with the same devices, it is useful to be able to specify defaults. Dodal defines device factory functions, but these cannot be injected as default arguments to plans. - -Dodal defines an `inject` function which allows defaulting devices, so long as there is a device of that name in the context which conforms to the type annotation. - -```python -from dodal.common import inject - -def touch_synchrotron(sync: Synchrotron = inject("synchrotron")) -> MsgGenerator: - # There is only one Synchrotron device, so we know which one it will always be. - # If there is no device named "synchrotron" in the blueapi context, it will except. - sync.specific_function() - yield from {} -``` +Some plans are created for specific sets of devices, or will almost always be used with the same devices, it is useful to be able to specify defaults. [Dodal makes this easy with its factory functions](https://diamondlightsource.github.io/dodal/main/how-to/include-devices-in-plans.html). ## Injecting Metadata @@ -66,8 +54,8 @@ Blueapi exposes the docstrings of plans to clients, along with the parameter typ ```python def temp_pressure_snapshot( detectors: List[Readable], - temperature: Movable = inject("sample_temperature"), - pressure: Movable = inject("sample_pressure"), + temperature: Movable = sample_temperature(), + pressure: Movable = sample_pressure(), target_temperature: float = 273.0, target_pressure: float = 10**5, metadata: Optional[Mapping[str, Any]] = None,