Skip to content
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

build: integrate mypy-protobuf for stub generation #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jrtknauer
Copy link

@jrtknauer jrtknauer commented Jun 27, 2023

The mypy-protobuf requirements [0] are not "hard" requirements, as earlier versions are simply untested. The listed requirement of protoc >= 4.21.8 is therefore not definitive, as with this commit protoc
version 3.4.0 successfully generated stubs with the plugin.

References:

[0] https://github.com/nipunn1313/mypy-protobuf#requirements-to-run-mypy-protobuf

The mypy-protobuf requirements [0] are not "hard" requirements, as
earlier versions are simply untested. The listed requirement of protoc
>= 4.21.8 is therefore not definitive, as with this commit protoc
version 3.4.0 successfully generated stubs with the plugin.

References:

[0] https://github.com/nipunn1313/mypy-protobuf#requirements-to-run-mypy-protobuf
@jrtknauer
Copy link
Author

jrtknauer commented Jun 27, 2023

Example install and outputs:

$ sudo pip install .
Processing /home/jrtknauer/jrt/tmp/s2client-proto
  Preparing metadata (setup.py) ... done
Requirement already satisfied: mypy-protobuf in /usr/local/lib/python3.10/dist-packages (from s2clientprotocol==5.0.11.90136.0) (3.3.0)
Requirement already satisfied: protobuf in /usr/local/lib/python3.10/dist-packages (from s2clientprotocol==5.0.11.90136.0) (3.20.3)
Requirement already satisfied: types-protobuf>=3.19.12 in /usr/local/lib/python3.10/dist-packages (from mypy-protobuf->s2clientprotocol==5.0.11.90136.0) (4.23.0.1)
Building wheels for collected packages: s2clientprotocol
  Building wheel for s2clientprotocol (setup.py) ... done
  Created wheel for s2clientprotocol: filename=s2clientprotocol-5.0.11.90136.0-py3-none-any.whl size=55612 sha256=90e200f20d9b0393180da6378fe26dcaebf5afad7d4452fcb0bfa7f604bdaf17
  Stored in directory: /root/.cache/pip/wheels/a1/c7/ab/c94eff23fc8bc78833f5edc3a65a85c277da4d35fe39573367
Successfully built s2clientprotocol
Installing collected packages: s2clientprotocol
  Attempting uninstall: s2clientprotocol
    Found existing installation: s2clientprotocol 5.0.11.90136.0
    Uninstalling s2clientprotocol-5.0.11.90136.0:
      Successfully uninstalled s2clientprotocol-5.0.11.90136.0
Successfully installed s2clientprotocol-5.0.11.90136.0

$ ls -l s2clientprotocol
total 884
-rw-r--r-- 1 jrtknauer jrtknauer      0 Jun 27 16:17 __init__.py
drwxr-xr-x 2 jrtknauer jrtknauer   4096 Jun 27 16:21 __pycache__
-rw-r--r-- 1 jrtknauer jrtknauer    952 Jun 27 16:17 build.py
-rw-r--r-- 1 jrtknauer jrtknauer   1217 Jun 27 16:17 common.proto
-rw-r--r-- 1 root      root       13208 Jun 27 16:21 common_pb2.py
-rw-r--r-- 1 root      root        6404 Jun 27 16:21 common_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   5435 Jun 27 16:17 data.proto
-rw-r--r-- 1 root      root       33259 Jun 27 16:21 data_pb2.py
-rw-r--r-- 1 root      root       18791 Jun 27 16:21 data_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   2677 Jun 27 16:17 debug.proto
-rw-r--r-- 1 root      root       37032 Jun 27 16:21 debug_pb2.py
-rw-r--r-- 1 root      root       18087 Jun 27 16:21 debug_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   6515 Jun 27 16:17 error.proto
-rw-r--r-- 1 root      root       45236 Jun 27 16:21 error_pb2.py
-rw-r--r-- 1 root      root       24198 Jun 27 16:21 error_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   1645 Jun 27 16:17 query.proto
-rw-r--r-- 1 root      root       17931 Jun 27 16:21 query_pb2.py
-rw-r--r-- 1 root      root        8942 Jun 27 16:21 query_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   5768 Jun 27 16:17 raw.proto
-rw-r--r-- 1 root      root       59938 Jun 27 16:21 raw_pb2.py
-rw-r--r-- 1 root      root       31464 Jun 27 16:21 raw_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer  27351 Jun 27 16:17 sc2api.proto
-rw-r--r-- 1 root      root      182998 Jun 27 16:21 sc2api_pb2.py
-rw-r--r-- 1 root      root       94695 Jun 27 16:21 sc2api_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   5481 Jun 27 16:17 score.proto
-rw-r--r-- 1 root      root       22401 Jun 27 16:21 score_pb2.py
-rw-r--r-- 1 root      root       15458 Jun 27 16:21 score_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   5926 Jun 27 16:17 spatial.proto
-rw-r--r-- 1 root      root       41026 Jun 27 16:21 spatial_pb2.py
-rw-r--r-- 1 root      root       23206 Jun 27 16:21 spatial_pb2.pyi
-rw-r--r-- 1 jrtknauer jrtknauer   4136 Jun 27 16:17 ui.proto
-rw-r--r-- 1 root      root       44755 Jun 27 16:21 ui_pb2.py
-rw-r--r-- 1 root      root       24260 Jun 27 16:21 ui_pb2.pyi

However, what information I do not have is what environment is building the package for publication. mypy-protobuf has a hard execution requirement for Python 3.7 and greater - and the setup.py has not been updated to reflect Python versions since Python 3.4. If the environment is unable to support adoption of generating Python stubs, I will default to publishing the generated stubs to typeshed instead.

@Avasam
Copy link

Avasam commented Apr 16, 2024

Might be a good idea to add a py.typed marker as well https://peps.python.org/pep-0561/#packaging-type-information
Which also needs to be explicitly added to setup.py for anyone not using setuptools>=69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants