Skip to content

Commit

Permalink
Merge branch 'master' into genpyiv2
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcarneiro committed Oct 4, 2021
2 parents 574eb05 + 6e7fffd commit b310447
Show file tree
Hide file tree
Showing 51 changed files with 2,537 additions and 1,838 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 120
extend-ignore = E203,E211,E225,E226,E227,E231,E251,E261,E262,E265,E402,E999
max-complexity = 10
per-file-ignores =
test/test_examples.py: C901
9 changes: 5 additions & 4 deletions .github/workflows/packagingtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ jobs:
run: |
python setup.py build
pip install .
- name: Lint with flake8
- name: Lint with flake8 and check black
run: |
pip install flake8
flake8 . --filename '*.py,*.pyx,*.pxd' --count --max-complexity=10 --max-line-length=120 --ignore=E211,E225,E226,E227,E231,E251,E261,E262,E265,E402,E999 --show-source --statistics --exclude benchmark,build,capnp/templates/module.pyx
flake8 . --count --max-complexity=10 --max-line-length=120 --show-source --statistics --exclude benchmark,build
pip install black flake8
flake8 . --filename '*.py,*.pyx,*.pxd' --count --show-source --statistics --exclude benchmark,build,capnp/templates/module.pyx
flake8 . --count --show-source --statistics --exclude benchmark,build
black . --check --diff --color
- name: Packaging
run: |
python setup.py bdist_wheel
Expand Down
30 changes: 15 additions & 15 deletions benchmark/addressbook.capnp.orphan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@
import capnp

this_dir = os.path.dirname(__file__)
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
addressbook = capnp.load(os.path.join(this_dir, "addressbook.capnp"))

print = lambda *x: x


def writeAddressBook():
addressBook = addressbook.AddressBook.new_message()
people = addressBook.init_resizable_list('people')
people = addressBook.init_resizable_list("people")

alice = people.add()
alice.id = 123
alice.name = 'Alice'
alice.email = 'alice@example.com'
alicePhones = alice.init('phones', 1)
alice.name = "Alice"
alice.email = "alice@example.com"
alicePhones = alice.init("phones", 1)
alicePhones[0].number = "555-1212"
alicePhones[0].type = 'mobile'
alicePhones[0].type = "mobile"

bob = people.add()
bob.id = 456
bob.name = 'Bob'
bob.email = 'bob@example.com'
bobPhones = bob.init('phones', 2)
bob.name = "Bob"
bob.email = "bob@example.com"
bobPhones = bob.init("phones", 2)
bobPhones[0].number = "555-4567"
bobPhones[0].type = 'home'
bobPhones[0].type = "home"
bobPhones[1].number = "555-7654"
bobPhones[1].type = 'work'
bobPhones[1].type = "work"

people.finish()
msg_bytes = addressBook.to_bytes()
return msg_bytes


def printAddressBook(msg_bytes):
addressBook = addressbook.AddressBook.from_bytes(msg_bytes)

for person in addressBook.people:
print(person.name, ':', person.email)
print(person.name, ":", person.email)
for phone in person.phones:
print(phone.type, ':', phone.number)
print(phone.type, ":", phone.number)
print()


if __name__ == '__main__':
if __name__ == "__main__":
for i in range(10000):
msg_bytes = writeAddressBook()

printAddressBook(msg_bytes)

51 changes: 28 additions & 23 deletions benchmark/addressbook.capnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,38 @@
except:
profile = lambda func: func
this_dir = os.path.dirname(__file__)
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
addressbook = capnp.load(os.path.join(this_dir, "addressbook.capnp"))

print = lambda *x: x


@profile
def writeAddressBook():
addressBook = addressbook.AddressBook.new_message()
people = addressBook.init('people', 2)
people = addressBook.init("people", 2)

