Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/how-to/add-plans-and-devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To add plans, you would add the following into your configuration file:
```


Devices are added similarly, using `dodal` as the `kind`, like so:
Devices are added similarly, using `deviceManager` as the `kind`, like so:
```{literalinclude} ../../tests/unit_tests/valid_example_config/plans_and_devices.yaml
:language: yaml
```
Expand Down
58 changes: 0 additions & 58 deletions helm/blueapi/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,56 +100,6 @@
"type": "object",
"$id": "DeviceManagerSource"
},
"DeviceSource": {
"additionalProperties": false,
"properties": {
"module": {
"description": "Module to be imported",
"title": "Module",
"type": "string"
},
"kind": {
"const": "deviceFunctions",
"default": "deviceFunctions",
"title": "Kind",
"type": "string"
}
},
"required": [
"module"
],
"title": "DeviceSource",
"type": "object",
"$id": "DeviceSource"
},
"DodalSource": {
"additionalProperties": false,
"properties": {
"module": {
"description": "Module to be imported",
"title": "Module",
"type": "string"
},
"kind": {
"const": "dodal",
"default": "dodal",
"title": "Kind",
"type": "string"
},
"mock": {
"default": false,
"description": "If true, ophyd_async device connections are mocked",
"title": "Mock",
"type": "boolean"
}
},
"required": [
"module"
],
"title": "DodalSource",
"type": "object",
"$id": "DodalSource"
},
"EnvironmentConfig": {
"additionalProperties": false,
"description": "Config for the RunEngine environment",
Expand All @@ -168,9 +118,7 @@
"items": {
"discriminator": {
"mapping": {
"deviceFunctions": "DeviceSource",
"deviceManager": "DeviceManagerSource",
"dodal": "DodalSource",
"planFunctions": "PlanSource"
},
"propertyName": "kind"
Expand All @@ -179,12 +127,6 @@
{
"$ref": "PlanSource"
},
{
"$ref": "DeviceSource"
},
{
"$ref": "DodalSource"
},
{
"$ref": "DeviceManagerSource"
}
Expand Down
54 changes: 0 additions & 54 deletions helm/blueapi/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,54 +533,6 @@
},
"additionalProperties": false
},
"DeviceSource": {
"$id": "DeviceSource",
"title": "DeviceSource",
"type": "object",
"required": [
"module"
],
"properties": {
"kind": {
"title": "Kind",
"default": "deviceFunctions",
"const": "deviceFunctions"
},
"module": {
"title": "Module",
"description": "Module to be imported",
"type": "string"
}
},
"additionalProperties": false
},
"DodalSource": {
"$id": "DodalSource",
"title": "DodalSource",
"type": "object",
"required": [
"module"
],
"properties": {
"kind": {
"title": "Kind",
"default": "dodal",
"const": "dodal"
},
"mock": {
"title": "Mock",
"description": "If true, ophyd_async device connections are mocked",
"default": false,
"type": "boolean"
},
"module": {
"title": "Module",
"description": "Module to be imported",
"type": "string"
}
},
"additionalProperties": false
},
"EnvironmentConfig": {
"$id": "EnvironmentConfig",
"title": "EnvironmentConfig",
Expand Down Expand Up @@ -618,12 +570,6 @@
{
"$ref": "PlanSource"
},
{
"$ref": "DeviceSource"
},
{
"$ref": "DodalSource"
},
{
"$ref": "DeviceManagerSource"
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies = [
"fastapi>=0.112.0",
"uvicorn",
"requests",
"dls-dodal>=1.69.0",
"super-state-machine", # https://github.com/DiamondLightSource/blueapi/issues/553
"GitPython",
"event-model==1.23.1", # https://github.com/DiamondLightSource/blueapi/issues/684
Expand All @@ -47,6 +46,7 @@ requires-python = ">=3.11"
dev = [
"ophyd_async[sim]",
"copier",
"dls-dodal>=1.69.0",
"myst-parser",
"prek",
"pydata-sphinx-theme>=0.15.4",
Expand Down
21 changes: 4 additions & 17 deletions src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def _expand_env(loader: yaml.Loader, node: yaml.ScalarNode) -> str:

class SourceKind(StrEnum):
PLAN_FUNCTIONS = "planFunctions"
DEVICE_FUNCTIONS = "deviceFunctions"
DODAL = "dodal"
DEVICE_MANAGER = "deviceManager"


Expand All @@ -63,19 +61,6 @@ class PlanSource(Source):
)


class DeviceSource(Source):
kind: Literal[SourceKind.DEVICE_FUNCTIONS] = Field(
SourceKind.DEVICE_FUNCTIONS, init=False
)


class DodalSource(Source):
kind: Literal[SourceKind.DODAL] = Field(SourceKind.DODAL, init=False)
mock: bool = Field(
description="If true, ophyd_async device connections are mocked", default=False
)


class DeviceManagerSource(Source):
kind: Literal[SourceKind.DEVICE_MANAGER] = Field(
SourceKind.DEVICE_MANAGER, init=False
Expand All @@ -84,7 +69,9 @@ class DeviceManagerSource(Source):
description="If true, ophyd_async device connections are mocked", default=False
)
name: str = Field(
default="devices", description="Name of the device manager in the module"
default="devices",
description="Name of the device manager in the module",
exclude_if=lambda v: v == "devices",
)


Expand Down Expand Up @@ -150,7 +137,7 @@ class EnvironmentConfig(BlueapiBaseModel):

sources: list[
Annotated[
PlanSource | DeviceSource | DodalSource | DeviceManagerSource,
PlanSource | DeviceManagerSource,
Field(discriminator="kind"),
]
] = [
Expand Down
3 changes: 1 addition & 2 deletions src/blueapi/core/bluesky_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
WritesExternalAssets,
)
from bluesky.utils import Msg, MsgGenerator
from dodal.common import PlanGenerator
from ophyd_async.core import Device as AsyncDevice
from pydantic import BaseModel, Field

from blueapi.utils import BlueapiBaseModel

PlanWrapper = Callable[[MsgGenerator], MsgGenerator]
PlanGenerator = Callable[..., MsgGenerator]

#: An object that encapsulates the device to do useful things to produce
# data (e.g. move and read)
Expand Down
66 changes: 0 additions & 66 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

from bluesky.protocols import HasName
from bluesky.run_engine import RunEngine
from dodal.common.beamlines.beamline_utils import get_path_provider, set_path_provider
from dodal.utils import AnyDevice, make_all_devices
from ophyd_async.core import NotConnectedError, PathProvider
from pydantic import (
BaseModel,
Expand All @@ -26,8 +24,6 @@
from blueapi.config import (
ApplicationConfig,
DeviceManagerSource,
DeviceSource,
DodalSource,
EnvironmentConfig,
PlanSource,
ServiceAccount,
Expand Down Expand Up @@ -151,8 +147,6 @@ def __post_init__(self, configuration: ApplicationConfig | None):
)

path_provider = StartDocumentPathProvider()
# TODO: Remove this when device manager is rolled out
set_path_provider(path_provider)

self.run_engine.subscribe(path_provider.run_start, "start")
self.run_engine.subscribe(path_provider.run_stop, "stop")
Expand All @@ -173,13 +167,6 @@ async def _update_scan_num(md: dict[str, Any]) -> int:
self.run_engine.scan_id_source = _update_scan_num

self.with_config(configuration.env)
if configuration.numtracker and not isinstance(
get_path_provider(), StartDocumentPathProvider
):
raise InvalidConfigError(
"Numtracker has been configured but a path provider was imported with "
"the devices. Remove this path provider to use numtracker."
)

if (tiled_conf := configuration.tiled) is not None and tiled_conf.enabled:
if configuration.env.metadata is None:
Expand Down Expand Up @@ -232,22 +219,6 @@ def with_config(self, config: EnvironmentConfig) -> None:
case PlanSource():
LOGGER.info("Including plans from %s", source.module)
self.with_plan_module(mod)
case DeviceSource():
LOGGER.info("Including devices from %s", source.module)
LOGGER.warning(
"'devices' environment kind is deprecated - please convert "
"configuration to use deviceManager"
)
self.with_device_module(mod)
case DodalSource(mock=mock):
LOGGER.info(
"Including devices from 'dodal' source %s", source.module
)
LOGGER.warning(
"'dodal' environment kind is deprecated - please convert "
"configuration to use deviceManager"
)
self.with_dodal_module(mod, mock=mock)
case DeviceManagerSource(mock=mock, name=name):
LOGGER.info(
"Including devices from 'deviceManager' source %s:%s",
Expand Down Expand Up @@ -333,43 +304,6 @@ def with_device_manager(self, manager: DeviceManager, mock: bool = False):
**build_result.connection_errors,
}

def with_device_module(self, module: ModuleType) -> None:
self.with_dodal_module(module)

def with_dodal_module(
self, module: ModuleType, **kwargs
) -> tuple[dict[str, AnyDevice], dict[str, Exception]]:
"""
Discover all device factories in the specified module,
construct devices by invoking them and register them with the device context,
Then attempt to connect to all the devices.

Args:
module: The python module to inspect for factories
kwargs: keyword arguments that will be passed to make_all_devices() and
to connect_devices() for construction and connection respectively
Returns:
A tuple containing a map of device name to devices, and a map of
device name to any exceptions encountered.
"""
devices, exceptions = make_all_devices(module, **kwargs)

exceptions |= utils.connect_devices(self.run_engine, module, devices, **kwargs)

for device in devices.values():
self.register_device(device)

# If exceptions have occurred, we log them but we do not make blueapi
# fall over
if len(exceptions) > 0:
LOGGER.warning(
f"{len(exceptions)} exceptions occurred while instantiating devices"
)
LOGGER.exception(NotConnectedError(exceptions))
elif not devices:
LOGGER.warning("No devices were loaded from dodal module %s", module)
return devices, exceptions

def register_plan(self, plan: PlanGenerator) -> PlanGenerator:
"""
Register the argument as a plan in the context. Can be used as a decorator e.g.
Expand Down
3 changes: 1 addition & 2 deletions src/blueapi/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import ParamSpec, TypeVar

from .base_model import BlueapiBaseModel, BlueapiModelConfig, BlueapiPlanModelConfig
from .connect_devices import connect_devices, report_successful_devices
from .connect_devices import report_successful_devices
from .file_permissions import get_owner_gid, is_sgid_set
from .invalid_config_error import InvalidConfigError
from .modules import is_function_sourced_from_module, load_module_all
Expand All @@ -20,7 +20,6 @@
"BlueapiPlanModelConfig",
"InvalidConfigError",
"NumtrackerClient",
"connect_devices",
"report_successful_devices",
"is_sgid_set",
"get_owner_gid",
Expand Down
Loading
Loading