Skip to content

generic

generic.restore_from_json

                                                                                
 Documentation                                                                  
                          -- n/a --                                             
                                                                                
 Origin                                                                         
                          Authors   Markus Binsteiner (markus@frkl.io)          
                                                                                
 Context                                                                        
                          Tags         core                                     
                          Labels       package: kiara_modules.core              
                          References   source_repo:                             
                                       https://github.com/DHARPA-Project/kia…   
                                       documentation:                           
                                       https://dharpa.org/kiara_modules.core/   
                                       module_doc:                              
                                       https://dharpa.org/kiara_modules.core…   
                                       source_url:                              
                                       https://github.com/DHARPA-Project/kia…   
                                                                                
 Module config                                                                  
                          Field       Type     Description           Required   
                         ─────────────────────────────────────────────────────  
                          constants   object   Value constants for   no         
                                               this module.                     
                          defaults    object   Value defaults for    no         
                                               this module.                     
                                                                                
 Module config          -- no config --                                         
 Python class                                                                   
                          class_name    RestoreFromJsonDictModule               
                          module_name   kiara_modules.core.generic              
                          full_name     kiara_modules.core.generic.RestoreFr…   
                                                                                
 Processing source code  ─────────────────────────────────────────────────────  
                          def process(self, inputs: ValueSet, outputs: Value…   
                                                                                
                              base_path = inputs.get_value_data("base_path")    
                              file_name = inputs.get_value_data("file_name")    
                                                                                
                              full_path = os.path.join(base_path, file_name)    
                                                                                
                              if not os.path.exists(full_path):                 
                                  raise KiaraProcessingException(               
                                      f"Can't deserialize dict, path to file…   
                                  )                                             
                                                                                
                              if not os.path.isfile(os.path.realpath(full_pa…   
                                  raise KiaraProcessingException(               
                                      f"Can't deserialize dict, path is not …   
                                  )                                             
                                                                                
                              with open(full_path, "r") as f:                   
                                  content = f.read()                            
                                                                                
                              data = orjson.loads(content)                      
                              outputs.set_value("value_item", data)             
                                                                                
                         ─────────────────────────────────────────────────────  
                                                                                

generic.restore_scalar

                                                                                
 Documentation                                                                  
                          Utility module, only used internally.                 
                                                                                
 Origin                                                                         
                          Authors   Markus Binsteiner (markus@frkl.io)          
                                                                                
 Context                                                                        
                          Tags         core                                     
                          Labels       package: kiara_modules.core              
                          References   source_repo:                             
                                       https://github.com/DHARPA-Project/kia…   
                                       documentation:                           
                                       https://dharpa.org/kiara_modules.core/   
                                       module_doc:                              
                                       https://dharpa.org/kiara_modules.core…   
                                       source_url:                              
                                       https://github.com/DHARPA-Project/kia…   
                                                                                
 Module config                                                                  
                          Field        Type     Description          Required   
                         ─────────────────────────────────────────────────────  
                          constants    object   Value constants      no         
                                                for this module.                
                          defaults     object   Value defaults for   no         
                                                this module.                    
                          value_type   string   The value type of    yes        
                                                the scalar to                   
                                                load.                           
                                                                                
 Module config          -- no config --                                         
 Python class                                                                   
                          class_name    RestoreScalarModule                     
                          module_name   kiara_modules.core.generic              
                          full_name     kiara_modules.core.generic.RestoreSc…   
                                                                                
 Processing source code  ─────────────────────────────────────────────────────  
                          def process(self, inputs: ValueSet, outputs: Value…   
                                                                                
                              data = inputs.get_value_obj("scalar_data")        
                              outputs.set_value("value_item", data)             
                                                                                
                         ─────────────────────────────────────────────────────  
                                                                                

generic.store

                                                                                
 Documentation                                                                  
                          -- n/a --                                             
                                                                                
 Origin                                                                         
                          Authors   Markus Binsteiner (markus@frkl.io)          
                                                                                
 Context                                                                        
                          Tags         core                                     
                          Labels       package: kiara_modules.core              
                          References   source_repo:                             
                                       https://github.com/DHARPA-Project/kia…   
                                       documentation:                           
                                       https://dharpa.org/kiara_modules.core/   
                                       module_doc:                              
                                       https://dharpa.org/kiara_modules.core…   
                                       source_url:                              
                                       https://github.com/DHARPA-Project/kia…   
                                                                                
 Module config                                                                  
                          Field        Type     Description          Required   
                         ─────────────────────────────────────────────────────  
                          constants    object   Value constants      no         
                                                for this module.                
                          defaults     object   Value defaults for   no         
                                                this module.                    
                          value_type   string   The type of the      yes        
                                                value to save.                  
                                                                                
 Module config          -- no config --                                         
 Python class                                                                   
                          class_name    StoreScalarModule                       
                          module_name   kiara_modules.core.generic              
                          full_name     kiara_modules.core.generic.StoreScal…   
                                                                                
 Processing source code  ─────────────────────────────────────────────────────  
                          def process(self, inputs: ValueSet, outputs: Value…   
                                                                                
                              value_id: str = inputs.get_value_data("value_i…   
                              if not value_id:                                  
                                  raise KiaraProcessingException("No value i…   
                                                                                
                              field_name = self.get_config_value("value_type…   
                              if field_name == "any":                           
                                  field_name = "value_item"                     
                                                                                
                              value_obj: Value = inputs.get_value_obj(field_…   
                              base_path: str = inputs.get_value_data("base_p…   
                                                                                
                              result = self.store_value(value=value_obj, bas…   
                              if isinstance(result, typing.Mapping):            
                                  load_config = result                          
                                  result_value = value_obj                      
                              elif isinstance(result, tuple):                   
                                  load_config = result[0]                       
                                  if result[1]:                                 
                                      result_value = result[1]                  
                                  else:                                         
                                      result_value = value_obj                  
                              else:                                             
                                  raise KiaraProcessingException(               
                                      f"Invalid result type for 'store_value…   
                                  )                                             
                                                                                
                              load_config["value_id"] = value_id                
                                                                                
                              lc = LoadConfig(**load_config)                    
                                                                                
                              if lc.base_path_input_name and lc.base_path_in…   
                                  raise KiaraProcessingException(               
                                      f"Invalid load config: base path '{lc.   
                                  )                                             
                                                                                
                              outputs.set_values(                               
                                  metadata=None, lineage=None, **{"load_conf…   
                              )                                                 
                                                                                
                         ─────────────────────────────────────────────────────