alice = people[0]
alice.id = 123
alice.name = 'Alice'
alice.email = 'alice@example.com'
alicePhones = alice.init('phones', 1)
alice.name = "Alice"
alice.email = "alice@example.com"
alicePhones = alice.init("phones", 1)
alicePhones[0].number = "555-1212"
alicePhones[0].type = 'mobile'
alicePhones[0].type = "mobile"

bob = people[1]
bob.id = 456
bob.name = 'Bob'
bob.email = 'bob@example.com'
bobPhones = bob.init('phones', 2)
bob.name = "Bob"
bob.email = "bob@example.com"
bobPhones = bob.init("phones", 2)
bobPhones[0].number = "555-4567"
bobPhones[0].type = 'home'
bobPhones[0].type = "home"
bobPhones[1].number = "555-7654"
bobPhones[1].type = 'work'
bobPhones[1].type = "work"

msg_bytes = addressBook.to_bytes()
return msg_bytes


@profile
def printAddressBook(msg_bytes):
addressBook = addressbook.AddressBook.from_bytes(msg_bytes)
Expand All @@ -44,31 +47,34 @@ def printAddressBook(msg_bytes):
for phone in person.phones:
phone.type, phone.number


@profile
def writeAddressBookDict():
addressBook = addressbook.AddressBook.new_message()
people = addressBook.init('people', 2)
people = addressBook.init("people", 2)

alice = people[0]
alice.id = 123
alice.name = 'Alice'
alice.email = 'alice@example.com'
alicePhones = alice.init('phones', 1)
alice.name = "Alice"
alice.email = "alice@example.com"
alicePhones = alice.init("phones", 1)
alicePhones[0].number = "555-1212"
alicePhones[0].type = 'mobile'
alicePhones[0].type = "mobile"

bob = people[1]
bob.id = 456
bob.name = 'Bob'
bob.email = 'bob@example.com'
bobPhones = bob.init('phones', 2)
bob.name = "Bob"
bob.email = "bob@example.com"
bobPhones = bob.init("phones", 2)
bobPhones[0].number = "555-4567"
bobPhones[0].type = 'home'
bobPhones[0].type = "home"
bobPhones[1].number = "555-7654"
bobPhones[1].type = 'work'
bobPhones[1].type = "work"

msg = addressBook.to_dict()
return msg


@profile
def printAddressBookDict(msg):
addressBook = addressbook.AddressBook.new_message(**msg)
Expand All @@ -79,7 +85,7 @@ def printAddressBookDict(msg):
phone.type, phone.number


if __name__ == '__main__':
if __name__ == "__main__":
# for i in range(10000):
# msg_bytes = writeAddressBook()

Expand All @@ -88,4 +94,3 @@ def printAddressBookDict(msg):
msg = writeAddressBookDict()

printAddressBookDict(msg)

15 changes: 7 additions & 8 deletions benchmark/addressbook.proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ def writeAddressBook():

alice = addressBook.person.add()
alice.id = 123
alice.name = 'Alice'
alice.email = 'alice@example.com'
alice.name = "Alice"
alice.email = "alice@example.com"
alicePhones = [alice.phone.add()]
alicePhones[0].number = "555-1212"
alicePhones[0].type = addressbook.Person.MOBILE

bob = addressBook.person.add()
bob.id = 456
bob.name = 'Bob'
bob.email = 'bob@example.com'
bob.name = "Bob"
bob.email = "bob@example.com"
bobPhones = [bob.phone.add(), bob.phone.add()]
bobPhones[0].number = "555-4567"
bobPhones[0].type = addressbook.Person.HOME
Expand All @@ -34,15 +34,14 @@ def printAddressBook(message_string):
addressBook.ParseFromString(message_string)

for person in addressBook.person:
print(person.name, ':', person.email)
print(person.name, ":", person.email)
for phone in person.phone:
print(phone.type, ':', phone.number)
print(phone.type, ":", phone.number)
print()


if __name__ == '__main__':
if __name__ == "__main__":
for i in range(10000):
message_string = writeAddressBook()

printAddressBook(message_string)

Loading

0 comments on commit b310447

Please sign in to comment.