summarylogtreecommitdiffstats
path: root/host.patch
blob: 99da42c32a74f935b362c8b559e9e1f84ddb264a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# HG changeset patch
# User Bitbucket <noreply@bitbucket.org>
# Date 0 0
# Node ID f1c61b7dab8a078193cb611920a14b65c5c9c6a8
# Parent  69fe424722f50cf74b9c1b5db1095f0430e22181
# Parent  c41d418c286245cf6161eefc9a5bff5ba9ba2404

diff -r 69fe424722f5 -r f1c61b7dab8a remote_ikernel/kernel.py
--- a/remote_ikernel/kernel.py
+++ b/remote_ikernel/kernel.py
@@ -18,6 +18,7 @@
 import uuid
 
 import pexpect
+import warnings
 
 from tornado.log import LogFormatter
 
@@ -173,6 +174,20 @@
 
     """
 
+    @property
+    def host(self):
+        return self._host
+
+    @host.setter
+    def host(self, new):
+        if isinstance(new, bytes):
+            warnings.warn('Automatically Decoding self.host assignment to bytes. Did you forget a `.decode()` ? ')
+            self._host = new.decode()
+        elif isinstance(new, str):
+            self._host = new
+        else:
+            raise TypeError('self.host can only be assigned `str` or `bytes`, not `{}`'.format(type(new)))
+
     def __init__(self, connection_info=None, interface='sge', cpus=1, pe='smp',
                  kernel_cmd='ipython kernel', workdir=None, tunnel=True,
                  host=None, precmd=None, launch_args=None, verbose=False,
@@ -196,7 +211,12 @@
         self.cpus = cpus
         self.pe = pe
         self.kernel_cmd = kernel_cmd
-        self.host = host  # Name of node to be changed once connection is ready.
+        self._host = ''
+        if not host :
+            self.host = ''
+        else:
+            self.host = host
+
         self.tunnel_hosts = tunnel_hosts
         self.connection = None  # will usually be a spawned pexpect
         self.workdir = workdir
@@ -331,10 +351,10 @@
         # hostnames whould be alphanumeric with . and - permitted
         # This way we also ignore the echoed echo command
         qsub_i.expect('Running on ([\w.-]+)')
-        node = qsub_i.match.groups()[0]
+        node = qsub_i.match.groups()[0] or b''
 
         self.log.info("Established session on node: {0}.".format(node))
-        self.host = node
+        self.host = node.decode()
 
     def launch_sge(self, qlogin='qlogin'):
         """
@@ -361,9 +381,9 @@
         # Hopefully this text is universal?
         qlogin.expect('Establishing .* session to host (.*) ...')
 
-        node = qlogin.match.groups()[0]
+        node = qlogin.match.groups()[0] or b''
         self.log.info("Established session on node: {0}.".format(node))
-        self.host = node
+        self.host = node.decode()
 
     def launch_slurm(self):
         """
@@ -390,9 +410,9 @@
         # Hopefully this text is universal?
         srun.expect('srun: Node (.*), .* tasks started')
 
-        node = srun.match.groups()[0]
+        node = srun.match.groups()[0] or b''
         self.log.info("Established session on node: {0}.".format(node))
-        self.host = node
+        self.host = node.decode()
 
     def launch_lsf(self):
         """
@@ -418,9 +438,9 @@
         # Hopefully this text is universal?
         bsub.expect('<<Starting on (.*)>>')
 
-        node = bsub.match.groups()[0]
+        node = bsub.match.groups()[0] or b''
         self.log.info("Established session on node: {0}.".format(node))
-        self.host = node
+        self.host = node.decode()
 
     def start_kernel(self):
         """
@@ -597,10 +617,6 @@
     @property
     def tunnel_cmd(self):
         """Return a tunnelling command that just needs a port."""
-        # zmq needs str in Python 3, but pexpect gives bytes
-        if hasattr(self.host, 'decode'):
-            self.host = self.host.decode('utf-8')
-
         # One connection can tunnel all the ports
         ports_str = " ".join(["-L 127.0.0.1:{{{port}}}:127.0.0.1:{{{port}}}"
                               "".format(port=port) for port in PORT_NAMES])
diff -r 69fe424722f5 -r f1c61b7dab8a setup.py
--- a/setup.py
+++ b/setup.py
@@ -7,10 +7,13 @@
     from distutils.core import setup
     scripts = ['bin/remote_ikernel']
 
+with open('README.rst') as f:
+    long_desc = f.read()
+
 setup(name='remote_ikernel',
       version='0.4.6',
       description='Running IPython kernels through batch queues',
-      long_description=open('README.rst').read(),
+      long_description=long_desc,
       author='Tom Daff',
       author_email='tdd20@cam.ac.uk',
       license='BSD',