bumptech / palm Goto Github PK
View Code? Open in Web Editor NEWProtobufs Are Lightweight Messages
Home Page: http://bu.mp
License: Other
Protobufs Are Lightweight Messages
Home Page: http://bu.mp
License: Other
enum Foo {
a = 1;
};
Is valid in Google's protoc 2.4.1 compiler but not palm. It doesn't change the generated code to remove, so this isn't a very important issue.
I'm not worried about palmc generating service code for me, but it'd be nice if the parser didn't break when it encountered service definitions like:
service RemoteService {
rpc Execute (Request) returns (Response);
}
#29 has caused a regression. You can no longer reference messages imported from other .proto
files.
Given t.proto
:
message A {
optional string foo = 0;
}
grep -c __contains__ t_palm.py => 1
Which is what you expect.
However, add a couple more fields:
message A {
optional string foo = 0;
optional string bar = 1;
optional string baz = 2;
}
And you get __contains__
defined 3 times: grep -c __contains__ t_palm.py => 3
The definition is the same, so this is a harmless bug other than a few extra instructions processed when Python compiles the proto's class.
Attempting to pip install palm
fails with:
Could not install requirement palm because of HTTP error HTTP Error 404: 404 NOT FOUND for URL http://bu.mp/static/oss/palm/palm-0.1.2.tar.gz (from http://pypi.python.org/simple/palm/)
The proto file t.proto
:
message M {
repeated string a = 0;
}
It'd be nice to be able to set the a
field from a list during initialization like: pb = M(a=["one", "two"])
Google's protobuf library allows this, but palm does not:
>>> import t_palm
>>> pb = t_palm.M(a=['a', 'b'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "t_palm.py", line 14, in __init__
ProtoBase.__init__(self, _pbf_buf, **kw)
File "palm.pyx", line 154, in palm.palm.ProtoBase.__init__ (palm/palm.c:1583)
File "t_palm.py", line 70, in _set_a
raise ProtoValueError(list_assign_error)
palm.palm.ProtoValueError: Can't assign list to repeated field a
data is a common field name in protocol buffers, we should avoid using it in the constructor for ProtoBase because it means you can't set that field using the generated code's constructor.
Google's protoc can compile the following just fine as the duplicate message X
s are in different enclosing messages:
message A {
optional B b = 1;
optional C c = 2;
message B {
optional X x = 1;
message X {
optional bool wat = 1;
}
}
message C {
optional X x = 1;
message X {
optional bool wat = 1;
}
}
}
palm 0.1.2 produces the following:
p.proto... [FAIL]
Traceback (most recent call last):
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/main.py", line 24, in run
r = parser.parse(source)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/baseparser.py", line 32, in parse
return processor( value, data )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 32, in __call__
result = dispatchList( self, tags, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 63, in message
dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 88, in message_body
return dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 63, in message
dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 88, in message_body
return dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 63, in message
dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 83, in message_label
raise ProtoParseError(start, stop, buffer, "message %s already defined" % self.current_message)
ProtoParseError: [line 1] message 2-X already defined
palm 0.1.5 produces the following:
p.proto... [FAIL]
Traceback (most recent call last):
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/main.py", line 36, in run
r = parser.parse(source)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/baseparser.py", line 32, in parse
return processor( value, data )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 32, in __call__
result = dispatchList( self, tags, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 81, in message
dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 106, in message_body
return dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 81, in message
dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 106, in message_body
return dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 81, in message
dispatchList(self, subtags, buffer)
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 59, in dispatchList
return map( dispatch, [source]*len(taglist), taglist, [buffer]*len(taglist))
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/simpleparse/dispatchprocessor.py", line 54, in dispatch
return function( tag, buffer )
File "/home/schmichael/src/ua/pyreactor-client/lib/python2.6/site-packages/palm/palmc/parse.py", line 101, in message_label
raise ProtoParseError(start, stop, buffer, "message %s already defined" % self.current_message)
ProtoParseError: [line 1] message 2-X already defined
It would be handy to integrate into Google's protoc tool to simplify usage and integrate with cross-platform projects more easily.
Plugins are as "simple" as a binary named protoc-gen-$NAME
:
// A plugin executable needs only to be placed somewhere in the path. The
// plugin should be named "protoc-gen-$NAME", and will then be used when the
// flag "--${NAME}_out" is passed to protoc.
via: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin.pb
See also: https://developers.google.com/protocol-buffers/docs/reference/other
(I know this is probably a lot of work for only a slight bump in usability, but a guy can dream right?)
@jamwt - Would you mind running python setup.py sdist upload
? pypi is back on 0.1.2
t.proto
message M {
optional Options opt = 1 [default = NONE];
enum Options {
NONE = 0;
NOT_NONE = 1;
}
}
palmc . .
python
>>> import t_palm
>>> t_palm.M(t_palm.M().dumps()).opt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "t_palm.py", line 51, in _get_opt
r = NONE
NameError: global name 'NONE' is not defined
Setting default = M.NONE
or default = Options.NONE
are both invalid.
Ignoring package directives seems sensible since Python doesn't use it.
I'll see if I can't figure it out, but I've never used SimpleParse.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.