-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port FlatBuffers to Python. #112
Conversation
This is a feature-complete Python port, derived from the Go version. I'm not trying to collide with other PRs, but instead provide more options for whatever ends up being merged. |
Please provide feedback on my use of ctypes; it seems mostly unnecessary now but I would benefit from additional opinions. |
I've tried ctypes and ended up using struct because it enforces value ranges automatically, takes care of endianess and returns native python data types. Also it seems to be much faster: ctypes:
struct:
I'll steal the idea of explicit type definitions though. |
Nice microbenchmarks. I am personally more interested in correctness than speed at this point,
|
Also, what do you mean by steal?
|
If you don't mind I'll use parts of your builder implementation and put datatype definitions in separate module as you did and remove hardcoded datatype sizes. |
I'd rather you keep your PR at its current scope..."lifting" code is not
|
I don't understand - you've mentioned combining my PR with yours in #110. I'll go ahead and provide own implementation of Builder then... |
I think we are both miscommunicating. Reconciling our efforts is my goal.
|
I think we are talking about same thing then :-) |
Where do our implementations overlap? |
They don't seem to overlap that much as #110 is based on C++ API and uses struct / array heavily. |
A joint PR would be great :) |
@rw: I've merged encode / numtypes code, using struct module but keeping the methods. Could we sync via email? |
@shaxbee Yes, please email me. Address is on my profile page. :-) |
Beta testers: please evaluate this PR for merging. I force-pushed some updates:
This branch has feature parity with the Java and Go versions, supports both Python 2 and 3, and is thoroughly tested. |
Looks good to me. |
this looks to be in really good shape. |
|
Increase code coverage to 97%: Add cases to generate and test conditionals not traversed with the 'gold' example Monster data. |
+1 for this PR, i don't have capacity at the moment to finish up #110. On Mon, 9 Mar 2015 at 14:12 Robert notifications@github.com wrote:
|
Robert, do you want to do more to this commit, or is it "good enough" for now? |
@gwvo I'll address your comments in this thread, squash, and this should be good to go. I'll comment here when that's ready. Ideally we'd do a round of speed work afterwards, similar to #165. |
Pushed some updates:
|
ready then? :) |
@gwvo Yep! |
Python2 tests: |
Improved compatibility:
|
Still get this: Also maybe have the files generates in |
More tweaks: Lift generated Python files into tests/MyGame, like we do for the other ports. |
Now we disable Go/Java comparison checks by default. |
@rw I found a little bug in the setup script, the following patch should fix. python/setup.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/python/setup.py b/python/setup.py
index f067b38..44f5ee7 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -8,7 +8,7 @@ setup(
author_email='me@rwinslow.com',
url='https://github.com/python/flatbuffers/python',
long_description='Python runtime library and code generator for use with the Flatbuffers serialization format.',
- packages=['flatbuffers'],
+ packages=['flatbuffers', 'flatbuffers.vendor'],
include_package_data=True,
requires=[],
description='Runtime library and code generator for use with the Flatbuffers serialization format.', |
After reinstall this package, everything is OK for me. |
Thanks @layzerar! Pushed. |
Life is short, how about this? |
@layzerar Almost there, incorporating some out-of-band feedback. |
Implement code generation and self-contained runtime library for Python. The test suite verifies: - Correctness of generated Python code by comparing output to that of the other language ports. - The exact bytes in the Builder buffer during many scenarios. - Vtable deduplication correctness. - Edge cases for table construction, via a fuzzer derived from the Go implementation. - All code is simultaneously valid in Python 2.6, 2.7, and 3.4. The test suite includes benchmarks for: - Building 'gold' data. - Parsing 'gold' data. - Deduplicating vtables. All tests pass on this author's system for the following Python implementations: - CPython 2.6.7 - CPython 2.7.8 - CPython 3.4.2 - PyPy 2.5.0 (CPython 2.7.8 compatible)
Factored out some duplicated code, made the runtime library PEP8-compliant, and made a number of other stylistic fixes. The structure of the code has not changed. This is looking OK to me. Anyone else want to give feedback? |
tests/py_test.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tests/py_test.py b/tests/py_test.py
index c6861f1..2934394 100644
--- a/tests/py_test.py
+++ b/tests/py_test.py
@@ -1290,13 +1290,13 @@ def main():
import os
import sys
if not len(sys.argv) == 4:
- sys.stderr.write(('Usage: %s <benchmark vtable count>')
- ('<benchmark read count> <benchmark build count>')
- ('\n' % sys.argv[0]))
- sys.stderr.write((' Provide COMPARE_GENERATED_TO_GO=1 to check')
- ('for bytewise comparison to Go data.\n'))
- sys.stderr.write((' Provide COMPARE_GENERATED_TO_JAVA=1 to check')
- ('for bytewise comparison to Java data.\n'))
+ sys.stderr.write('Usage: %s <benchmark vtable count>'
+ '<benchmark read count> <benchmark build count>'
+ '\n' % sys.argv[0])
+ sys.stderr.write(' Provide COMPARE_GENERATED_TO_GO=1 to check'
+ 'for bytewise comparison to Go data.\n')
+ sys.stderr.write(' Provide COMPARE_GENERATED_TO_JAVA=1 to check'
+ 'for bytewise comparison to Java data.\n')
sys.stderr.flush()
sys.exit(1) |
For |
@layzerar Thanks, fixed string catenation in |
@gwvo Switched from |
Ok, merge at will :) |
Briliant! |
We've got it on PyPI: |
Is ./flatc still needed to do code gen? I'm hitting issues with its python output. |
@rw Congrats on getting this through! :-) |
…k_multi_repos support multi repositories in github webhook
Implement code generation and runtime library for Python 2 and 3, derived
from the Go implementation. Additionally, the test suite verifies:
the exact bytes in the Builder buffer during many scenarios,
vtable deduplication, and
table construction, via a fuzzer derived from the Go implementation.