Skip to content

Commit 4bbae78

Browse files
committed
Allow extra configuration components to be added by a key found in the murfey.config entry point and validate against the provided model
Also provide a convenience function for extracting the relevant part of the extended configuration from other packages if Murfey is installed
1 parent bcf52af commit 4bbae78

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ murfey = "murfey.client:run"
9595
"murfey.transfer" = "murfey.cli.transfer:run"
9696
[project.entry-points."murfey.auth.token_validation"]
9797
"password" = "murfey.server.api.auth:password_token_validation"
98+
[project.entry-points."murfey.config.extraction"]
99+
"murfey_machine" = "murfey.util.config:get_extended_machine_config"
98100
[project.entry-points."murfey.workflows"]
99101
"lif_to_stack" = "murfey.workflows.lif_to_stack:zocalo_cluster_request"
100102
"tiff_to_stack" = "murfey.workflows.tiff_to_stack:zocalo_cluster_request"

src/murfey/util/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Dict, List, Literal, Optional, Union
88

99
import yaml
10+
from backports.entry_points_selectable import entry_points
1011
from pydantic import BaseModel, BaseSettings
1112

1213

@@ -157,3 +158,16 @@ def get_machine_config(instrument_name: str = "") -> Dict[str, MachineConfig]:
157158
Path(settings.murfey_machine_configuration), microscope
158159
)
159160
return machine_config
161+
162+
163+
def get_extended_machine_config(
164+
extension_name: str, instrument_name: str = ""
165+
) -> Optional[BaseModel]:
166+
machine_config = get_machine_config(instrument_name=instrument_name).get(
167+
instrument_name
168+
)
169+
if not machine_config:
170+
return None
171+
model = entry_points.select(group="murfey.config", name=extension_name)[0].load()
172+
data = getattr(machine_config, extension_name, {})
173+
return model(data)

0 commit comments

Comments
 (0)