Skip to content

Commit

Permalink
remove support code for py26 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi authored and qinxuye committed Dec 10, 2018
1 parent bf80609 commit ffe539e
Show file tree
Hide file tree
Showing 42 changed files with 126 additions and 123 deletions.
3 changes: 2 additions & 1 deletion mars/actors/pool/tests/test_gevent_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import hashlib
import uuid
import time
import unittest

import gevent

from mars.compat import unittest, six, BrokenPipeError
from mars.compat import six, BrokenPipeError
from mars.actors import create_actor_pool as new_actor_pool, Actor, ActorNotExist, Distributor, new_client
from mars.actors.pool.gevent_pool import Dispatcher, Connections
from mars.utils import to_binary
Expand Down
60 changes: 8 additions & 52 deletions mars/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@

from ..lib import six

PY26 = six.PY2 and sys.version_info[1] == 6
PY27 = six.PY2 and sys.version_info[1] == 7
LESS_PY26 = sys.version_info[:2] < (2, 6)
LESS_PY32 = sys.version_info[:2] < (3, 2)
LESS_PY33 = sys.version_info[:2] < (3, 3)
LESS_PY34 = sys.version_info[:2] < (3, 4)
LESS_PY35 = sys.version_info[:2] < (3, 5)
PYPY = platform.python_implementation().lower() == 'pypy'

SEEK_SET = 0
Expand Down Expand Up @@ -71,23 +65,21 @@
StringIO = io.StringIO
BytesIO = io.BytesIO

if LESS_PY34:
if PY27:
from ..lib import enum
else:
import enum

if LESS_PY33:
if PY27:
try:
import cdecimal as decimal

DECIMAL_TYPES.append(decimal.Decimal)
except:
except ImportError:
import decimal
else:
import decimal

import unittest
import unittest.mock as mock
from collections import OrderedDict

OrderedDict3 = OrderedDict
Expand Down Expand Up @@ -176,36 +168,12 @@ def east_asian_len(data, encoding=None, ambiguous_width=1):
else:
return len(data)

if PY26:
warnings.warn('Python 2.6 is no longer supported by the Python core team. A future version of Mars ' +
'will drop support for this version.')

try:
import unittest2 as unittest
import unittest2.mock as mock
except ImportError:
pass

try:
from ordereddict import OrderedDict
except ImportError:
raise

def total_seconds(self):
return self.days * 86400.0 + self.seconds + self.microseconds * 1.0e-6
else:
try:
import unittest
import mock
except ImportError:
pass

from collections import OrderedDict
from collections import OrderedDict

dictconfig = lambda config: logging.config.dictConfig(config)
dictconfig = lambda config: logging.config.dictConfig(config)

from datetime import timedelta
total_seconds = timedelta.total_seconds
from datetime import timedelta
total_seconds = timedelta.total_seconds

import __builtin__ as builtins # don't remove
from ..lib import futures # don't remove
Expand Down Expand Up @@ -244,18 +212,6 @@ def accumulate(iterable, func=lambda a, b: a + b):
total = func(total, element)
yield total

if PY26:
try:
import simplejson as json
except ImportError:
pass
if PY26 or LESS_PY32:
try:
from .tests.dictconfig import dictConfig
dictconfig = lambda config: dictConfig(config)
except ImportError:
pass

if six.PY3:
from contextlib import suppress
else:
Expand Down Expand Up @@ -482,7 +438,7 @@ def _exitfunc(cls):
gc.enable()


