From 0f5843d713e76fb0a23eef6e25e4d75d789b2f7d Mon Sep 17 00:00:00 2001 From: Austin Raney Date: Fri, 30 Aug 2024 15:01:15 -0400 Subject: [PATCH] feat: support for GenericSerializer --- python/ngen_config_gen/src/ngen/config_gen/file_writer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/ngen_config_gen/src/ngen/config_gen/file_writer.py b/python/ngen_config_gen/src/ngen/config_gen/file_writer.py index 975d76f9..ed273a13 100644 --- a/python/ngen_config_gen/src/ngen/config_gen/file_writer.py +++ b/python/ngen_config_gen/src/ngen/config_gen/file_writer.py @@ -16,6 +16,7 @@ NamelistSerializer, TomlSerializer, YamlSerializer, + GenericSerializer, ) from pydantic import BaseModel from typing_extensions import Literal, Self @@ -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 @@ -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) @@ -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"