Skip to content

Commit 67b2706

Browse files
dalthvizjroitgrund
authored andcommitted
PR: Remove ujson dependency for Windows (it requires the install of MSVC compiler) (#26)
* Remove ujson dependency for Windows (requires the install of MSVC compiler) * Update setup.py and stream write test * Add broad exception for ujson import
1 parent 1b1d9b2 commit 67b2706

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

examples/langserver.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import ujson as json
21
import logging
32

43
from tornado import web, ioloop, websocket
54

65
from pyls_jsonrpc import dispatchers, endpoint
76

7+
try:
8+
import ujson as json
9+
except Exception: # pylint: disable=broad-except
10+
import json
11+
812
log = logging.getLogger(__name__)
913

1014

examples/langserver_ext.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ujson as json
21
import logging
32
import subprocess
43
import threading
@@ -7,6 +6,11 @@
76

87
from pyls_jsonrpc import streams
98

9+
try:
10+
import ujson as json
11+
except Exception: # pylint: disable=broad-except
12+
import json
13+
1014
log = logging.getLogger(__name__)
1115

1216

pyls_jsonrpc/streams.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import logging
33
import threading
44

5-
import ujson as json
5+
try:
6+
import ujson as json
7+
except Exception: # pylint: disable=broad-except
8+
import json
69

710
log = logging.getLogger(__name__)
811

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
install_requires=[
3535
'future>=0.14.0',
3636
'futures; python_version<"3.2"',
37-
'ujson<=1.35',
37+
'ujson<=1.35; platform_system!="Windows"',
3838
],
3939

4040
# List additional groups of dependencies here (e.g. development

test/test_streams.py

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2018 Palantir Technologies, Inc.
22
# pylint: disable=redefined-outer-name
33
from io import BytesIO
4+
import os
45
import mock
56
import pytest
67

@@ -77,12 +78,21 @@ def test_writer(wfile, writer):
7778
'method': 'method',
7879
'params': {}
7980
})
80-
assert wfile.getvalue() == (
81-
b'Content-Length: 44\r\n'
82-
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
83-
b'\r\n'
84-
b'{"id":"hello","method":"method","params":{}}'
85-
)
81+
82+
if os.name == 'nt':
83+
assert wfile.getvalue() == (
84+
b'Content-Length: 49\r\n'
85+
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
86+
b'\r\n'
87+
b'{"id": "hello", "method": "method", "params": {}}'
88+
)
89+
else:
90+
assert wfile.getvalue() == (
91+
b'Content-Length: 44\r\n'
92+
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
93+
b'\r\n'
94+
b'{"id":"hello","method":"method","params":{}}'
95+
)
8696

8797

8898
def test_writer_bad_message(wfile, writer):
@@ -97,9 +107,13 @@ def test_writer_bad_message(wfile, writer):
97107
minute=1,
98108
second=1,
99109
))
100-
assert wfile.getvalue() == (
101-
b'Content-Length: 10\r\n'
102-
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
103-
b'\r\n'
104-
b'1546304461'
105-
)
110+
111+
if os.name == 'nt':
112+
assert wfile.getvalue() == b''
113+
else:
114+
assert wfile.getvalue() == (
115+
b'Content-Length: 10\r\n'
116+
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
117+
b'\r\n'
118+
b'1546304461'
119+
)

0 commit comments

Comments
 (0)