Skip to content

Commit

Permalink
Remove DirectoryProvider and pre-processor handling to Dodal (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondJoseph authored Apr 29, 2024
1 parent c3d1ccd commit 0a634dc
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 697 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"uvicorn",
"requests",
"dls-bluesky-core", #requires ophyd-async
"dls-dodal<1.21",
"dls-dodal",
]
dynamic = ["version"]
license.file = "LICENSE"
Expand Down
7 changes: 0 additions & 7 deletions src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ class StompConfig(BaseModel):
auth: BasicAuthentication | None = None


class DataWritingConfig(BlueapiBaseModel):
visit_service_url: str | None = None # e.g. "http://localhost:8088/api"
visit_directory: Path = Path("/tmp/0-0")
group_name: str = "example"


class WorkerEventConfig(BlueapiBaseModel):
"""
Config for event broadcasting via the message bus
Expand All @@ -78,7 +72,6 @@ class EnvironmentConfig(BlueapiBaseModel):
Source(kind=SourceKind.PLAN_FUNCTIONS, module="dls_bluesky_core.plans"),
Source(kind=SourceKind.PLAN_FUNCTIONS, module="dls_bluesky_core.stubs"),
]
data_writing: DataWritingConfig = Field(default_factory=DataWritingConfig)
events: WorkerEventConfig = Field(default_factory=WorkerEventConfig)


Expand Down
14 changes: 1 addition & 13 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import functools
import logging
from collections.abc import Callable, Sequence
from collections.abc import Callable
from dataclasses import dataclass, field
from importlib import import_module
from inspect import Parameter, signature
Expand All @@ -22,10 +21,8 @@
BLUESKY_PROTOCOLS,
Device,
HasName,
MsgGenerator,
Plan,
PlanGenerator,
PlanWrapper,
is_bluesky_compatible_device,
is_bluesky_plan_generator,
)
Expand All @@ -45,22 +42,13 @@ class BlueskyContext:
run_engine: RunEngine = field(
default_factory=lambda: RunEngine(context_managers=[])
)
plan_wrappers: Sequence[PlanWrapper] = field(default_factory=list)
plans: dict[str, Plan] = field(default_factory=dict)
devices: dict[str, Device] = field(default_factory=dict)
plan_functions: dict[str, PlanGenerator] = field(default_factory=dict)
sim: bool = field(default=False)

_reference_cache: dict[type, type] = field(default_factory=dict)

def wrap(self, plan: MsgGenerator) -> MsgGenerator:
wrapped_plan = functools.reduce(
lambda wrapped, next_wrapper: next_wrapper(wrapped),
self.plan_wrappers,
plan,
)
yield from wrapped_plan

def find_device(self, addr: str | list[str]) -> Device | None:
"""
Find a device in this context, allows for recursive search.
Expand Down
Empty file.
127 changes: 0 additions & 127 deletions src/blueapi/data_management/visit_directory_provider.py

This file was deleted.

41 changes: 0 additions & 41 deletions src/blueapi/preprocessors/attach_metadata.py

This file was deleted.

40 changes: 0 additions & 40 deletions src/blueapi/service/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
from blueapi.config import ApplicationConfig
from blueapi.core import BlueskyContext
from blueapi.core.event import EventStream
from blueapi.data_management.visit_directory_provider import (
LocalVisitServiceClient,
VisitDirectoryProvider,
VisitServiceClient,
VisitServiceClientBase,
)
from blueapi.messaging import StompMessagingTemplate
from blueapi.messaging.base import MessagingTemplate
from blueapi.preprocessors.attach_metadata import attach_metadata
from blueapi.service.handler_base import BlueskyHandler
from blueapi.service.model import DeviceModel, PlanModel, WorkerTask
from blueapi.worker.event import WorkerState
Expand Down Expand Up @@ -159,42 +152,9 @@ def setup_handler(
) -> None:
global HANDLER

provider = None
plan_wrappers = []
if config:
visit_service_client: VisitServiceClientBase
if config.env.data_writing.visit_service_url is not None:
visit_service_client = VisitServiceClient(
config.env.data_writing.visit_service_url
)
else:
visit_service_client = LocalVisitServiceClient()

provider = VisitDirectoryProvider(
data_group_name=config.env.data_writing.group_name,
data_directory=config.env.data_writing.visit_directory,
client=visit_service_client,
)

# Make all dodal devices created by the context use provider if they can
try:
from dodal.parameters.gda_directory_provider import (
set_directory_provider_singleton,
)

set_directory_provider_singleton(provider)
except ImportError:
logging.error(
"Unable to set directory provider for ophyd-async devices, "
"a newer version of dodal is required"
)

plan_wrappers.append(lambda plan: attach_metadata(plan, provider))

handler = Handler(
config,
context=BlueskyContext(
plan_wrappers=plan_wrappers,
sim=False,
),
)
Expand Down
4 changes: 1 addition & 3 deletions src/blueapi/worker/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def do_task(self, ctx: BlueskyContext) -> None:

func = ctx.plan_functions[self.name]
prepared_params = self.prepare_params(ctx)
plan_generator = func(**prepared_params.dict())
wrapped_plan_generator = ctx.wrap(plan_generator)
ctx.run_engine(wrapped_plan_generator)
ctx.run_engine(func(**prepared_params.dict()))


def _lookup_params(ctx: BlueskyContext, task: Task) -> BaseModel:
Expand Down
66 changes: 0 additions & 66 deletions tests/data_management/test_visit_directory_provider.py

This file was deleted.

Empty file removed tests/preprocessors/__init__.py
Empty file.
Loading

0 comments on commit 0a634dc

Please sign in to comment.