-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mg515 <[email protected]>
- Loading branch information
Showing
6 changed files
with
59 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
plugins/flytekit-omegaconf/flytekitplugins/omegaconf/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,33 @@ | ||
from contextlib import contextmanager | ||
|
||
from flytekitplugins.omegaconf.config import OmegaConfTransformerMode | ||
from flytekitplugins.omegaconf.dictconfig_transformer import DictConfigTransformer # noqa: F401 | ||
from flytekitplugins.omegaconf.listconfig_transformer import ListConfigTransformer # noqa: F401 | ||
|
||
_TRANSFORMER_MODE = OmegaConfTransformerMode.Auto | ||
|
||
|
||
def set_transformer_mode(mode: OmegaConfTransformerMode) -> None: | ||
"""Set the global serialization mode for OmegaConf objects.""" | ||
global _TRANSFORMER_MODE | ||
_TRANSFORMER_MODE = mode | ||
|
||
|
||
def get_transformer_mode() -> OmegaConfTransformerMode: | ||
"""Get the global serialization mode for OmegaConf objects.""" | ||
return _TRANSFORMER_MODE | ||
|
||
|
||
@contextmanager | ||
def local_transformer_mode(mode: OmegaConfTransformerMode): | ||
"""Context manager to set a local serialization mode for OmegaConf objects.""" | ||
global _TRANSFORMER_MODE | ||
previous_mode = _TRANSFORMER_MODE | ||
set_transformer_mode(mode) | ||
try: | ||
yield | ||
finally: | ||
set_transformer_mode(previous_mode) | ||
|
||
|
||
__all__ = ["set_transformer_mode", "get_transformer_mode", "local_transformer_mode", "OmegaConfTransformerMode"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters