diff --git a/cts1_ground_support/json_parser.py b/cts1_ground_support/json_parser.py index fff08d6..8f14d43 100644 --- a/cts1_ground_support/json_parser.py +++ b/cts1_ground_support/json_parser.py @@ -1,9 +1,10 @@ """Tools for parsing JSON strings from blobs of text.""" -import json from collections.abc import Iterator from dataclasses import dataclass +import orjson + @dataclass(kw_only=True) class ParsedJson: @@ -24,7 +25,7 @@ def extract_json_blobs(content: str) -> Iterator[ParsedJson]: for end_idx in range(len(content) - 1, start_idx, -1): if content[end_idx] == "}": try: - data = json.loads(content[start_idx : end_idx + 1]) + data = orjson.loads(content[start_idx : end_idx + 1]) yield ParsedJson( data=data, start_idx=start_idx, @@ -33,7 +34,7 @@ def extract_json_blobs(content: str) -> Iterator[ParsedJson]: ) start_idx = end_idx break - except json.JSONDecodeError: + except orjson.JSONDecodeError: pass start_idx += 1 @@ -43,6 +44,9 @@ def auto_format_json_in_blob(blob: str) -> str: json_parts = list(extract_json_blobs(blob)) for json_part in json_parts: - blob = blob.replace(json_part.original_str, json.dumps(json_part.data, indent=4)) + formatted_data: str = orjson.dumps(json_part.data, option=orjson.OPT_INDENT_2).decode( + "utf-8" + ) + blob = blob.replace(json_part.original_str, formatted_data) return blob diff --git a/pyproject.toml b/pyproject.toml index 41e85e4..086700f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,13 +6,15 @@ build-backend = "hatchling.build" name = "cts1_ground_support" version = "v0-dev" dependencies = [ - "GitPython", - "pyserial", - "loguru", - "dash", - "dash-bootstrap-components", - "dash-split-pane~=1.0.0", + "GitPython<4,>3", + "pyserial>3,<4", + "loguru~=0.7.2", + "dash>2,<3", + "dash-bootstrap-components>1,<2", + "dash-split-pane>=1,<2", "pytz", + "orjson>3,<4", + "platformdirs>4,<5" ] requires-python = ">=3.10" authors = [