Skip to content

please regenerate protobuf _pb2.py files using recent protoc, and publish new release on PyPI #146

@SomberNight

Description

@SomberNight

Unfortunately Google made breaking changes in protobuf (see e.g. here), and hence the current _pb2.py generated files in latest release/master of keepkeylib cannot be parsed with new versions of protobuf (4.x).

AFAICT protoc >=3.19 generates _pb2 files in the new format, while older protoc generates the old format.
AFAICT

  • protobuf 3.20.x is able to parse both the old and the new format,
  • protobuf <3.20 can only parse the old format,
  • protobuf >=3.21 can only parse the new format
user@user-VirtualBox:~/wspace/tmp$ git clone https://github.com/keepkey/python-keepkey
Cloning into 'python-keepkey'...
remote: Enumerating objects: 8669, done.
remote: Counting objects: 100% (54/54), done.
remote: Compressing objects: 100% (37/37), done.
remote: Total 8669 (delta 31), reused 33 (delta 17), pack-reused 8615
Receiving objects: 100% (8669/8669), 56.08 MiB | 606.00 KiB/s, done.
Resolving deltas: 100% (3780/3780), done.


user@user-VirtualBox:~/wspace/tmp$ python3 -m venv env
user@user-VirtualBox:~/wspace/tmp$ source env/bin/activate

(env) user@user-VirtualBox:~/wspace/tmp$ cd python-keepkey/
(env) user@user-VirtualBox:~/wspace/tmp/python-keepkey$ git log -n1
commit 7bddc11d7ee8208161d8b428ad5b6760dd450a98 (HEAD -> master, origin/master, origin/HEAD)
Merge: 4054710 866fc63
Author: markrypt0 <91701444+markrypt0@users.noreply.github.com>
Date:   Sun Aug 7 07:34:19 2022 -0600

    Merge pull request #145 from keepkey/xpub-support
    
    Xpub support

(env) user@user-VirtualBox:~/wspace/tmp/python-keepkey$ pip install -e .
Obtaining file:///home/user/wspace/tmp/python-keepkey
  Preparing metadata (setup.py) ... done
Collecting ecdsa>=0.9
  Using cached ecdsa-0.18.0-py2.py3-none-any.whl (142 kB)
Collecting hidapi>=0.7.99.post15
  Using cached hidapi-0.12.0.post2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (892 kB)
Collecting libusb1>=1.6
  Using cached libusb1-3.0.0-py3-none-any.whl (62 kB)
Collecting mnemonic>=0.8
  Using cached mnemonic-0.20-py3-none-any.whl (62 kB)
Collecting protobuf>=3.0.0
  Using cached protobuf-4.21.4-cp37-abi3-manylinux2014_x86_64.whl (408 kB)
Collecting six>=1.9.0
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Requirement already satisfied: setuptools>=19.0 in /home/user/wspace/tmp/env/lib/python3.10/site-packages (from hidapi>=0.7.99.post15->keepkey==7.0.3) (59.6.0)
Installing collected packages: libusb1, six, protobuf, mnemonic, hidapi, ecdsa, keepkey
  Running setup.py develop for keepkey
Successfully installed ecdsa-0.18.0 hidapi-0.12.0.post2 keepkey-7.0.3 libusb1-3.0.0 mnemonic-0.20 protobuf-4.21.4 six-1.16.0

(env) user@user-VirtualBox:~/wspace/tmp/python-keepkey$ python ./helloworld.py 
Traceback (most recent call last):
  File "/home/user/wspace/tmp/python-keepkey/./helloworld.py", line 4, in <module>
    from keepkeylib.client import KeepKeyClient
  File "/home/user/wspace/tmp/python-keepkey/keepkeylib/client.py", line 37, in <module>
    from . import mapping
  File "/home/user/wspace/tmp/python-keepkey/keepkeylib/mapping.py", line 1, in <module>
    from . import messages_pb2 as proto
  File "/home/user/wspace/tmp/python-keepkey/keepkeylib/messages_pb2.py", line 17, in <module>
    from . import types_pb2 as types__pb2
  File "/home/user/wspace/tmp/python-keepkey/keepkeylib/types_pb2.py", line 34, in <module>
    _descriptor.EnumValueDescriptor(
  File "/home/user/wspace/tmp/env/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 755, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
(env) user@user-VirtualBox:~/wspace/tmp/python-keepkey$ 

related: BitBoxSwiss/bitbox02-firmware#951


I would suggest

  1. using latest protoc to re-generate the _pb2.py files
    $ mkdir -p /opt/protoc && \
      curl -L0 https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-x86_64.zip -o /tmp/protoc-21.2-linux-x86_64.zip && \
      unzip /tmp/protoc-21.2-linux-x86_64.zip -d /opt/protoc
    $ PATH="/opt/protoc/bin:$PATH"
    $ ./build_pb.sh
    
  2. bumping required protobuf in setup.py to "protobuf>=3.20"
    'protobuf>=3.0.0',
  3. then releasing a new version of this library on PyPI
    • btw, I see there has been multiple git tags since the last PyPI release (6.3.1 in Dec 2019). Please also release there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions