Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal configuration for inserting documents into Tiled #755

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ classifiers = [
]
description = "Lightweight bluesky-as-a-service wrapper application. Also usable as a library."
dependencies = [
"tiled",
"json_merge_patch",
"jsonpatch",
"pyarrow",
"bluesky>=1.13",
"ophyd",
"nslsii",
Expand Down Expand Up @@ -95,7 +99,8 @@ addopts = """
--ignore=src/blueapi/startup
"""
# https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings
filterwarnings = ["error", "ignore::DeprecationWarning"]
# Unignore UserWarning after Pydantic warning removed from bluesky/bluesky and release
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bluesky/bluesky#1867

  • a release of bluesky

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: Include issue link in a comment in the file

filterwarnings = ["error", "ignore::DeprecationWarning", "ignore::UserWarning"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to only ignore warnings from the tests in question? Otherwise we may end up removing this in a few months time only to find the tests blowing up in a bunch of other places?

# Doctest python code in docs, python code in src docstrings, test functions in tests
testpaths = "docs src tests"
asyncio_mode = "auto"
Expand Down
10 changes: 10 additions & 0 deletions src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class StompConfig(BaseModel):
auth: BasicAuthentication | None = None


class TiledConfig(BaseModel):
"""
Config for connecting to a tiled instance
"""

uri: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Can we use separate host and port fields to be consistent with the other config models?

api_key: str


class WorkerEventConfig(BlueapiBaseModel):
"""
Config for event broadcasting via the message bus
Expand Down Expand Up @@ -160,6 +169,7 @@ class ApplicationConfig(BlueapiBaseModel):
"""

stomp: StompConfig | None = None
tiled: TiledConfig | None = None
env: EnvironmentConfig = Field(default_factory=EnvironmentConfig)
logging: LoggingConfig = Field(default_factory=LoggingConfig)
api: RestConfig = Field(default_factory=RestConfig)
Expand Down
18 changes: 17 additions & 1 deletion src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from functools import cache
from typing import Any

from bluesky.callbacks.tiled_writer import TiledWriter
from bluesky_stomp.messaging import StompClient
from bluesky_stomp.models import Broker, DestinationBase, MessageTopic
from tiled.client import from_uri

from blueapi.config import ApplicationConfig, OIDCConfig, StompConfig
from blueapi.config import ApplicationConfig, OIDCConfig, StompConfig, TiledConfig
from blueapi.core.context import BlueskyContext
from blueapi.core.event import EventStream
from blueapi.service.model import DeviceModel, PlanModel, WorkerTask
Expand Down Expand Up @@ -48,6 +50,19 @@
return worker


@cache
def tiled_inserter():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should:

Suggested change
def tiled_inserter():
def tiled_inserter() -> TiledClient:

...or whatever it's called

tiled_config: TiledConfig | None = config().tiled
if tiled_config is not None:
client = from_uri(tiled_config.uri, api_key=tiled_config.api_key)

Check warning on line 57 in src/blueapi/service/interface.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/service/interface.py#L55-L57

Added lines #L55 - L57 were not covered by tests

ctx = context()
ctx.run_engine.subscribe(TiledWriter(client))
return client

Check warning on line 61 in src/blueapi/service/interface.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/service/interface.py#L59-L61

Added lines #L59 - L61 were not covered by tests
else:
return None

Check warning on line 63 in src/blueapi/service/interface.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/service/interface.py#L63

Added line #L63 was not covered by tests


@cache
def stomp_client() -> StompClient | None:
stomp_config: StompConfig | None = config().stomp
Expand Down Expand Up @@ -86,6 +101,7 @@
logging.basicConfig(format="%(asctime)s - %(message)s", level=config.logging.level)
worker()
stomp_client()
tiled_inserter()

Check warning on line 104 in src/blueapi/service/interface.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/service/interface.py#L104

Added line #L104 was not covered by tests


def teardown() -> None:
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def temp_yaml_config_file(
"logging": {"level": "INFO"},
"api": {"host": "0.0.0.0", "port": 8000, "protocol": "http"},
"scratch": None,
"tiled": None,
},
],
indirect=True,
Expand Down Expand Up @@ -285,6 +286,7 @@ def test_config_yaml_parsed(temp_yaml_config_file):
}
],
},
"tiled": None,
},
{
"stomp": {
Expand Down Expand Up @@ -318,6 +320,7 @@ def test_config_yaml_parsed(temp_yaml_config_file):
}
],
},
"tiled": None,
},
],
indirect=True,
Expand Down
Loading