__all__ = ['sys', 'builtins', 'logging.config', 'unittest', 'mock', 'OrderedDict', 'dictconfig', 'suppress',
__all__ = ['sys', 'builtins', 'logging.config', 'OrderedDict', 'dictconfig', 'suppress',
'reduce', 'reload_module', 'Queue', 'PriorityQueue', 'Empty', 'ElementTree', 'ElementTreeParseError',
'urlretrieve', 'pickle', 'urlencode', 'urlparse', 'unquote', 'quote', 'quote_plus', 'parse_qsl',
'Enum', 'ConfigParser', 'decimal', 'Decimal', 'DECIMAL_TYPES', 'FixedOffset', 'utc', 'finalize',
Expand Down
16 changes: 15 additions & 1 deletion mars/lib/sparse/tests/test_coo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 1999-2018 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np

from mars.lib.sparse.core import issparse
import mars.lib.sparse as mls
from mars.tests.core import TestBase
from mars.compat import unittest

DEBUG = True

Expand Down
4 changes: 2 additions & 2 deletions mars/lib/sparse/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np
import scipy.sparse as sps

from mars.compat import unittest
from mars.tests.core import TestBase
from mars.compat import unittest
from mars.lib.sparse import SparseNDArray
from mars.lib.sparse.core import issparse
import mars.lib.sparse as mls
Expand Down
3 changes: 2 additions & 1 deletion mars/scheduler/tests/test_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import uuid

import gevent

from mars.cluster_info import ClusterInfoActor
from mars.scheduler import ResourceActor, AssignerActor, KVStoreActor
from mars.actors import FunctionActor, create_actor_pool
from mars.compat import unittest


class PromiseReplyTestActor(FunctionActor):
Expand Down
3 changes: 2 additions & 1 deletion mars/scheduler/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# limitations under the License.

import uuid
import unittest

import gevent

import mars.tensor as mt
from mars.cluster_info import ClusterInfoActor
from mars.scheduler import GraphActor, ResourceActor, KVStoreActor, AssignerActor
from mars.utils import serialize_graph, deserialize_graph
from mars.actors import create_actor_pool
from mars.compat import unittest


class Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion mars/scheduler/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import uuid
import json
import signal
import unittest

import numpy as np
from numpy.testing import assert_array_equal
import gevent

from mars.serialize.dataserializer import loads
from mars.config import options
from mars.compat import unittest
from mars.tensor.expressions.datasource import ones
from mars.utils import get_next_port
from mars.actors.core import new_client
Expand Down
3 changes: 2 additions & 1 deletion mars/scheduler/tests/test_operand.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import sys
import time
import unittest
import uuid
from collections import defaultdict

Expand All @@ -26,7 +27,7 @@
from mars.scheduler import OperandActor, ResourceActor, GraphActor, AssignerActor, KVStoreActor
from mars.utils import serialize_graph, deserialize_graph
from mars.actors import create_actor_pool
from mars.compat import unittest, mock
from mars.tests.core import mock


class FakeExecutionActor(promise.PromiseActor):
Expand Down
3 changes: 2 additions & 1 deletion mars/scheduler/tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import uuid

import gevent

from mars.scheduler import ResourceActor
from mars.actors import create_actor_pool
from mars.compat import unittest


class Test(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion mars/serialize/tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import json
import os
import tempfile
import unittest

import numpy as np

Expand All @@ -25,7 +26,7 @@
except ImportError:
pyarrow = None

from mars.compat import unittest, six, OrderedDict, BytesIO
from mars.compat import six, OrderedDict, BytesIO
from mars.lib import sparse
from mars.serialize.core import Serializable, IdentityField, StringField, Int32Field, BytesField, \
KeyField, ReferenceField, OneOfField, ListField, NDArrayField, DictField, TupleField, \
Expand Down
9 changes: 5 additions & 4 deletions mars/tensor/execution/optimizes/tests/test_compose.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 1999-2018 Alibaba Group Holding Ltd.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from mars.compat import lmap
from mars.compat import unittest
from mars.tensor.execution.core import Executor
from mars.tensor.expressions.arithmetic import TensorTreeAdd
from mars.tensor.expressions.indexing import TensorSlice
Expand Down
4 changes: 3 additions & 1 deletion mars/tensor/execution/tests/test_arithmetic_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np
import scipy.sparse as sps

from mars.compat import unittest, six
from mars.compat import six
from mars.tensor.execution.core import Executor
from mars.tensor.expressions.datasource import ones, tensor, zeros
from mars.tensor.expressions.arithmetic import add, truediv, frexp, \
Expand Down
3 changes: 2 additions & 1 deletion mars/tensor/execution/tests/test_base_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np
import scipy.sparse as sps

from mars.compat import unittest
from mars.tensor.execution.core import Executor
from mars import tensor as mt
from mars.tensor.expressions.datasource import tensor, ones, zeros, arange
Expand Down
3 changes: 2 additions & 1 deletion mars/tensor/execution/tests/test_core_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mars.compat import unittest
import unittest

from mars.tensor.execution.core import Executor
from mars.tensor import ones
from mars.session import LocalSession, Session
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/execution/tests/test_cupy_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from mars.compat import unittest
from mars.tensor.execution.core import Executor
from mars.tensor.execution.cp import _evaluate
from mars.tensor.expressions.datasource import ones
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/execution/tests/test_fft_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np

from mars.compat import unittest
from mars.tensor.execution.core import Executor
from mars.tensor.expressions.datasource import tensor
from mars.tensor.expressions.fft import fft, ifft, fft2, ifft2, fftn, ifftn, rfft, irfft, rfft2, irfft2, \
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/execution/tests/test_index_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np
import scipy.sparse as sps

from mars.compat import unittest
from mars.tensor.execution.core import Executor
from mars.tensor.expressions.datasource import tensor, arange
from mars.tensor.expressions.indexing import take, compress, extract, choose, \
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/execution/tests/test_linalg_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np
import scipy.sparse as sps

from mars.compat import unittest
from mars.tensor.execution.core import Executor
from mars.tensor.expressions.datasource import tensor, diag, ones, arange
from mars.tensor.expressions.linalg import qr, svd, cholesky, norm, lu, \
Expand Down

0 comments on commit ffe539e

Please sign in to comment.