11import io
2+ import json
23from pathlib import Path
34from urllib .parse import urlparse
45
56import boto3 as boto
67import click
7- import orjson
88
99from sync .api .predictions import (
1010 create_prediction ,
1717from sync .cli .util import validate_project
1818from sync .config import CONFIG
1919from sync .models import Platform , Preference
20+ from sync .utils .json import DateTimeEncoderNaiveUTCDropMicroseconds
2021
2122
2223@click .group
@@ -48,12 +49,12 @@ def generate(
4849 parsed_report_arg = urlparse (report )
4950 if parsed_report_arg .scheme == "" :
5051 with open (report ) as report_fobj :
51- report = orjson .loads (report_fobj .read ())
52+ report = json .loads (report_fobj .read ())
5253 elif parsed_report_arg .scheme == "s3" :
5354 s3 = boto .client ("s3" )
5455 report_io = io .BytesIO ()
5556 s3 .download_fileobj (parsed_report_arg .netloc , parsed_report_arg .path .lstrip ("/" ), report_io )
56- report = orjson .loads (report_io .getvalue ())
57+ report = json .loads (report_io .getvalue ())
5758 else :
5859 ctx .fail ("Unsupported report argument" )
5960
@@ -83,13 +84,7 @@ def generate(
8384 prediction = prediction_response .result
8485 if prediction :
8586 click .echo (
86- orjson .dumps (
87- prediction ,
88- option = orjson .OPT_INDENT_2
89- | orjson .OPT_UTC_Z
90- | orjson .OPT_NAIVE_UTC
91- | orjson .OPT_OMIT_MICROSECONDS ,
92- )
87+ json .dumps (prediction , indent = 2 , cls = DateTimeEncoderNaiveUTCDropMicroseconds )
9388 )
9489 else :
9590 click .echo (str (response .error ), err = True )
@@ -108,12 +103,12 @@ def create(ctx: click.Context, platform: Platform, event_log: str, report: str,
108103 parsed_report_arg = urlparse (report )
109104 if parsed_report_arg .scheme == "" :
110105 with open (report ) as report_fobj :
111- report = orjson .loads (report_fobj .read ())
106+ report = json .loads (report_fobj .read ())
112107 elif parsed_report_arg .scheme == "s3" :
113108 s3 = boto .client ("s3" )
114109 report_io = io .BytesIO ()
115110 s3 .download_fileobj (parsed_report_arg .netloc , parsed_report_arg .path .lstrip ("/" ), report_io )
116- report = orjson .loads (report_io .getvalue ())
111+ report = json .loads (report_io .getvalue ())
117112 else :
118113 ctx .fail ("Unsupported report argument" )
119114
@@ -161,15 +156,7 @@ def status(prediction_id: str):
161156def get (prediction_id : str , preference : Preference ):
162157 """Retrieve a prediction"""
163158 response = get_prediction (prediction_id , preference .value )
164- click .echo (
165- orjson .dumps (
166- response .result ,
167- option = orjson .OPT_INDENT_2
168- | orjson .OPT_UTC_Z
169- | orjson .OPT_NAIVE_UTC
170- | orjson .OPT_OMIT_MICROSECONDS ,
171- )
172- )
159+ click .echo (json .dumps (response .result , indent = 2 , cls = DateTimeEncoderNaiveUTCDropMicroseconds ))
173160
174161
175162@predictions .command
0 commit comments