Skip to content

Commit

Permalink
fix some, indicate uncertain points
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Sep 11, 2024
1 parent 2b7946a commit 1bd5afb
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 143 deletions.
2 changes: 1 addition & 1 deletion docs/explanations/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ of being written, loaded and run. Take the following plan.
import bluesky.plans as bp
from blueapi.core import MsgGenerator
from dls_bluesky_core.core import inject
from dodal.common import inject
from bluesky.protocols import Readable
Expand Down
107 changes: 0 additions & 107 deletions errors.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from blueapi.client.rest import BlueskyRemoteControlError
from blueapi.config import (
ApplicationConfig,
BasicAuthentication,
ConfigLoader,
StompConfig,
)
Expand Down
2 changes: 1 addition & 1 deletion src/blueapi/core/bluesky_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Triggerable,
WritesExternalAssets,
)
from dls_bluesky_core.core import MsgGenerator, PlanGenerator
from dodal.common import MsgGenerator, PlanGenerator
from ophyd_async.core import Device as AsyncDevice
from pydantic import BaseModel, Field

Expand Down
4 changes: 2 additions & 2 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def my_plan(a: int, b: str):
model = create_model(
plan.__name__,
__config__=BlueapiPlanModelConfig,
**self._type_spec_for_function(plan),
**self._type_spec_for_function(plan), # type: ignore
)
self.plans[plan.__name__] = Plan(
name=plan.__name__, model=model, description=plan.__doc__
Expand Down Expand Up @@ -284,7 +284,7 @@ def _convert_type(self, typ: type | Any) -> type:
root = get_origin(typ)
if root == UnionType:
root = Union
return root[new_types] if root else typ
return root[new_types] # type: ignore
return typ


Expand Down
7 changes: 2 additions & 5 deletions src/blueapi/core/device_lookup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from typing import Any, TypeVar
from typing import Any

from .bluesky_types import Device, is_bluesky_compatible_device

#: Device obeying Bluesky protocols
D = TypeVar("D", bound=Device)


def find_component(obj: Any, addr: list[str]) -> D | None:
def find_component(obj: Any, addr: list[str]) -> Device | None:
"""
Best effort function to locate a child device, either in a dictionary of
devices or a device with child attributes.
Expand Down
8 changes: 5 additions & 3 deletions src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bluesky_stomp.messaging import MessagingTemplate
from bluesky_stomp.models import Broker, DestinationBase, MessageTopic

from blueapi.config import ApplicationConfig
from blueapi.config import ApplicationConfig, StompConfig
from blueapi.core.context import BlueskyContext
from blueapi.core.event import EventStream
from blueapi.service.model import DeviceModel, PlanModel, WorkerTask
Expand Down Expand Up @@ -50,11 +50,13 @@ def worker() -> TaskWorker:

@lru_cache
def messaging_template() -> MessagingTemplate | None:
stomp_config = config().stomp
stomp_config: StompConfig | None = config().stomp
if stomp_config is not None:
template = MessagingTemplate.for_broker(
broker=Broker(
host=stomp_config.host, port=stomp_config.port, auth=stomp_config.auth
host=stomp_config.host,
port=stomp_config.port,
auth=stomp_config.auth, # type: ignore
)
)

Expand Down
5 changes: 3 additions & 2 deletions src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ def submit_task(
task: Task = Body(..., example=example_task),
runner: WorkerDispatcher = Depends(_runner),
):
plan_model: PlanModel | None = None
"""Submit a task to the worker."""
plan_model = runner.run(interface.get_plan, task.name)
try:
plan_model = runner.run(interface.get_plan, task.name)
task_id: str = runner.run(interface.submit_task, task)
response.headers["Location"] = f"{request.url}/{task_id}"
return TaskResponse(task_id=task_id)
Expand All @@ -161,7 +162,7 @@ def submit_task(
)
error_detail_response = f"""
Input validation failed: {formatted_errors},
suppplied params {task.params},
supplied params {task.params},
do not match the expected params: {plan_model.parameter_schema}
"""
raise HTTPException(
Expand Down
4 changes: 2 additions & 2 deletions src/blueapi/service/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def _rpc(
**kwargs: Any,
) -> T:
mod = import_module(module_name)
func: Callable[P, T] = _validate_function(
func: Callable[..., T] = _validate_function(
mod.__dict__.get(function_name, None), function_name
)
) # type: ignore
value = func(*args, **kwargs)
return _valid_return(value, expected_type)

Expand Down
15 changes: 8 additions & 7 deletions src/blueapi/startup/example_plans.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import bluesky.plan_stubs as bps
from bluesky.plans import count
from bluesky.protocols import Movable, Readable
from dls_bluesky_core.core import inject
from dls_bluesky_core.plans import count
from dls_bluesky_core.stubs import move
from dodal.common import MsgGenerator, inject

from blueapi.core import MsgGenerator
TEMP: Movable = inject("sample_temperature")
PRESS: Movable = inject("sample_pressure")


def stp_snapshot(
detectors: list[Readable],
temperature: Movable = inject("sample_temperature"),
pressure: Movable = inject("sample_pressure"),
temperature: Movable = TEMP,
pressure: Movable = PRESS,
) -> MsgGenerator:
"""
Moves devices for pressure and temperature (defaults fetched from the context)
Expand All @@ -26,5 +27,5 @@ def stp_snapshot(
Yields:
Iterator[MsgGenerator]: Bluesky messages
"""
yield from move({temperature: 0, pressure: 10**5})
yield from bps.mv({temperature: 0, pressure: 10**5})
yield from count(detectors, 1)
1 change: 0 additions & 1 deletion src/blueapi/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
__all__ = [
"handle_all_exceptions",
"load_module_all",
"ConfigLoader",
"serialize",
"BlueapiBaseModel",
"BlueapiModelConfig",
Expand Down
1 change: 0 additions & 1 deletion src/blueapi/worker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
__all__ = [
"TaskWorker",
"Task",
"Worker",
"WorkerEvent",
"WorkerState",
"StatusView",
Expand Down
9 changes: 6 additions & 3 deletions src/blueapi/worker/task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def cancel_active_task(
# We only allow this method to be called if a Plan is active
raise TransitionError("Attempted to cancel while no active Task")
if failure:
self._ctx.run_engine.abort(reason)
default_reason = "Task failed for unknown reason"
self._ctx.run_engine.abort(reason or default_reason)
else:
self._ctx.run_engine.stop()
return self._current.task_id
Expand Down Expand Up @@ -181,8 +182,8 @@ def mark_task_as_started(event: WorkerEvent, _: str | None) -> None:
task_started.set()

LOGGER.info(f"Submitting: {trackable_task}")
sub = self.worker_events.subscribe(mark_task_as_started)
try:
sub = self.worker_events.subscribe(mark_task_as_started)
self._task_channel.put_nowait(trackable_task)
task_started.wait(timeout=5.0)
if not task_started.is_set():
Expand Down Expand Up @@ -262,7 +263,9 @@ def _cycle(self) -> None:
next_task: TrackableTask | KillSignal = self._task_channel.get()
if isinstance(next_task, TrackableTask):
LOGGER.info(f"Got new task: {next_task}")
self._current = next_task # Informing type checker that the task is not None
self._current = (
next_task # Informing type checker that the task is not None
)
self._current.is_pending = False
self._current.task.do_task(self._ctx)
elif isinstance(next_task, KillSignal):
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Based on https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option # noqa: E501
import pytest
from bluesky import RunEngine
from bluesky.run_engine import TransitionError
from bluesky.run_engine import RunEngine
from super_state_machine.errors import TransitionError


@pytest.fixture(scope="function")
Expand Down
Loading

0 comments on commit 1bd5afb

Please sign in to comment.