Giter Club home page Giter Club logo

Comments (11)

coffeemug avatar coffeemug commented on July 2, 2024

This looks like a compatibility issue with google's protobuf drivers and python3. @kratosaurion7 -- can you pip install protobuf directly?

from rethinkdb.

coffeemug avatar coffeemug commented on July 2, 2024

Just double checked, looks like protobufs proper don't support python3, but there is a port at https://github.com/machinalis/protobuf-python3. @kratosaurion7, if you have the time, would you mind seeing if you can hack rethink drivers to work with the python3 port?

from rethinkdb.

tristanred avatar tristanred commented on July 2, 2024

It seems the problem is with the "/tmp/pip-build/protobuf/setup.py" that is downloaded when using the "sudo pip install rethinkdb" command. It contains several print statements that uses % to replace arguments in the string. Commenting those print statements (two of them in my version) makes the setup works.

This solution works python2, I haven't tested for python 3 yet. This is a protobuf issue then.

from rethinkdb.

coffeemug avatar coffeemug commented on July 2, 2024

Moving to backlog. We'll investigate doing proper integration with protobuf lib on python 3 when we get the chance.

from rethinkdb.

malthe avatar malthe commented on July 2, 2024

I have ported the protobufs libray to Python 3: https://github.com/malthe/google-protobuf.

It seems to work on the rethinkdb client driver although I had to make the following changes:

diff --git a/drivers/python/rethinkdb/__init__.py b/drivers/python/rethinkdb/__init__.py
index 0174258..185f911 100644
--- a/drivers/python/rethinkdb/__init__.py
+++ b/drivers/python/rethinkdb/__init__.py
@@ -1,5 +1,5 @@
 # This file includes all public facing Python API functions
-from net import connect, Connection, Cursor
-from query import expr, js, error, do, row, table, db, db_create, db_drop, db_list, branch, count, sum, avg, asc, desc, eq, ne, le, ge, lt, gt, any, 
-from errors import RqlError, RqlClientError, RqlCompileError, RqlRuntimeError, RqlDriverError
-from ast import RqlQuery
+from .net import connect, Connection, Cursor
+from .query import expr, js, error, do, row, table, db, db_create, db_drop, db_list, branch, count, sum, avg, asc, desc, eq, ne, le, ge, lt, gt, any,
+from .errors import RqlError, RqlClientError, RqlCompileError, RqlRuntimeError, RqlDriverError
+from .ast import RqlQuery
diff --git a/drivers/python/rethinkdb/ast.py b/drivers/python/rethinkdb/ast.py
index a4841cc..b8f84ee 100644
--- a/drivers/python/rethinkdb/ast.py
+++ b/drivers/python/rethinkdb/ast.py
@@ -1,8 +1,15 @@
-import ql2_pb2 as p
+from rethinkdb import ql2_pb2 as p
 import types
 import sys
-from errors import *
-from net import Connection
+from .errors import *
+from .net import Connection
+
+if sys.version_info[0] == 3:
+    number = (int, float)
+    stringtypes = (str, )
+else:
+    number = (int, long, float)
+    stringtypes = (str, unicode)

 class RqlQuery(object):

@@ -314,10 +321,10 @@ class Datum(RqlQuery):
         elif isinstance(self.data, bool):
             term.datum.type = p.Datum.R_BOOL
             term.datum.r_bool = self.data
-        elif isinstance(self.data, int) or isinstance(self.data, float) or isinstance(self.data, long):
+        elif isinstance(self.data, number):
             term.datum.type = p.Datum.R_NUM
             term.datum.r_num = self.data
-        elif isinstance(self.data, types.StringTypes):
+        elif isinstance(self.data, stringtypes):
             term.datum.type = p.Datum.R_STR
             term.datum.r_str = self.data
         else:
@@ -664,7 +671,7 @@ def func_wrap(val):
             return True
         if any([ivar_scan(arg) for arg in node.args]):
             return True
-        if any([ivar_scan(arg) for k,arg in node.optargs.iteritems()]):
+        if any([ivar_scan(arg) for k,arg in node.optargs.items()]):
             return True
         return False

