diff --git a/pupy/packages/all/pupyimporter.py b/pupy/packages/all/pupyimporter.py index f2a22568..08d02178 100644 --- a/pupy/packages/all/pupyimporter.py +++ b/pupy/packages/all/pupyimporter.py @@ -65,6 +65,9 @@ def pupy_add_package(pkdic): modules.update(module) +def native_import(name): + __import__(name) + class PupyPackageLoader: def __init__(self, fullname, contents, extension, is_pkg, path): self.fullname = fullname diff --git a/pupy/pupylib/PupyClient.py b/pupy/pupylib/PupyClient.py index 0890d300..757e81e2 100644 --- a/pupy/pupylib/PupyClient.py +++ b/pupy/pupylib/PupyClient.py @@ -261,6 +261,10 @@ class PupyClient(object): For other platforms : loading .so in memory is not supported yet. """ # start path should only use "/" as separator + + if module_name in self.conn.modules.sys.modules and not force: + return + start_path=module_name.replace(".", "/") package_found=False package_path=None @@ -284,8 +288,19 @@ class PupyClient(object): raise PupyModuleError("Error while loading package from sys.path %s : %s"%(module_name, traceback.format_exc())) if "pupyimporter" not in self.conn.modules.sys.modules: raise PupyModuleError("pupyimporter module does not exists on the remote side !") + if not modules_dic: - raise PupyModuleError("Couldn't load package %s : no such file or directory neither in \(path=%s) or sys.path"%(module_name,repr(self.get_packages_path()))) + if self.desc['native']: + raise PupyModuleError("Couldn't find package {} in \(path={}) and sys.path / native".format( + module_name, repr(self.get_packages_path()))) + else: + try: + self.conn.modules.pupyimporter.native_import(module_name) + except Exception as e: + raise PupyModuleError("Couldn't find package {} in \(path={}) and sys.path / python = {}".format( + module_name, repr(self.get_packages_path()), e)) + + if force or ( module_name not in self.conn.modules.sys.modules ): self.conn.modules.pupyimporter.pupy_add_package(cPickle.dumps(modules_dic)) # we have to pickle the dic for two reasons : because the remote side is not aut0horized to iterate/access to the dictionary declared on this side and because it is more efficient logging.debug("package %s loaded on %s from path=%s"%(module_name, self.short_name(), package_path)) @@ -293,6 +308,7 @@ class PupyClient(object): self.conn.modules.sys.modules.pop(module_name) logging.debug("package removed from sys.modules to force reloading") return True + return False def run_module(self, module_name, args): diff --git a/pupy/pupylib/PupyModule.py b/pupy/pupylib/PupyModule.py index e544585c..271e456a 100644 --- a/pupy/pupylib/PupyModule.py +++ b/pupy/pupylib/PupyModule.py @@ -108,13 +108,16 @@ class PupyModule(object): def import_dependencies(self): if type(self.dependencies) == dict: - dependencies = self.dependencies.get('all', []) + \ - self.dependencies.get(self.client.platform, []) + dependencies = self.dependencies.get(self.client.platform, []) + \ + self.dependencies.get('all', []) else: dependencies = self.dependencies for d in dependencies: - self.client.load_package(d) + if d.lower().endswith('.dll'): + self.client.load_dll(d) + else: + self.client.load_package(d) def init_argparse(self): """ Override this class to define your own arguments. """ diff --git a/pupy/pupylib/PupyServer.py b/pupy/pupylib/PupyServer.py index 8e3b92a0..daf06704 100644 --- a/pupy/pupylib/PupyServer.py +++ b/pupy/pupylib/PupyServer.py @@ -111,6 +111,7 @@ class PupyServer(threading.Thread): "launcher_args" : obtain(conn.get_infos("launcher_args")), "transport" : obtain(conn.get_infos("transport")), "daemonize" : (True if obtain(conn.get_infos("daemonize")) else False), + "native": conn.get_infos("native"), } client_info.update(l) pc=PupyClient.PupyClient(client_info, self)