##// END OF EJS Templates
Merge pull request #8272 from minrk/utils-data...
Matthias Bussonnier -
r21182:b3916ddc merge
parent child Browse files
Show More
@@ -24,9 +24,16 b' from IPython.nbformat.v4 import ('
24 )
24 )
25 from IPython.nbformat import v2
25 from IPython.nbformat import v2
26 from IPython.utils import py3compat
26 from IPython.utils import py3compat
27 from IPython.utils.data import uniq_stable
28 from IPython.utils.tempdir import TemporaryDirectory
27 from IPython.utils.tempdir import TemporaryDirectory
29
28
29 def uniq_stable(elems):
30 """uniq_stable(elems) -> list
31
32 Return from an iterable, a list of all the unique elements in the input,
33 maintaining the order in which they first appear.
34 """
35 seen = set()
36 return [x for x in elems if x not in seen and not seen.add(x)]
30
37
31 def notebooks_only(dir_model):
38 def notebooks_only(dir_model):
32 return [nb for nb in dir_model['content'] if nb['type']=='notebook']
39 return [nb for nb in dir_model['content'] if nb['type']=='notebook']
@@ -10,9 +10,9 b' except:'
10 cPickle = None
10 cPickle = None
11 import pickle
11 import pickle
12
12
13 # IPython imports
13 from itertools import chain
14
14 from IPython.utils.py3compat import PY3, buffer_to_bytes_py2
15 from IPython.utils.py3compat import PY3, buffer_to_bytes_py2
15 from IPython.utils.data import flatten
16 from ipython_kernel.pickleutil import (
16 from ipython_kernel.pickleutil import (
17 can, uncan, can_sequence, uncan_sequence, CannedObject,
17 can, uncan, can_sequence, uncan_sequence, CannedObject,
18 istype, sequence_types, PICKLE_PROTOCOL,
18 istype, sequence_types, PICKLE_PROTOCOL,
@@ -138,10 +138,12 b' def pack_apply_message(f, args, kwargs, buffer_threshold=MAX_BYTES, item_thresho'
138 With length at least two + len(args) + len(kwargs)
138 With length at least two + len(args) + len(kwargs)
139 """
139 """
140
140
141 arg_bufs = flatten(serialize_object(arg, buffer_threshold, item_threshold) for arg in args)
141 arg_bufs = list(chain.from_iterable(
142 serialize_object(arg, buffer_threshold, item_threshold) for arg in args))
142
143
143 kw_keys = sorted(kwargs.keys())
144 kw_keys = sorted(kwargs.keys())
144 kwarg_bufs = flatten(serialize_object(kwargs[key], buffer_threshold, item_threshold) for key in kw_keys)
145 kwarg_bufs = list(chain.from_iterable(
146 serialize_object(kwargs[key], buffer_threshold, item_threshold) for key in kw_keys))
145
147
146 info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys)
148 info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys)
147
149
@@ -12,10 +12,7 b' pieces to individual nodes in a cluster.'
12 from __future__ import division
12 from __future__ import division
13
13
14 import sys
14 import sys
15 from itertools import islice
15 from itertools import islice, chain
16
17 from IPython.utils.data import flatten as utils_flatten
18
19
16
20 numpy = None
17 numpy = None
21
18
@@ -75,7 +72,7 b' class Map(object):'
75 return numpy.concatenate(listOfPartitions)
72 return numpy.concatenate(listOfPartitions)
76 # Next try for Python sequence types
73 # Next try for Python sequence types
77 if isinstance(testObject, (list, tuple)):
74 if isinstance(testObject, (list, tuple)):
78 return utils_flatten(listOfPartitions)
75 return list(chain.from_iterable(listOfPartitions))
79 # If we have scalars, just return listOfPartitions
76 # If we have scalars, just return listOfPartitions
80 return listOfPartitions
77 return listOfPartitions
81
78
@@ -125,5 +122,3 b' def mappable(obj):'
125
122
126 dists = {'b':Map,'r':RoundRobinMap}
123 dists = {'b':Map,'r':RoundRobinMap}
127
124
128
129
@@ -1,6 +1,6 b''
1 """Utilities for identifying local IP addresses."""
1 """Utilities for identifying local IP addresses."""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) Jupyter Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import os
6 import os
@@ -8,7 +8,6 b' import re'
8 import socket
8 import socket
9 from subprocess import Popen, PIPE
9 from subprocess import Popen, PIPE
10
10
11 from IPython.utils.data import uniq_stable
12 from warnings import warn
11 from warnings import warn
13
12
14
13
@@ -17,6 +16,18 b' PUBLIC_IPS = []'
17
16
18 LOCALHOST = ''
17 LOCALHOST = ''
19
18
19
20 def _uniq_stable(elems):
21 """uniq_stable(elems) -> list
22
23 Return from an iterable, a list of all the unique elements in the input,
24 maintaining the order in which they first appear.
25
26 From IPython.utils.data
27 """
28 seen = set()
29 return [x for x in elems if x not in seen and not seen.add(x)]
30
20 def _get_output(cmd):
31 def _get_output(cmd):
21 """Get output of a command, raising IOError if it fails"""
32 """Get output of a command, raising IOError if it fails"""
22 p = Popen(cmd, stdout=PIPE, stderr=PIPE)
33 p = Popen(cmd, stdout=PIPE, stderr=PIPE)
@@ -69,8 +80,8 b' def _populate_from_list(addrs):'
69
80
70 local_ips.extend(['0.0.0.0', ''])
81 local_ips.extend(['0.0.0.0', ''])
71
82
72 LOCAL_IPS[:] = uniq_stable(local_ips)
83 LOCAL_IPS[:] = _uniq_stable(local_ips)
73 PUBLIC_IPS[:] = uniq_stable(public_ips)
84 PUBLIC_IPS[:] = _uniq_stable(public_ips)
74
85
75 def _load_ips_ifconfig():
86 def _load_ips_ifconfig():
76 """load ip addresses from `ifconfig` output (posix)"""
87 """load ip addresses from `ifconfig` output (posix)"""
@@ -145,8 +156,8 b' def _load_ips_netifaces():'
145 LOCALHOST = '127.0.0.1'
156 LOCALHOST = '127.0.0.1'
146 local_ips.insert(0, LOCALHOST)
157 local_ips.insert(0, LOCALHOST)
147 local_ips.extend(['0.0.0.0', ''])
158 local_ips.extend(['0.0.0.0', ''])
148 LOCAL_IPS[:] = uniq_stable(local_ips)
159 LOCAL_IPS[:] = _uniq_stable(local_ips)
149 PUBLIC_IPS[:] = uniq_stable(public_ips)
160 PUBLIC_IPS[:] = _uniq_stable(public_ips)
150
161
151
162
152 def _load_ips_gethostbyname():
163 def _load_ips_gethostbyname():
@@ -170,13 +181,13 b' def _load_ips_gethostbyname():'
170 except socket.error:
181 except socket.error:
171 pass
182 pass
172 finally:
183 finally:
173 PUBLIC_IPS[:] = uniq_stable(PUBLIC_IPS)
184 PUBLIC_IPS[:] = _uniq_stable(PUBLIC_IPS)
174 LOCAL_IPS.extend(PUBLIC_IPS)
185 LOCAL_IPS.extend(PUBLIC_IPS)
175
186
176 # include all-interface aliases: 0.0.0.0 and ''
187 # include all-interface aliases: 0.0.0.0 and ''
177 LOCAL_IPS.extend(['0.0.0.0', ''])
188 LOCAL_IPS.extend(['0.0.0.0', ''])
178
189
179 LOCAL_IPS[:] = uniq_stable(LOCAL_IPS)
190 LOCAL_IPS[:] = _uniq_stable(LOCAL_IPS)
180
191
181 LOCALHOST = LOCAL_IPS[0]
192 LOCALHOST = LOCAL_IPS[0]
182
193
General Comments 0
You need to be logged in to leave comments. Login now