Repository: mars-project/mars

Issue:
`.execute()` code completion?
How to set `.execute()`  to code completion?  Write code faster？
`.execute()` code completion?
How to set `.execute()`  to code completion?  Write code faster？


Discussion:
Currently this method is provided by ```__getattr__``` in Tensor class. We will add it as a method in the next release and then code completion should not be a problem.
Already solved in #226, either try to install from master or wait for the next releases.
Currently this method is provided by ```__getattr__``` in Tensor class. We will add it as a method in the next release and then code completion should not be a problem.
Already solved in #226, either try to install from master or wait for the next releases.

Resolving patch:
diff --git a/mars/tensor/core.py b/mars/tensor/core.py
--- a/mars/tensor/core.py
+++ b/mars/tensor/core.py
@@ -519,6 +519,13 @@ class Tensor(Entity):
     __slots__ = ()
     _allow_data_type_ = (TensorData,)
 
+    def __dir__(self):
+        from ..lib.lib_utils import dir2
+        obj_dir = dir2(self)
+        if self._data is not None:
+            obj_dir = sorted(set(dir(self._data) + obj_dir))
+        return obj_dir
+
     def __len__(self):
         return len(self._data)
 
@@ -565,6 +572,9 @@ def imag(self, new_imag):
     def __array__(self, dtype=None):
         return np.asarray(self.execute(), dtype=dtype)
 
+    def execute(self, session=None, **kw):
+        return self._data.execute(session, **kw)
+
 
 class SparseTensor(Tensor):
     __slots__ = ()


Test patch:
diff --git a/mars/scheduler/tests/test_kvstore.py b/mars/scheduler/tests/test_kvstore.py
--- a/mars/scheduler/tests/test_kvstore.py
+++ b/mars/scheduler/tests/test_kvstore.py
@@ -24,6 +24,10 @@
 
 
 class Test(unittest.TestCase):
+    def tearDown(self):
+        super(Test, self).tearDown()
+        options.kv_store = ':inproc:'
+
     @unittest.skipIf(sys.platform == 'win32', 'does not run in windows')
     def testKVStoreActor(self):
         etcd_port = get_next_port()
diff --git a/mars/scheduler/tests/test_main.py b/mars/scheduler/tests/test_main.py
--- a/mars/scheduler/tests/test_main.py
+++ b/mars/scheduler/tests/test_main.py
@@ -68,7 +68,7 @@ def tearDown(self):
 
         check_time = time.time()
         while any(p.poll() is None for p in procs):
-            time.sleep(1)
+            time.sleep(0.1)
             if time.time() - check_time > 5:
                 break
 
@@ -78,6 +78,7 @@ def tearDown(self):
 
         if self.etcd_helper:
             self.etcd_helper.stop()
+        options.kv_store = ':inproc:'
 
     def start_processes(self, n_schedulers=1, n_workers=2, etcd=False, modules=None):
         old_not_errors = gevent.hub.Hub.NOT_ERROR
diff --git a/mars/tensor/expressions/tests/test_base.py b/mars/tensor/expressions/tests/test_base.py
--- a/mars/tensor/expressions/tests/test_base.py
+++ b/mars/tensor/expressions/tests/test_base.py
@@ -35,6 +35,12 @@ def testArray(self):
         c = asarray(a)
         self.assertIs(a, c)
 
+    def testDir(self):
+        a = tensor([0, 1, 2], chunk_size=2)
+        tensor_dir = dir(a)
+        for attr in dir(a.data):
+            self.assertIn(attr, tensor_dir)
+
     def testCopyto(self):
         a = ones((10, 20), chunk_size=3)
         b = ones(10, chunk_size=4)