From 9318e553e5954e222161f2fc558e196a3be8e23f Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Tue, 24 Oct 2023 12:58:18 -0400 Subject: [PATCH] refactor: set default serializer in one place --- src/autora/serializer/__init__.py | 6 +++--- src/autora/workflow/__main__.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/autora/serializer/__init__.py b/src/autora/serializer/__init__.py index b67980c4..137aa1de 100644 --- a/src/autora/serializer/__init__.py +++ b/src/autora/serializer/__init__.py @@ -29,7 +29,7 @@ class SerializersSupported(str, Enum): SerializersSupported.dill: _SerializerDef("dill", "load", "dump", "dumps", "b"), } -_default_serializer = SerializersSupported.pickle +default_serializer = SerializersSupported.pickle def _get_serializer_mode( @@ -49,7 +49,7 @@ def _get_serializer_mode( def load_state( path: Optional[pathlib.Path], - loader: SerializersSupported = _default_serializer, + loader: SerializersSupported = default_serializer, ) -> Union[State, None]: """Load a State object from a path.""" if path is not None: @@ -66,7 +66,7 @@ def load_state( def dump_state( state_: State, path: Optional[pathlib.Path], - dumper: SerializersSupported = _default_serializer, + dumper: SerializersSupported = default_serializer, ) -> None: """Write a State object to a path.""" if path is not None: diff --git a/src/autora/workflow/__main__.py b/src/autora/workflow/__main__.py index eb72c067..18062f17 100644 --- a/src/autora/workflow/__main__.py +++ b/src/autora/workflow/__main__.py @@ -6,7 +6,12 @@ import typer from typing_extensions import Annotated -from autora.serializer import SerializersSupported, dump_state, load_state +from autora.serializer import ( + SerializersSupported, + default_serializer, + dump_state, + load_state, +) _logger = logging.getLogger(__name__) @@ -27,7 +32,7 @@ def main( typer.Option( help="(de)serializer to load the data", ), - ] = SerializersSupported.dill, + ] = default_serializer, out_path: Annotated[ Optional[pathlib.Path], typer.Option(help="Path to output the final state"), @@ -37,7 +42,7 @@ def main( typer.Option( help="serializer to save the data", ), - ] = SerializersSupported.dill, + ] = default_serializer, verbose: Annotated[bool, typer.Option(help="Turns on info logging level.")] = False, debug: Annotated[bool, typer.Option(help="Turns on debug logging level.")] = False, ):