Comments (11)
This looks like a compatibility issue with google's protobuf drivers and python3. @kratosaurion7 -- can you pip install protobuf directly?
from rethinkdb.
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.
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.
Moving to backlog. We'll investigate doing proper integration with protobuf lib on python 3 when we get the chance.
from rethinkdb.
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.
@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.
@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.
@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.
@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.
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.
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)
- Unable to install Rethinkdb 2.4.0 on Ubuntu 20 HOT 3
- Data Explorer Code Completion Not working HOT 14
- Error in thread 2 in src/arch/runtime/context_switching.cc at line 362 HOT 1
- Rethinkdb Proxy
- Set a name to a proxy name HOT 3
- Add "Buffers" from /proc/meminfo in parse_meminfo_file to determine available memory
- download.rethinkdb.com is down, 502 Bad Gateway HOT 1
- Evaluate Profile-Guided Optimization (PGO) on RethinkDB
- error: to_string called on an uninitialized ip_address_t, addr_type: 0 compiling rethinkdb on Raspberry HOT 6
- RethinkDB not fully supported on Raspberry PI OS Bullseye (32/64 bit) HOT 10
- Reasonable to change hard-coded cluster size? HOT 5
- help bro my issue = warn: Problem when checking for new versions of RethinkDB: HTTP request to update.rethinkdb.com failed. HOT 1
- cluster connect/reconnect timeout HOT 1
- Installation fails in Kubuntu 23.10 HOT 4
- Generate web_assets.cc in a repeatable file order HOT 1
- Avoid full paths of coffeescript files in generation of web_assets.cc HOT 2
- Rethinkdb 2.4.4 release list HOT 11
- Support protobuf 25
- Return multiple changes feed
- Cache miss rate measurements HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rethinkdb.