Skip to content

Commit 4016fa4

Browse files
author
Dorian Birraux
committed
Merge branch 'master' into feature/preparing-release-1.1.0
2 parents 0b9167c + 90f5e16 commit 4016fa4

18 files changed

Lines changed: 128 additions & 171 deletions

File tree

wolframclient/cli/commands/refactor.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66

77
from wolframclient.cli.utils import SimpleCommand
8-
from wolframclient.utils.importutils import module_path
8+
from wolframclient.utils.importutils import module_path, safe_import_string_and_call
99

1010

1111
class Command(SimpleCommand):
@@ -24,42 +24,40 @@ def _module_args(self, *args):
2424
for arg in args:
2525
yield arg
2626

27-
def handle(self, **opts):
27+
def run(self, path, *args):
28+
originals = sys.argv
29+
sys.argv = list(self._module_args(*args))
30+
safe_import_string_and_call(path)
31+
sys.argv = originals
2832

29-
argv = sys.argv
33+
def handle(self, **opts):
3034

31-
from autoflake import main
35+
# autoflake is not removing imports if they are in a list
36+
# to fix this we first refactor the code using imports in single line
3237

33-
sys.argv = list(
34-
self._module_args(
35-
"--in-place",
36-
"--remove-duplicate-keys",
37-
"--expand-star-import",
38-
"--remove-all-unused-imports",
39-
"--recursive",
40-
)
38+
self.run(
39+
"isort.main.main",
40+
"-rc",
41+
"-sl",
42+
"-a",
43+
"from __future__ import absolute_import, print_function, unicode_literals",
4144
)
4245

43-
main()
46+
# then we remove all missing imports and we expand star imports
4447

45-
from isort.main import main
46-
47-
sys.argv = list(
48-
self._module_args(
49-
"-rc",
50-
"--multi-line",
51-
"5",
52-
"-a",
53-
"from __future__ import absolute_import, print_function, unicode_literals",
54-
)
48+
self.run(
49+
"autoflake.main",
50+
"--in-place",
51+
"--remove-duplicate-keys",
52+
"--expand-star-import",
53+
"--remove-all-unused-imports",
54+
"--recursive",
5555
)
5656

57-
main()
58-
59-
from black import main
57+
# then we use refactor imports again using pretty newline style
6058

61-
sys.argv = list(self._module_args("--line-length", "95", "--target-version", "py34"))
59+
self.run("isort.main.main", "-rc", "--multi-line", "5")
6260

63-
main()
61+
# after that we finally run black to refactor all code
6462

65-
sys.argv = argv
63+
self.run("black.main", "--line-length", "95", "--target-version", "py34")

wolframclient/deserializers/wxf/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def binary_deserialize(wxf_input, consumer=None, **kwargs):
2424
A stream of :class:`~wolframclient.deserializers.wxf.wxfparser.WXFToken` is generated from the WXF input by a instance
2525
of :class:`~wolframclient.deserializers.wxf.wxfparser.WXFParser`.
2626
27-
The consumer must be an instance of :class:`~wolframclient.deserializers.wxf.wxfconsumer.WXFConsumerNumpy`. If none is
28-
provided, :class:`~wolframclient.deserializers.wxf.wxfconsumer.WXFConsumer` is used. To disable NumPy array support,
27+
The consumer must be an instance of :class:`~wolframclient.deserializers.wxf.wxfconsumer.WXFConsumer`. If none is
28+
provided, :class:`~wolframclient.deserializers.wxf.wxfconsumer.WXFConsumerNumpy` is used. To disable NumPy array support,
2929
use :class:`~wolframclient.deserializers.wxf.wxfconsumer.WXFConsumer`.
3030
3131
Named parameters are passed to the consumer. They can be any valid parameter of

wolframclient/evaluation/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@
2323
)
2424

2525
__all__ = [
26-
"WolframAPICall",
27-
"WolframServer",
28-
"WolframCloudSession",
29-
"WolframCloudAsyncSession",
30-
"WolframAPICall",
3126
"SecuredAuthenticationKey",
3227
"UserIDPassword",
33-
"WolframLanguageSession",
34-
"WolframLanguageAsyncSession",
35-
"WolframResult",
36-
"WolframKernelEvaluationResult",
28+
"WolframAPICall",
29+
"WolframAPICall",
30+
"WolframAPICallAsync",
3731
"WolframAPIResponse",
32+
"WolframAPIResponseAsync",
33+
"WolframCloudAsyncSession",
3834
"WolframCloudEvaluationJSONResponse",
35+
"WolframCloudSession",
36+
"WolframEvaluationJSONResponseAsync",
3937
"WolframEvaluatorPool",
38+
"WolframKernelEvaluationResult",
39+
"WolframLanguageAsyncSession",
40+
"WolframLanguageSession",
41+
"WolframResult",
42+
"WolframServer",
4043
"parallel_evaluate",
4144
]

wolframclient/language/expression.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def __init__(self, head, *args, **opts):
8080
def __hash__(self):
8181
return hash((self.head, self.args))
8282

83+
def __getitem__(self, i):
84+
return self.args.__getitem__(i)
85+
8386
def __eq__(self, other):
8487
return (
8588
isinstance(other, WLFunction)
@@ -128,7 +131,7 @@ def __init__(self, name=None):
128131
self.name = name
129132

130133
def __getattr__(self, attr):
131-
# summing a tuple with another tuple is returning a new immutable tuple, this operation is always creating a new immutable symbol factory
134+
# this operation is always creating a new immutable symbol factory
132135
return self.__class__(self.name and "%s`%s" % (self.name, attr) or attr)
133136

134137

wolframclient/serializers/wxf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from wolframclient.serializers.base import FormatSerializer
88
from wolframclient.serializers.utils import py_encode_decimal, safe_len
99
from wolframclient.serializers.wxfencoder.constants import (
10-
ARRAY_TYPES,
1110
WXF_CONSTANTS,
1211
WXF_HEADER_COMPRESS,
1312
WXF_HEADER_SEPARATOR,
@@ -20,7 +19,6 @@
2019
numeric_array_to_wxf,
2120
packed_array_to_wxf,
2221
varint_bytes,
23-
write_varint,
2422
)
2523
from wolframclient.utils import six
2624
from wolframclient.utils.api import zlib

wolframclient/serializers/wxfencoder/wxfexpr.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
from wolframclient.serializers.wxfencoder.constants import (
66
VALID_PACKED_ARRAY_TYPES,
77
WXF_CONSTANTS,
8-
StructDouble,
9-
StructInt8LE,
10-
StructInt16LE,
11-
StructInt32LE,
12-
StructInt64LE,
138
)
149
from wolframclient.serializers.wxfencoder.serializer import WXFSerializerException
1510
from wolframclient.serializers.wxfencoder.utils import (

wolframclient/serializers/wxfencoder/wxfnumpyencoder.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
from __future__ import absolute_import, print_function, unicode_literals
44

5-
from wolframclient.serializers.wxfencoder.constants import (
6-
ARRAY_TYPES,
7-
WXF_CONSTANTS,
8-
WXF_HEADER_COMPRESS,
9-
WXF_HEADER_SEPARATOR,
10-
WXF_VERSION,
11-
)
5+
from wolframclient.serializers.wxfencoder.constants import ARRAY_TYPES
126
from wolframclient.serializers.wxfencoder.wxfencoder import WXFEncoder
137
from wolframclient.serializers.wxfencoder.wxfexpr import (
148
WXFExprNumericArray,

wolframclient/tests/configure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import json
66
import logging
7+
import unittest
78

89
from wolframclient.utils import six
910
from wolframclient.utils.api import os
@@ -109,4 +110,9 @@ def _parse_config(config):
109110
except IOError:
110111
raise ValueError("Failed to find json configuration file %s" % _json_config_path)
111112

112-
MSG_JSON_NOT_FOUND = "Environment variable WOLFRAMCLIENT_PY_JSON_CONFIG not set."
113+
114+
skip_for_jython = unittest.skipIf(six.JYTHON, "Currently not supported in jython")
115+
116+
skip_for_missing_config = unittest.skipIf(
117+
json_config is None, "Environment variable WOLFRAMCLIENT_PY_JSON_CONFIG not set."
118+
)

wolframclient/tests/core_functions.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44

55
from wolframclient.utils import six
66
from wolframclient.utils.dispatch import Dispatch
7-
from wolframclient.utils.functional import (
8-
composition,
9-
flatten,
10-
iterate,
11-
map,
12-
partition,
13-
riffle,
14-
)
7+
from wolframclient.utils.functional import composition, flatten, iterate, partition, riffle
158
from wolframclient.utils.tests import TestCase as BaseTestCase
169

1710

wolframclient/tests/deserializers/wxf_deserialize.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import decimal
66
import os
7-
import unittest
87

98
from wolframclient.deserializers import (
109
WXFConsumer,
@@ -16,6 +15,7 @@
1615
from wolframclient.exception import WolframParserException
1716
from wolframclient.serializers import export
1817
from wolframclient.serializers.wxfencoder.utils import write_varint
18+
from wolframclient.tests.configure import skip_for_jython
1919
from wolframclient.utils import six
2020
from wolframclient.utils.api import numpy
2121
from wolframclient.utils.tests import TestCase as BaseTestCase
@@ -108,27 +108,27 @@ def test_all_char(self):
108108
self.assertEqual(res, all_char)
109109

110110
### INTEGER TESTS
111-
@unittest.skipIf(six.JYTHON, None)
111+
@skip_for_jython
112112
def test_integer8(self):
113113
value = (0, 1, 127, -1, -128)
114114
self.wxf_assert_roundtrip(value)
115115

116-
@unittest.skipIf(six.JYTHON, None)
116+
@skip_for_jython
117117
def test_int16(self):
118118
value = (-(1 << 15), (1 << 15) - 1)
119119
self.wxf_assert_roundtrip(value)
120120

121-
@unittest.skipIf(six.JYTHON, None)
121+
@skip_for_jython
122122
def test_int32(self):
123123
value = (-(1 << 31), (1 << 31) - 1)
124124
self.wxf_assert_roundtrip(value)
125125

126-
@unittest.skipIf(six.JYTHON, None)
126+
@skip_for_jython
127127
def test_int64(self):
128128
value = (-(1 << 63), (1 << 63) - 1)
129129
self.wxf_assert_roundtrip(value)
130130

131-
@unittest.skipIf(six.JYTHON, None)
131+
@skip_for_jython
132132
def test_bigint_as_int(self):
133133
value = 10 ** 20
134134
self.wxf_assert_roundtrip(value)
@@ -232,7 +232,7 @@ def test_bad_wxf_buffer(self):
232232
binary_deserialize(wxf, consumer=WXFConsumer())
233233

234234

235-
@unittest.skipIf(six.JYTHON, "numpy is not supported in jython")
235+
@skip_for_jython
236236
class TestCaseNumPyArray(BaseTestCase):
237237
def test_numpy_1d_array(self):
238238
arr = numpy.array([0, 1], "uint8")

0 commit comments

Comments
 (0)