From 5b8a99dbafdad9b70bdf3cdd1493f7ac772b2e55 Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Fri, 22 May 2020 18:44:43 +0200 Subject: [PATCH 1/3] ensure modules are loaded by pyinstaller --- rethinkdb/__init__.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/rethinkdb/__init__.py b/rethinkdb/__init__.py index 68c926a5..f548c4c5 100644 --- a/rethinkdb/__init__.py +++ b/rethinkdb/__init__.py @@ -67,27 +67,28 @@ def __init__(self): def set_loop_type(self, library=None): if library is None: self.connection_type = self.net.DefaultConnection - return - - # find module file - manager = pkg_resources.ResourceManager() - lib_path = "%(library)s_net/net_%(library)s.py" % {"library": library} - if not manager.resource_exists(__name__, lib_path): - raise ValueError("Unknown loop type: %r" % library) - - # load the module - module_path = manager.resource_filename(__name__, lib_path) - module_name = "net_%s" % library - module_file, pathName, desc = imp.find_module( - module_name, [os.path.dirname(module_path)] - ) - module = imp.load_module("rethinkdb." + module_name, module_file, pathName, desc) - # set the connection type - self.connection_type = module.Connection + if library == "asyncio": + from rethinkdb.asyncio_net import net_asyncio + self.connection_type = net_asyncio.Connection + + if library == "gevent": + from rethinkdb.gevent_net import net_gevent + self.connection_type = net_gevent.Connection + + if library == "tornado": + from rethinkdb.tornado_net import net_tornado + self.connection_type = net_tornado.Connection + + if library == "trio": + from rethinkdb.trio_net import net_trio + self.connection_type = net_trio.Connection + + if library == "twisted": + from rethinkdb.twisted_net import net_twisted + self.connection_type = net_twisted.Connection - # cleanup - manager.cleanup_resources() + return def connect(self, *args, **kwargs): return self.make_connection(self.connection_type, *args, **kwargs) From c54a3deb150ad34a1936c9bee2b7abd9cfd34b7f Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Fri, 22 May 2020 18:55:18 +0200 Subject: [PATCH 2/3] removed unused imports --- rethinkdb/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rethinkdb/__init__.py b/rethinkdb/__init__.py index f548c4c5..05b682ea 100644 --- a/rethinkdb/__init__.py +++ b/rethinkdb/__init__.py @@ -11,10 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import imp -import os - -import pkg_resources from rethinkdb import errors, version From 8d6bbf578c6d8eadbb0fd19f81fb3740bcbf6679 Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Sun, 24 May 2020 13:20:13 +0200 Subject: [PATCH 3/3] ensure DefaultConnection in case connection_type returns None --- rethinkdb/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rethinkdb/__init__.py b/rethinkdb/__init__.py index 05b682ea..70b1661a 100644 --- a/rethinkdb/__init__.py +++ b/rethinkdb/__init__.py @@ -61,9 +61,6 @@ def __init__(self): self.set_loop_type(None) def set_loop_type(self, library=None): - if library is None: - self.connection_type = self.net.DefaultConnection - if library == "asyncio": from rethinkdb.asyncio_net import net_asyncio self.connection_type = net_asyncio.Connection @@ -84,6 +81,9 @@ def set_loop_type(self, library=None): from rethinkdb.twisted_net import net_twisted self.connection_type = net_twisted.Connection + if library is None or self.connection_type is None: + self.connection_type = self.net.DefaultConnection + return def connect(self, *args, **kwargs):