Skip to content

Commit 5c04783

Browse files
committed
Merge pull request #226 in LCL/wolframclientforpython from bugfix/380061-removing-dependencies to master
* commit '7dde14645418c7f7ab6fc8ccbf09ccb2b06d1ba4': automatic code refactor Update lock.py when pkg_resources are not available we can return a tuple using dynamic import fixing external libraries using asyncio api fixing indent using dynamic import when calling cProfile
2 parents 1140f9b + 7dde146 commit 5c04783

11 files changed

Lines changed: 26 additions & 22 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
def read(*rellibpath):
3434
with codecs.open(os.path.join(HERE, *rellibpath), 'r', encoding='utf-8') as fp:
35-
return fp.read()
35+
return fp.read()
3636

3737
def load_tests():
3838
import unittest

wolframclient/cli/commands/benchmark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

3-
import cProfile
43
import decimal
54
import os
65
import tempfile
@@ -12,6 +11,7 @@
1211
from wolframclient.utils.debug import timed
1312
from wolframclient.utils.encoding import force_text
1413
from wolframclient.utils.functional import first
14+
from wolframclient.utils.importutils import safe_import_string_and_call
1515

1616

1717
def repeat(el, n=1):
@@ -125,6 +125,8 @@ def report(self):
125125

126126
def handle(self, profile, **opts):
127127
if profile:
128-
cProfile.runctx("report()", {"report": self.report}, {})
128+
safe_import_string_and_call(
129+
"cProfile.runctx", "report()", {"report": self.report}, {}
130+
)
129131
else:
130132
self.report()

wolframclient/evaluation/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

3-
import asyncio
43
import warnings
54

65
from wolframclient.language import wlexpr
76
from wolframclient.language.expression import WLFunction
87
from wolframclient.utils import six
8+
from wolframclient.utils.api import asyncio
99
from wolframclient.utils.functional import map
1010

1111

wolframclient/evaluation/cloud/asynccloudsession.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
XAuthAIOHttpAsyncSession as XAuthAsyncSession,
1212
)
1313
from wolframclient.evaluation.cloud.base import WolframAPICallBase
14-
from wolframclient.evaluation.cloud.server import WOLFRAM_PUBLIC_CLOUD_SERVER, DEFAULT_CA_PATH
14+
from wolframclient.evaluation.cloud.server import DEFAULT_CA_PATH, WOLFRAM_PUBLIC_CLOUD_SERVER
1515
from wolframclient.evaluation.result import (
1616
WolframAPIResponseBuilder,
1717
WolframEvaluationWXFResponseAsync,
@@ -70,7 +70,6 @@ def __init__(
7070
else:
7171
self._ssl_context = None
7272

73-
7473
def duplicate(self):
7574
return self.__class__(
7675
credentials=self.credentials,

wolframclient/evaluation/cloud/asyncoauth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

33
import logging
4+
45
from wolframclient.evaluation.cloud.base import OAuthAsyncSessionBase, UserIDPassword
56
from wolframclient.evaluation.cloud.server import DEFAULT_CA_PATH
67
from wolframclient.exception import AuthenticationException

wolframclient/evaluation/cloud/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

33
from wolframclient.utils import six
4+
45
try:
56
import certifi
7+
68
DEFAULT_CA_PATH = certifi.where()
79
except ImportError:
810
certifi = None

wolframclient/serializers/encoder.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
from collections import defaultdict
66
from functools import partial
77

8-
import pkg_resources
9-
108
from wolframclient.serializers.utils import safe_len
11-
from wolframclient.utils.api import multiprocessing
9+
from wolframclient.utils.api import multithreading, pkg_resources
1210
from wolframclient.utils.dispatch import Dispatch
1311
from wolframclient.utils.functional import composition, is_iterable, iterate, map
1412
from wolframclient.utils.importutils import safe_import_string
@@ -66,7 +64,7 @@ def _update_plugins(self):
6664
# global lock to avoid multiple dispatcher updating in multithreaded programs.
6765

6866
def update_dispatch(self):
69-
with multiprocessing.Lock():
67+
with multithreading.Lock():
7068
self._update_dispatch()
7169
self._update_plugins()
7270

wolframclient/tests/deserializers/wxf_deserialize.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ def test_bigreal_precision_exponent(self):
148148
self.assertEqual(res, decimal.Decimal("9.999999999999996843873323328588479844E+999"))
149149

150150
def test_bigreal_precision_negexponent(self):
151-
wxf = b'8:RC4.590261537982443550699999999999999999999281`19.66183743091127*^-16'
152-
res = binary_deserialize(wxf, consumer=WXFConsumer())
153-
self.assertEqual(res, decimal.Decimal('4.590261537982443550699999999999999999999281E-16'))
151+
wxf = b"8:RC4.590261537982443550699999999999999999999281`19.66183743091127*^-16"
152+
res = binary_deserialize(wxf, consumer=WXFConsumer())
153+
self.assertEqual(
154+
res, decimal.Decimal("4.590261537982443550699999999999999999999281E-16")
155+
)
154156

155157
def test_empty_lists(self):
156158
value = ((), ((),), (1, ()), ())

wolframclient/tests/evaluation/test_async_cloud.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ async def test_bad_sak_with(self):
143143

144144
def test_sslcontext(self):
145145
from wolframclient.evaluation.cloud.server import DEFAULT_CA_PATH
146+
146147
s = WolframCloudAsyncSession()
147148
if DEFAULT_CA_PATH is None:
148149
self.assertIsNone(s._ssl_context)

wolframclient/utils/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@
138138
PackedArray="wolframclient.utils.packedarray.PackedArray",
139139
)
140140

141-
multiprocessing = API(Lock="wolframclient.utils.lock.Lock")
141+
multithreading = API(Lock="wolframclient.utils.lock.Lock")
142+
pkg_resources = API(
143+
iter_entry_points=("pkg_resources.iter_entry_points", lambda *args, **opts: ())
144+
)
142145

143146
PIL = API(Image="PIL.Image.Image", fromarray="PIL.Image.fromarray", open="PIL.Image.open")
144147

@@ -168,10 +171,7 @@
168171
StringPayload="aiohttp.StringPayload",
169172
)
170173

171-
ssl = API(
172-
SSLContext="ssl.SSLContext",
173-
create_default_context="ssl.create_default_context",
174-
)
174+
ssl = API(SSLContext="ssl.SSLContext", create_default_context="ssl.create_default_context")
175175

176176
externalevaluate = API(
177177
execute_from_file="wolframclient.utils.externalevaluate.execute_from_file",

0 commit comments

Comments
 (0)