44import socket
55from functools import lru_cache
66from pathlib import Path
7- from typing import Dict , List , Literal , Optional , Union
7+ from typing import Any , Dict , List , Literal , Mapping , Optional , Union
88
99import yaml
10- from pydantic import BaseModel , BaseSettings , Field
10+ from pydantic import BaseModel , BaseSettings , Field , validator
11+ from pydantic .errors import NoneIsNotAllowedError
1112
1213
1314class MachineConfig (BaseModel ):
14- acquisition_software : List [str ]
15+ acquisition_software : List [Literal [ "epu" , "tomo" , "serialem" , "autotem" ] ]
1516 calibrations : Dict [str , Dict [str , Union [dict , float ]]]
1617 data_directories : Dict [Path , str ]
17- rsync_basepath : Path
18- default_model : Path
18+ rsync_basepath : Optional [Path ] = Field (
19+ default = None ,
20+ description = "Path set for the rsync daemon which will need to be prepended to file paths. Required if data_transfer_enabled is True" ,
21+ )
22+ default_model : Optional [Path ] = Field (
23+ default = None , description = "Path to the default model used for particle picking"
24+ )
1925 display_name : str = Field (
2026 default = "" ,
2127 description = "Name of instrument used for display purposes, i.e. Krios I" ,
@@ -38,7 +44,6 @@ class MachineConfig(BaseModel):
3844 description = "Directories to be created within each visit" ,
3945 )
4046 analyse_created_directories : List [str ] = []
41- gain_reference_directory : Optional [Path ] = None
4247 eer_fractionation_file_template : str = ""
4348 gain_reference_directory : Optional [Path ] = Field (
4449 default = None ,
@@ -58,7 +63,6 @@ class MachineConfig(BaseModel):
5863 allow_removal : bool = Field (
5964 default = False , description = "Allow original files to be removed after rsync"
6065 )
61- modular_spa : bool = False
6266 data_transfer_enabled : bool = True
6367 processing_enabled : bool = True
6468 machine_override : str = ""
@@ -84,14 +88,35 @@ class MachineConfig(BaseModel):
8488 model_search_directory : str = "processing"
8589 initial_model_search_directory : str = "processing/initial_model"
8690
87- failure_queue : str = ""
91+ failure_queue : str = Field (
92+ default = "" ,
93+ description = "Name of RabbitMQ queue where failed API calls will be recorded" ,
94+ )
8895 instrument_server_url : str = "http://localhost:8001"
8996 frontend_url : str = "http://localhost:3000"
9097 murfey_url : str = "http://localhost:8000"
9198
9299 security_configuration_path : Optional [Path ] = None
93100 auth_url : str = ""
94101
102+ @validator ("rsync_basepath" , always = True )
103+ def __validate_rsync_basepath_if_transfer_enabled__ (
104+ cls , v : Optional [str ], values : Mapping [str , Any ]
105+ ) -> Any :
106+ if values ["data_transfer_enabled" ]:
107+ if v is None :
108+ raise NoneIsNotAllowedError
109+ return v
110+
111+ @validator ("default_model" , always = True )
112+ def __validate_default_model_if_processing_enabled_and_spa_possible__ (
113+ cls , v : Optional [str ], values : Mapping [str , Any ]
114+ ) -> Any :
115+ if values ["processing_enabled" ] and "epu" in values ["acquisition_software" ]:
116+ if v is None :
117+ raise NoneIsNotAllowedError
118+ return v
119+
95120
96121def from_file (config_file_path : Path , instrument : str = "" ) -> Dict [str , MachineConfig ]:
97122 with open (config_file_path , "r" ) as config_stream :
0 commit comments