Commits

Kazuhiko Shimada authored b59c21c3f98
PIPE-2354: modified JSON dumper to use JSON.dumps
No tags

pipeline/infrastructure/utils/utils.py

Modified
5 5 import ast
6 6 import bisect
7 7 import collections
8 8 import contextlib
9 9 import copy
10 10 import errno
11 11 import fcntl
12 12 import glob
13 13 import inspect
14 14 import itertools
15 +import json
15 16 import operator
16 17 import os
17 18 import pickle
18 19 import re
19 20 import shutil
20 21 import string
21 22 import tarfile
22 23 import time
23 24 from collections.abc import Iterable
24 25 from datetime import datetime
25 26 from functools import wraps
26 27 from numbers import Number
27 -from pprint import pprint
28 28 from typing import (Any, Callable, Collection, Dict, List, Optional, Sequence,
29 29 Tuple, Union)
30 30 from urllib.parse import urlparse
31 31
32 32 import casaplotms
33 33 import numpy as np
34 34 import numpy.typing as npt
35 35
36 36 from .. import casa_tools, logging, mpihelpers
37 37 from .conversion import dequote, range_to_list
1009 1009
1010 1010
1011 1011 def _dump(obj: object, path: str, name: str, dump_pickle: bool=True, dump_json: bool=False, json_dict={}):
1012 1012 file_path = os.path.join(path, f'{name}')
1013 1013
1014 1014 if dump_pickle:
1015 1015 with open(file_path+'.pickle', 'wb') as f:
1016 1016 pickle.dump(obj, f)
1017 1017 if dump_json:
1018 1018 with open(file_path+'.json', 'w') as f:
1019 - pprint(json_dict[name], f)
1019 + f.write(json.dumps(json_dict[name], default=str))
1020 1020
1021 1021
1022 1022 def _get_full_method_path(func):
1023 1023 module_name = func.__module__
1024 1024 if hasattr(func, '__qualname__'):
1025 1025 qualname = func.__qualname__
1026 1026 else:
1027 1027 qualname = func.__name__
1028 1028 return f'{module_name}.{qualname}'
1029 1029

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut