Skip to content

Commit

Permalink
added dynamic updateer to main
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Mar 7, 2024
1 parent bd16cb7 commit 3f86d86
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion biosimulator_processes/data_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from typing import Dict, List, Union, Tuple, Optional
from types import NoneType
from abc import ABC, abstractmethod
from pydantic import BaseModel as _BaseModel, field_validator, field_serializer, Field, ConfigDict
from pydantic import (
BaseModel as _BaseModel,
field_validator,
field_serializer,
Field,
ConfigDict,
create_model
)


__all__ = [
Expand Down Expand Up @@ -197,6 +204,21 @@ def set_value(cls):


# --- TYPE REGISTRY
def dynamic_config(name: str, config: dict, **kwargs):
config = config or {}
config.update(kwargs)
dynamic_config_types = {}
for param_name, param_val in config.items():
dynamic_config_types[param_name] = (type(param_val), ...)

name = name.replace(name[0], name[0].upper())
DynamicProcessConfig = create_model(
f'{name}ProcessConfig',
**dynamic_config_types
)
return DynamicProcessConfig(**config)


class ProcessConfig(BaseModel):
value: Dict

Expand Down

0 comments on commit 3f86d86

Please sign in to comment.