@@ -888,6 +888,7 @@ def __post_init_post_parse__(self):
888888 self ._default_hooks : bool = False
889889 self ._links_resolved : Set [str ] = set ()
890890 self ._imports_resolved : Set [str ] = set ()
891+ self ._package_path : Optional [str ] = None
891892
892893 @property
893894 def environment (self ) -> Dict [str , str ]:
@@ -899,8 +900,17 @@ def filenames(self) -> List[str]:
899900
900901 @property
901902 def package_path (self ) -> str :
902- package = importlib .import_module (self .package )
903- return dirname (package .__file__ )
903+ if not self ._package_path :
904+ package = importlib .import_module (self .package )
905+ self ._package_path = dirname (package .__file__ )
906+
907+ return self ._package_path
908+
909+ @package_path .setter
910+ def package_path (self , value : str ):
911+ if self ._package_path :
912+ raise ConfigInitializationException
913+ self ._package_path = value
904914
905915 @classmethod
906916 def load (
@@ -972,14 +982,14 @@ def get_tzkt_datasource(self, name: str) -> TzktDatasourceConfig:
972982 raise ConfigurationError ('`datasource` field must refer to TzKT datasource' )
973983 return datasource
974984
975- def pre_initialize (self ) -> None :
985+ def initialize (self , skip_imports : bool = False ) -> None :
976986 self ._set_names ()
977987 self ._resolve_templates ()
978988 self ._resolve_links ()
979989 self ._validate ()
980990
981- def initialize ( self ) -> None :
982- self . pre_initialize ()
991+ if skip_imports :
992+ return
983993
984994 for index_config in self .indexes .values ():
985995 if index_config .name in self ._imports_resolved :
@@ -991,12 +1001,12 @@ def initialize(self) -> None:
9911001 raise ConfigInitializationException
9921002
9931003 elif isinstance (index_config , OperationIndexConfig ):
994- self ._load_operation_index_types (index_config )
995- self ._load_index_callbacks (index_config )
1004+ self ._import_operation_index_types (index_config )
1005+ self ._import_index_callbacks (index_config )
9961006
9971007 elif isinstance (index_config , BigMapIndexConfig ):
998- self ._load_big_map_index_types (index_config )
999- self ._load_index_callbacks (index_config )
1008+ self ._import_big_map_index_types (index_config )
1009+ self ._import_index_callbacks (index_config )
10001010
10011011 else :
10021012 raise NotImplementedError (f'Index kind `{ index_config .kind } ` is not supported' )
@@ -1151,7 +1161,7 @@ def _set_names(self) -> None:
11511161 for name , config in named_configs .items ():
11521162 config .name = name
11531163
1154- def _load_operation_index_types (self , index_config : OperationIndexConfig ) -> None :
1164+ def _import_operation_index_types (self , index_config : OperationIndexConfig ) -> None :
11551165 for handler_config in index_config .handlers :
11561166 for pattern_config in handler_config .pattern :
11571167 if isinstance (pattern_config , OperationHandlerTransactionPatternConfig ):
@@ -1165,11 +1175,11 @@ def _load_operation_index_types(self, index_config: OperationIndexConfig) -> Non
11651175 else :
11661176 raise NotImplementedError
11671177
1168- def _load_index_callbacks (self , index_config : ResolvedIndexConfigT ) -> None :
1178+ def _import_index_callbacks (self , index_config : ResolvedIndexConfigT ) -> None :
11691179 for handler_config in index_config .handlers :
11701180 handler_config .initialize_callback_fn (self .package )
11711181
1172- def _load_big_map_index_types (self , index_config : BigMapIndexConfig ) -> None :
1182+ def _import_big_map_index_types (self , index_config : BigMapIndexConfig ) -> None :
11731183 for big_map_handler_config in index_config .handlers :
11741184 big_map_handler_config .initialize_big_map_type (self .package )
11751185
0 commit comments