88from typing import Callable , Dict , List , NamedTuple , Optional , Set
99from urllib .parse import ParseResult
1010
11- from pydantic import BaseModel , validator
11+ from pydantic import BaseModel , ConfigDict , field_validator
12+ from pydantic_core .core_schema import FieldValidationInfo
1213
1314from murfey .client .watchdir import DirWatcher
1415
@@ -40,20 +41,20 @@ class MurfeyInstanceEnvironment(BaseModel):
4041 destination_registry : Dict [str , str ] = {}
4142 watchers : Dict [Path , DirWatcher ] = {}
4243 demo : bool = False
43- data_collection_group_ids : Dict [str , int ] = {}
44- data_collection_ids : Dict [str , int ] = {}
45- processing_job_ids : Dict [str , Dict [str , int ]] = {}
46- autoproc_program_ids : Dict [str , Dict [str , int ]] = {}
4744 id_tag_registry : Dict [str , List [str ]] = {
4845 "data_collection_group" : [],
4946 "data_collection" : [],
5047 "processing_job" : [],
5148 "auto_proc_program" : [],
5249 }
50+ listeners : Dict [str , Set [Callable ]] = {}
51+ data_collection_group_ids : Dict [str , int ] = {}
52+ data_collection_ids : Dict [str , int ] = {}
53+ processing_job_ids : Dict [str , Dict [str , int ]] = {}
54+ autoproc_program_ids : Dict [str , Dict [str , int ]] = {}
5355 data_collection_parameters : dict = {}
5456 movies : Dict [Path , MovieTracker ] = {}
5557 motion_corrected_movies : Dict [Path , List [str ]] = {}
56- listeners : Dict [str , Set [Callable ]] = {}
5758 movie_tilt_pair : Dict [Path , str ] = {}
5859 tilt_angles : Dict [str , List [List [str ]]] = {}
5960 movie_counters : Dict [str , itertools .count ] = {}
@@ -64,42 +65,41 @@ class MurfeyInstanceEnvironment(BaseModel):
6465 murfey_session : Optional [int ] = None
6566 samples : Dict [Path , SampleInfo ] = {}
6667
67- class Config :
68- validate_assignment : bool = True
69- arbitrary_types_allowed : bool = True
68+ model_config = ConfigDict (arbitrary_types_allowed = True )
7069
71- @validator ("data_collection_group_ids" )
72- def dcg_callback (cls , v , values ):
70+ @field_validator ("data_collection_group_ids" )
71+ def dcg_callback (cls , v , info : FieldValidationInfo ):
7372 with global_env_lock :
74- for l in values .get ("listeners" , {}).get ("data_collection_group_ids" , []):
73+ for l in info .data .get ("listeners" , {}).get (
74+ "data_collection_group_ids" , []
75+ ):
7576 for k in v .keys ():
76- if k not in values ["id_tag_registry" ]["data_collection" ]:
77+ if k not in info . data ["id_tag_registry" ]["data_collection" ]:
7778 l (k )
7879 return v
7980
80- @validator ("data_collection_ids" )
81- def dc_callback (cls , v , values ):
81+ @field_validator ("data_collection_ids" )
82+ def dc_callback (cls , v , info : FieldValidationInfo ):
8283 with global_env_lock :
83- for l in values .get ("listeners" , {}).get ("data_collection_ids" , []):
84+ for l in info . data .get ("listeners" , {}).get ("data_collection_ids" , []):
8485 for k in v .keys ():
85- if k not in values ["id_tag_registry" ]["processing_job" ]:
86+ if k not in info . data ["id_tag_registry" ]["processing_job" ]:
8687 l (k )
8788 return v
8889
89- @validator ("processing_job_ids" )
90- def job_callback (cls , v , values ):
90+ @field_validator ("processing_job_ids" )
91+ def job_callback (cls , v , info : FieldValidationInfo ):
9192 with global_env_lock :
92- for l in values .get ("listeners" , {}).get ("processing_job_ids" , []):
93+ for l in info . data .get ("listeners" , {}).get ("processing_job_ids" , []):
9394 for k in v .keys ():
94- if k not in values ["id_tag_registry" ]["auto_proc_program" ]:
95+ if k not in info . data ["id_tag_registry" ]["auto_proc_program" ]:
9596 l (k , v [k ]["ispyb-relion" ])
9697 return v
9798
98- @validator ("autoproc_program_ids" )
99- def app_callback (cls , v , values ):
100- # logger.info(f"autoproc program ids validator: {v}")
99+ @field_validator ("autoproc_program_ids" )
100+ def app_callback (cls , v , info : FieldValidationInfo ):
101101 with global_env_lock :
102- for l in values .get ("listeners" , {}).get ("autoproc_program_ids" , []):
102+ for l in info . data .get ("listeners" , {}).get ("autoproc_program_ids" , []):
103103 for k in v .keys ():
104104 if v [k ].get ("em-tomo-preprocess" ):
105105 l (k , v [k ]["em-tomo-preprocess" ])
0 commit comments