From d6d13ee50653d857d1284e892d5b1c33ab64dbb6 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 12 Aug 2016 04:29:11 +0100 Subject: [PATCH] Rationalize _fixup_package(), fix _setup_master() name. --- econtext/core.py | 25 ++++++++++++++----------- econtext/master.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/econtext/core.py b/econtext/core.py index 5e756557..06f8f643 100644 --- a/econtext/core.py +++ b/econtext/core.py @@ -679,14 +679,17 @@ class Broker(object): class ExternalContext(object): - def _fixup_main_module(self): - main = sys.modules['__main__'] - main.__path__ = [] - main.core = main - - sys.modules['econtext'] = main - sys.modules['econtext.core'] = main - for klass in globals().itervalues(): + def _fixup_package(self): + econtext = imp.new_module('econtext') + econtext.__package__ = 'econtext' + econtext.__path__ = [] + econtext.core = sys.modules['__main__'] + + sys.modules['econtext'] = econtext + sys.modules['econtext.core'] = econtext.core + exec 'from econtext.core import *' in vars(econtext) + + for klass in vars(econtext.core).itervalues(): if hasattr(klass, '__module__'): klass.__module__ = 'econtext.core' @@ -695,7 +698,7 @@ class ExternalContext(object): os.dup2(100, 0) os.close(100) - def _SetupMaster(self, key): + def _setup_master(self, key): self.broker = Broker() self.context = Context(self.broker, 'master', key=key) self.channel = Channel(self.context, CALL_FUNCTION) @@ -743,8 +746,8 @@ class ExternalContext(object): def main(self, key, log_level): self._reap_first_stage() - self._fixup_main_module() - self._SetupMaster(key) + self._fixup_package() + self._setup_master(key) try: self._setup_logging(log_level) self._setup_importer() diff --git a/econtext/master.py b/econtext/master.py index 322df62a..6f981732 100644 --- a/econtext/master.py +++ b/econtext/master.py @@ -245,7 +245,7 @@ class Broker(econtext.core.Broker): context.stream.connect() return self.register(context) - def get_remote(self, hostname, username, name=None, python_path=None): + def get_remote(self, hostname, username=None, name=None, python_path=None): """Get the named remote context, creating it if it does not exist.""" if name is None: name = hostname