Permalink
Browse files

eliminate relative imports

  • Loading branch information...
1 parent 4f574e1 commit a0bfb1f70d5c3300a322d126618cbb2fcb836395 @minrk minrk committed Mar 6, 2011
@@ -100,7 +100,7 @@ def __init__(self, unSerialized):
self.typeDescriptor = 'ndarray'
self.metadata = {'shape':self.obj.shape,
'dtype':self.obj.dtype.str}
- elif isinstance(self.obj, str):
+ elif isinstance(self.obj, bytes):
self.typeDescriptor = 'bytes'
self.metadata = {}
elif isinstance(self.obj, buffer):
@@ -109,7 +109,7 @@ def __init__(self, unSerialized):
else:
self.typeDescriptor = 'pickle'
self.metadata = {}
- self._generateData()
+ self._generateData()
def _generateData(self):
if self.typeDescriptor == 'ndarray':
@@ -145,11 +145,13 @@ def __init__(self, serialized):
def getObject(self):
typeDescriptor = self.serialized.getTypeDescriptor()
if globals().has_key('numpy') and typeDescriptor == 'ndarray':
- result = numpy.frombuffer(self.serialized.getData(), dtype = self.serialized.metadata['dtype'])
+ buf = self.serialized.getData()
+ if isinstance(buf, buffer):
+ result = numpy.frombuffer(buf, dtype = self.serialized.metadata['dtype'])
+ else:
+ # memoryview
+ result = numpy.array(buf, dtype = self.serialized.metadata['dtype'])
result.shape = self.serialized.metadata['shape']
- # numpy arrays with frombuffer are read-only. We are working with
- # the numpy folks to address this issue.
- # result = result.copy()
elif typeDescriptor == 'pickle':
result = pickle.loads(self.serialized.getData())
elif typeDescriptor in ('bytes', 'buffer'):
@@ -13,7 +13,7 @@
import time
from IPython.external.decorator import decorator
-import error
+from . import error
#-----------------------------------------------------------------------------
# Classes
@@ -29,15 +29,15 @@
from IPython.external.decorator import decorator
from IPython.external.ssh import tunnel
-import error
-import map as Map
-import streamsession as ss
-from asyncresult import AsyncResult, AsyncMapResult, AsyncHubResult
-from clusterdir import ClusterDir, ClusterDirError
-from dependency import Dependency, depend, require, dependent
-from remotefunction import remote,parallel,ParallelFunction,RemoteFunction
-from util import ReverseDict, disambiguate_url, validate_url
-from view import DirectView, LoadBalancedView
+from . import error
+from . import map as Map
+from . import streamsession as ss
+from .asyncresult import AsyncResult, AsyncMapResult, AsyncHubResult
+from .clusterdir import ClusterDir, ClusterDirError
+from .dependency import Dependency, depend, require, dependent
+from .remotefunction import remote,parallel,ParallelFunction,RemoteFunction
+from .util import ReverseDict, disambiguate_url, validate_url
+from .view import DirectView, LoadBalancedView
#--------------------------------------------------------------------------
# helpers for implementing old MEC API via client.apply
@@ -23,9 +23,9 @@
from IPython.utils.importstring import import_item
from IPython.utils.traitlets import Int, Str, Instance, List, Bool
-from entry_point import signal_children
-from hub import Hub, HubFactory
-from scheduler import launch_scheduler
+from .entry_point import signal_children
+from .hub import Hub, HubFactory
+from .scheduler import launch_scheduler
#-----------------------------------------------------------------------------
# Configurable
@@ -2,8 +2,8 @@
from IPython.external.decorator import decorator
-from asyncresult import AsyncResult
-from error import UnmetDependency
+from .asyncresult import AsyncResult
+from .error import UnmetDependency
class depend(object):
@@ -19,11 +19,11 @@
from IPython.utils.traitlets import Instance, Str, Dict, Int, Type, CFloat
# from IPython.utils.localinterfaces import LOCALHOST
-import heartmonitor
-from factory import RegistrationFactory
-from streamkernel import Kernel
-from streamsession import Message
-from util import disambiguate_url
+from . import heartmonitor
+from .factory import RegistrationFactory
+from .streamkernel import Kernel
+from .streamsession import Message
+from .util import disambiguate_url
def printer(*msg):
# print (self.log.handlers, file=sys.__stdout__)
@@ -23,6 +23,7 @@
# System library imports.
import zmq
from zmq.log import handlers
+
# Local imports.
from IPython.core.ultratb import FormattedTB
from IPython.external.argparse import ArgumentParser
@@ -215,7 +215,7 @@ def _get_engine_str(self, ei):
if not ei:
return '[Engine Exception]'
else:
- return '[%s:%s]: ' % (ei['engineid'], ei['method'])
+ return '[%s:%s]: ' % (ei['engine_id'], ei['method'])
def _get_traceback(self, ev):
try:
@@ -14,7 +14,7 @@
from zmq.eventloop import ioloop, zmqstream
from IPython.utils.traitlets import Set, Instance, CFloat, Bool
-from factory import LoggingFactory
+from .factory import LoggingFactory
class Heart(object):
"""A basic heart object for responding to a HeartMonitor.
@@ -29,12 +29,12 @@
from IPython.utils.importstring import import_item
from IPython.utils.traitlets import HasTraits, Instance, Int, CStr, Str, Dict, Set, List, Bool
-from entry_point import select_random_ports
-from factory import RegistrationFactory, LoggingFactory
+from .entry_point import select_random_ports
+from .factory import RegistrationFactory, LoggingFactory
-from heartmonitor import HeartMonitor
-from streamsession import Message, wrap_exception, ISO8601
-from util import validate_url_container
+from .heartmonitor import HeartMonitor
+from .streamsession import Message, wrap_exception, ISO8601
+from .util import validate_url_container
try:
from pymongo.binary import Binary
@@ -36,10 +36,10 @@
ApplicationWithClusterDir,
ClusterDirConfigLoader
)
+from IPython.zmq.parallel.util import disambiguate_ip_address, split_url
# from IPython.kernel.fcutil import FCServiceFactory, FURLError
from IPython.utils.traitlets import Instance, Unicode
-from util import disambiguate_ip_address, split_url
#-----------------------------------------------------------------------------
@@ -31,9 +31,9 @@
from IPython.zmq.parallel import factory
from IPython.zmq.parallel.engine import EngineFactory
from IPython.zmq.parallel.streamkernel import Kernel
+from IPython.zmq.parallel.util import disambiguate_url
from IPython.utils.importstring import import_item
-from util import disambiguate_url
#-----------------------------------------------------------------------------
# Module level variables
@@ -24,7 +24,7 @@
ApplicationWithClusterDir,
ClusterDirConfigLoader
)
-from IPython.zmq.parallel.logwatcher import LogWatcher
+from .logwatcher import LogWatcher
#-----------------------------------------------------------------------------
# Module level variables
@@ -1,7 +1,8 @@
"""KernelStarter class that intercepts Control Queue messages, and handles process management."""
from zmq.eventloop import ioloop
-from streamsession import StreamSession
+
+from .streamsession import StreamSession
class KernelStarter(object):
"""Object for resetting/killing the Kernel."""
@@ -48,7 +48,7 @@ def check_output(*args, **kwargs):
from IPython.utils.path import get_ipython_module_path
from IPython.utils.process import find_cmd, pycmd2argv, FindCmdError
-from factory import LoggingFactory
+from .factory import LoggingFactory
# load winhpcjob from IPython.kernel
try:
@@ -21,7 +21,7 @@
from IPython.utils.traitlets import Int, Str, Instance, List
-from factory import LoggingFactory
+from .factory import LoggingFactory
#-----------------------------------------------------------------------------
# Classes
@@ -10,7 +10,7 @@
from pymongo import Connection
-from dictdb import BaseDB
+from .dictdb import BaseDB
#-----------------------------------------------------------------------------
# MongoDB class
@@ -14,8 +14,8 @@
from IPython.testing import decorators as testdec
-import map as Map
-from asyncresult import AsyncMapResult
+from . import map as Map
+from .asyncresult import AsyncMapResult
#-----------------------------------------------------------------------------
# Decorators
@@ -30,11 +30,11 @@
from IPython.external.decorator import decorator
from IPython.utils.traitlets import Instance, Dict, List, Set
-import error
-import streamsession as ss
-from dependency import Dependency
-from entry_point import connect_logger, local_logger
-from factory import SessionFactory
+from . import error
+from . import streamsession as ss
+from .dependency import Dependency
+from .entry_point import connect_logger, local_logger
+from .factory import SessionFactory
@decorator
@@ -33,10 +33,10 @@
from IPython.zmq.iostream import OutStream
from IPython.zmq.displayhook import DisplayHook
-import heartmonitor
-from client import Client
-from factory import SessionFactory
-from streamsession import StreamSession, Message, extract_header, serialize_object,\
+from . import heartmonitor
+from .client import Client
+from .factory import SessionFactory
+from .streamsession import StreamSession, Message, extract_header, serialize_object,\
unpack_apply_message, ISO8601, wrap_exception
def printer(*args):
@@ -24,7 +24,7 @@
from IPython.utils.pickleutil import can, uncan, canSequence, uncanSequence
from IPython.utils.newserialized import serialize, unserialize
-from IPython.zmq.parallel.error import RemoteError
+from .error import RemoteError
# packer priority: jsonlib[2], cPickle, simplejson/json, pickle
json_name = '' if not jsonapi.jsonmod else jsonapi.jsonmod.__name__
@@ -14,9 +14,10 @@
from IPython.utils.traitlets import HasTraits, Bool, List, Dict, Set, Int, Instance
from IPython.external.decorator import decorator
-from IPython.zmq.parallel.asyncresult import AsyncResult
-from IPython.zmq.parallel.dependency import Dependency
-from IPython.zmq.parallel.remotefunction import ParallelFunction, parallel, remote
+
+from .asyncresult import AsyncResult
+from .dependency import Dependency
+from .remotefunction import ParallelFunction, parallel, remote
#-----------------------------------------------------------------------------
# Decorators
@@ -405,15 +406,32 @@ def map(self, f, *sequences, **kwargs):
@sync_results
@save_ids
- def execute(self, code, block=True):
+ def execute(self, code, block=None):
"""execute some code on my targets."""
+
+ block = block if block is not None else self.block
+
return self.client.execute(code, block=block, targets=self._targets)
+ @sync_results
+ @save_ids
+ def run(self, fname, block=None):
+ """execute the code in a file on my targets."""
+
+ block = block if block is not None else self.block
+
+ return self.client.run(fname, block=block, targets=self._targets)
+
def update(self, ns):
"""update remote namespace with dict `ns`"""
return self.client.push(ns, targets=self._targets, block=self.block)
- push = update
+ def push(self, ns, block=None):
+ """update remote namespace with dict `ns`"""
+
+ block = block if block is not None else self.block
+
+ return self.client.push(ns, targets=self._targets, block=block)
def get(self, key_s):
"""get object(s) by `key_s` from remote namespace
Oops, something went wrong.

0 comments on commit a0bfb1f

Please sign in to comment.