From 469ca10068433d428009e340825b40105567840c Mon Sep 17 00:00:00 2001 From: boonhapus Date: Sat, 10 Aug 2024 13:01:45 -0500 Subject: [PATCH 1/2] opt for python dumper/loader when C-based impl not available --- src/thoughtspot_tml/_compat.py | 10 ++++++++++ src/thoughtspot_tml/_yaml.py | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/thoughtspot_tml/_compat.py b/src/thoughtspot_tml/_compat.py index 4583591..6922ba9 100644 --- a/src/thoughtspot_tml/_compat.py +++ b/src/thoughtspot_tml/_compat.py @@ -1,5 +1,15 @@ import sys +import yaml + + +try: + Dumper = yaml.CDumper + Loader = yaml.CSafeLoader +except AttributeError: + Dumper = yaml.Dumper + Loader = yaml.SafeLoader + if sys.version_info < (3, 8): from typing_extensions import get_origin, get_args from typing_extensions import Literal, TypedDict diff --git a/src/thoughtspot_tml/_yaml.py b/src/thoughtspot_tml/_yaml.py index b664a2f..cde0ae2 100644 --- a/src/thoughtspot_tml/_yaml.py +++ b/src/thoughtspot_tml/_yaml.py @@ -5,6 +5,8 @@ import yaml +from thoughtspot_tml import _compat + NEARLY_INFINITY = 999999999 # This used to be math.inf, but C has no concept of infinity. ;) # TML column ids typically take the form.. @@ -60,7 +62,7 @@ def _double_quote_when_special_char(dumper: yaml.Dumper, data: str) -> yaml.Scal return dumper.represent_scalar("tag:yaml.org,2002:str", data, style=style) -yaml.add_representer(str, _double_quote_when_special_char, Dumper=yaml.CDumper) +yaml.add_representer(str, _double_quote_when_special_char, Dumper=_compat.Dumper) # BUG: pyyaml #89 ==> resolved by #635 yaml.Loader.yaml_implicit_resolvers.pop("=") @@ -70,7 +72,7 @@ def load(document: str) -> Dict[str, Any]: """ Load a TML object. """ - return yaml.load(document, Loader=yaml.CSafeLoader) + return yaml.load(document, Loader=_compat.Loader) def dump(document: Dict[str, Any]) -> str: @@ -92,6 +94,6 @@ def dump(document: Dict[str, Any]) -> str: "default_flow_style": False, "sort_keys": False, "allow_unicode": True, - "Dumper": yaml.CDumper, + "Dumper": _compat.Dumper, } return yaml.dump(document, **options) From 91e7a02737c5380dc6158f2cb6d8430d9ec222fb Mon Sep 17 00:00:00 2001 From: boonhapus Date: Sat, 10 Aug 2024 13:02:15 -0500 Subject: [PATCH 2/2] version bump --> 2.1.1 --- src/thoughtspot_tml/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thoughtspot_tml/_version.py b/src/thoughtspot_tml/_version.py index 9aa3f90..58039f5 100644 --- a/src/thoughtspot_tml/_version.py +++ b/src/thoughtspot_tml/_version.py @@ -1 +1 @@ -__version__ = "2.1.0" +__version__ = "2.1.1"