Skip to content

Commit

Permalink
feat: support for GenericSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
aaraney committed Sep 7, 2024
1 parent 40f0bd3 commit 0f5843d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/ngen_config_gen/src/ngen/config_gen/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NamelistSerializer,
TomlSerializer,
YamlSerializer,
GenericSerializer,
)
from pydantic import BaseModel
from typing_extensions import Literal, Self
Expand Down Expand Up @@ -58,6 +59,8 @@ def _get_str_serializer(data: BaseModel) -> Callable[[], str]:
return data.to_toml_str
elif isinstance(data, YamlSerializer):
return data.to_yaml_str
elif isinstance(data, GenericSerializer):
return data.to_str
elif isinstance(data, BaseModel):
return data.json

Expand All @@ -81,6 +84,8 @@ def serialize(p: Path):
return data.to_toml
elif isinstance(data, YamlSerializer):
return data.to_yaml
elif isinstance(data, GenericSerializer):
return data.to_file
elif isinstance(data, BaseModel): # type: ignore
json_serializer(data)

Expand All @@ -98,6 +103,8 @@ def _get_file_extension(data: BaseModel) -> str:
return "toml"
elif isinstance(data, YamlSerializer):
return "yaml"
elif isinstance(data, GenericSerializer):
return ""
elif isinstance(data, BaseModel): # type: ignore
return "json"

Expand Down

0 comments on commit 0f5843d

Please sign in to comment.