Skip to content

Commit 222e0d5

Browse files
steff456ccordoba12delta003
authored
PR: Upgrade ujson dependency (#44)
* Upgrade ujson dependency to 2.0.3 * Add monkeypatch to support datetime in the latest version of ujson * revert to datetime in CI * add Python 2 support in the monkeypatch * add import * move sys import before mock import * Add support to all OS if python 3 * add review changes * Fix dependency constraint Co-authored-by: Carlos Cordoba <[email protected]> Co-authored-by: Carlos Cordoba <[email protected]> Co-authored-by: Marko Bakovic <[email protected]>
1 parent 7987e30 commit 222e0d5

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

setup.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#!/usr/bin/env python
22
from setuptools import find_packages, setup
3+
import sys
34
import versioneer
45

56
README = open('README.rst', 'r').read()
67

78

9+
install_requires = [
10+
'future>=0.14.0; python_version<"3"',
11+
'futures; python_version<"3.2"',
12+
]
13+
14+
if sys.version_info[0] == 2:
15+
install_requires.append('ujson<=2.0.3; platform_system!="Windows"')
16+
else:
17+
install_requires.append('ujson>=3.0.0')
18+
819
setup(
920
name='python-jsonrpc-server',
1021

@@ -31,11 +42,7 @@
3142
# your project is installed. For an analysis of "install_requires" vs pip's
3243
# requirements files see:
3344
# https://packaging.python.org/en/latest/requirements.html
34-
install_requires=[
35-
'future>=0.14.0; python_version<"3"',
36-
'futures; python_version<"3.2"',
37-
'ujson<=1.35; platform_system!="Windows"',
38-
],
45+
install_requires=install_requires,
3946

4047
# List additional groups of dependencies here (e.g. development
4148
# dependencies). You can install these using the following syntax,

test/test_streams.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright 2018 Palantir Technologies, Inc.
22
# pylint: disable=redefined-outer-name
33
from io import BytesIO
4+
import datetime
45
import os
6+
import sys
57
import mock
68
import pytest
79

@@ -95,11 +97,21 @@ def test_writer(wfile, writer):
9597
)
9698

9799

100+
class JsonDatetime(datetime.datetime):
101+
"""Monkey path json datetime."""
102+
def __json__(self):
103+
if sys.version_info.major == 3:
104+
dif = int(self.timestamp())
105+
else:
106+
dif = int((self - datetime.datetime(1970, 1, 1)).total_seconds())
107+
return '{0}'.format(dif)
108+
109+
98110
def test_writer_bad_message(wfile, writer):
99111
# A datetime isn't serializable(or poorly serializable),
100112
# ensure the write method doesn't throw, but the result could be empty
101113
# or the correct datetime
102-
import datetime
114+
datetime.datetime = JsonDatetime
103115
writer.write(datetime.datetime(
104116
year=2019,
105117
month=1,

0 commit comments

Comments
 (0)