Skip to content

Commit

Permalink
remove ujson
Browse files Browse the repository at this point in the history
Signed-off-by: pstlouis <[email protected]>
  • Loading branch information
PatStLouis committed Sep 13, 2024
1 parent 814ef20 commit f69ee5c
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 61 deletions.
1 change: 0 additions & 1 deletion build-scripts/ubuntu-2004/build-3rd-parties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,3 @@ build_from_pypi semver 2.13.0
build_from_pypi sha3
build_from_pypi six
build_from_pypi sortedcontainers 1.5.7
build_from_pypi ujson 1.33
1 change: 0 additions & 1 deletion build-scripts/ubuntu-2004/prepare-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ if [ "$distro_packages" = "debian-packages" ]; then
# Update the package names to match the versions that are pre-installed on the os.
echo -e "\nAdapt the dependencies for the Canonical archive"
#### ToDo adjust packages for the Cannonical archive for Ubuntu 20.04 (focal)
# sed -i "s~ujson==1.33~ujson==1.33-1build1~" setup.py
# sed -i "s~prompt_toolkit==0.57~prompt_toolkit==0.57-1~" setup.py
# sed -i "s~msgpack-python==0.4.6~msgpack==0.4.6-1build1~" setup.py
elif [ "$distro_packages" = "python-packages" ]; then
Expand Down
46 changes: 13 additions & 33 deletions common/serializers/json_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,25 @@


import base64
import json
from typing import Dict

from common.serializers.mapping_serializer import MappingSerializer

try:
import ujson as json
from ujson import encode as uencode
class OrderedJsonEncoder(json.JSONEncoder):
def __init__(self, *args, **kwargs):
kwargs['ensure_ascii'] = False
kwargs['sort_keys'] = True
kwargs['separators'] = (',', ':')
super().__init__(*args, **kwargs)

# Older versions of ujson's encode do not support `sort_keys`, if that
# is the case default to using json
uencode({'xx': '123', 'aa': 90}, sort_keys=True)
def encode(self, o):
if isinstance(o, (bytes, bytearray)):
return '"{}"'.format(base64.b64encode(o).decode("utf-8"))
else:
return super().encode(o)

class UJsonEncoder:
@staticmethod
def encode(o):
if isinstance(o, (bytes, bytearray)):
return '"{}"'.format(base64.b64encode(o).decode("utf-8"))
else:
return uencode(o, sort_keys=True)

JsonEncoder = UJsonEncoder()

except (ImportError, TypeError):
import json

class OrderedJsonEncoder(json.JSONEncoder):
def __init__(self, *args, **kwargs):
kwargs['ensure_ascii'] = False
kwargs['sort_keys'] = True
kwargs['separators'] = (',', ':')
super().__init__(*args, **kwargs)

def encode(self, o):
if isinstance(o, (bytes, bytearray)):
return '"{}"'.format(base64.b64encode(o).decode("utf-8"))
else:
return super().encode(o)

JsonEncoder = OrderedJsonEncoder()
JsonEncoder = OrderedJsonEncoder()


class JsonSerializer(MappingSerializer):
Expand Down
3 changes: 0 additions & 3 deletions common/serializers/signing_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,3 @@ def serialize(self, obj, level=0, objname=None, topLevelKeysToIgnore=None,
return res

return res.encode('utf-8')

# topLevelKeysToIgnore = topLevelKeysToIgnore or []
# return ujson.dumps({k:obj[k] for k in obj.keys() if k not in topLevelKeysToIgnore}, sort_keys=True)
1 change: 0 additions & 1 deletion dev-setup/ubuntu/ubuntu-2004/SetupVMTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
sortedcontainers==1.5.7 \
timeout-decorator==0.5.0 \
toml==0.10.2 \
ujson==1.33 \
wcwidth==0.2.5 \
wheel==0.34.2 \
zipp==1.2.0
Expand Down
6 changes: 1 addition & 5 deletions plenum/recorder/recorder.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import os
import time
import json
from typing import Callable

from storage.kv_store_rocksdb_int_keys import KeyValueStorageRocksdbIntKeys

try:
import ujson as json
except ImportError:
import json


class Recorder:
INCOMING_FLAG = 0
Expand Down
6 changes: 1 addition & 5 deletions plenum/test/recorder/test_recorder.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import random
import time
import json
from collections import OrderedDict

from plenum.common.util import randomString

try:
import ujson as json
except ImportError:
import json

import pytest

from plenum.recorder.recorder import Recorder
Expand Down
7 changes: 1 addition & 6 deletions scripts/test_zmq/test_zmq/zstack.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from test_zmq.authenticator import MultiZapAuthenticator

try:
import ujson as json
except ImportError:
import json

import json
import os
import shutil
import sys
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ def run(self):
'six',
### Tests fail without version pin (GHA run: https://github.com/udosson/indy-plenum/actions/runs/1078741118)
'sortedcontainers==1.5.7',
### Tests fail without version pin (GHA run: https://github.com/udosson/indy-plenum/actions/runs/1078741118)
'ujson==5.4.0',
],

setup_requires=['pytest-runner==5.3.0'],
Expand Down
5 changes: 1 addition & 4 deletions stp_zmq/zstack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import json

from plenum.common.constants import OP_FIELD_NAME, BATCH
from plenum.common.metrics_collector import NullMetricsCollector
Expand All @@ -8,10 +9,6 @@
from stp_core.common.constants import CONNECTION_PREFIX, ZMQ_NETWORK_PROTOCOL
from stp_zmq.client_message_provider import ClientMessageProvider

try:
import ujson as json
except ImportError:
import json

import os
import shutil
Expand Down

0 comments on commit f69ee5c

Please sign in to comment.