@@ -700,4 +707,4 @@ class Desc(RqlTopLevelQuery):
     tt = p.Term.DESC
     st = 'desc'

-from query import expr
+from .query import expr
diff --git a/drivers/python/rethinkdb/errors.py b/drivers/python/rethinkdb/errors.py
index cf4c3d0..0d73aba 100644
--- a/drivers/python/rethinkdb/errors.py
+++ b/drivers/python/rethinkdb/errors.py
@@ -1,4 +1,4 @@
-import ql2_pb2 as p
+from rethinkdb import ql2_pb2 as p

 class RqlError(Exception):
     def __init__(self, message, term, frames):
diff --git a/drivers/python/rethinkdb/net.py b/drivers/python/rethinkdb/net.py
index 6bd5ba3..e98ea46 100644
--- a/drivers/python/rethinkdb/net.py
+++ b/drivers/python/rethinkdb/net.py
@@ -5,9 +5,9 @@ __all__ = ['connect', 'Connection', 'Cursor']
 import socket
 import struct

-import ql2_pb2 as p
+from rethinkdb import ql2_pb2 as p

-from errors import *
+from .errors import *

 class Cursor(object):
     def __init__(self, conn, query, term, chunk, complete):
@@ -99,7 +99,7 @@ class Connection(object):
             if self.db:
                global_opt_args['db'] = self.db

-        for k,v in global_opt_args.iteritems():
+        for k,v in global_opt_args.items():
             pair = query.global_optargs.add()
             pair.key = k
             expr(v).build(pair.val)
@@ -174,5 +174,5 @@ class Connection(object):
 def connect(host='localhost', port=28015, db='test'):
     return Connection(host, port, db)

-from ast import Datum, DB
-from query import expr
+from .ast import Datum, DB
+from .query import expr
diff --git a/drivers/python/rethinkdb/query.py b/drivers/python/rethinkdb/query.py
index 1dae0f6..7000c6d 100644
--- a/drivers/python/rethinkdb/query.py
+++ b/drivers/python/rethinkdb/query.py
@@ -1,5 +1,5 @@
-from ast import *
-import ql2_pb2 as p
+from .ast import *
+from rethinkdb import ql2_pb2 as p

 """
 All top level functions defined here are the starting points for RQL queries

That said, Google's protobufs implementation isn't the only game in town and it might be interesting to look at something like upb.

from rethinkdb.

coffeemug avatar coffeemug commented on July 2, 2024

@malthe -- do you have any idea if the kind folks at google would be willing to accept your protobuf library Python 3 patch? We'd love to get python 3 support for the driver, the only thing that's keeping us is the fact that we'd have to bundle the protobuf library with the driver, which is, for a number of reasons, very undesirable. (We could use upb, but that would require pretty significant testing effort).

from rethinkdb.

malthe avatar malthe commented on July 2, 2024

@coffeemug: I have been in touch with Gregory P. Smith from Google; he asked me to sign a contributor agreement about a month ago, and I got the intention that they were interested in merging the patch (in some form).

from rethinkdb.

coffeemug avatar coffeemug commented on July 2, 2024

@malthe -- that's awesome! I think it would make a lot of people (RethinkDB team included) very, very happy. Could you let us know when this gets merged? (although we'll probably hear about it anyway)

from rethinkdb.

robert-zaremba avatar robert-zaremba commented on July 2, 2024

@malthe did they merge your patch?
I'm trying with protobuf from http://protobuf.googlecode.com/svn/trunk/python and I needed to manually patch it after 2to3.

from rethinkdb.

malthe avatar malthe commented on July 2, 2024

I don't think they did. They said that I would be added to the contributor list, but that hasn't happened yet. At least no changes were made to the file that lists contributions in the repository you linked above.

Note that I decided against using the 2to3 utility. Instead, I require 2.7 and 3.2 or better, which are mostly syntax compatible.

from rethinkdb.

wmrowan avatar wmrowan commented on July 2, 2024

Since this issue has become about Python 3 compatibility I created a new issue (#1050) explicitly about that issue and will close this one.

from rethinkdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.