BurnySc2 / python-sc2

A StarCraft II bot api client library for Python 3
MIT License
491 stars 157 forks source link

Moves protobuf internally and upgrades to v4 #174

Closed gmenel closed 3 months ago

gmenel commented 1 year ago

Hello Sir,

Feature: Removes s2clientprotocol and moves proto inline to add protbuf v4. Below is the steps followed to add it to the project. You can check out your own develop branch and follow along. I'm not adding my .lock files as i don't want to mess with anything.

  1. Grab the *.proto files from blizzard and paste them into root folder ./s2clientprotocol https://github.com/Blizzard/s2client-proto/tree/master/s2clientprotocol

  2. Run generate_protobufs.py or your OS equivalent of this command project root: $ protoc --python_out=./sc2/ ./s2clientprotocol/*.proto Ensure you have the latest "protoc" version on your system. The protoc executables are downloadable here: https://github.com/protocolbuffers/protobuf/releases/tag/v23.2 This overwrites the files in: sc2/s2clientprotocol/*_pb2.py

  3. Replace all imports of old lib to use local import with simple search replace. "from s2clientprotocol import" replace with "from sc2.s2clientprotocol import" important to run this after codegen

X. (irrelevant to this process, but had to update codecov poetry update codecov)

  1. execute: poetry remove s2clientprotocol

  2. execute: poetry remove protobuf poetry add protobuf or an upgrade command which can get it to 4.23.2


Upgrading

should the .proto files ever get an upgrade, you simply place them in the root s2clientprotocol folder and execute generate_protobufs.py again.

NB: the renaming might need to occur again, in which case some search + replace on the generated code in the sc2/s2clientprotocol/*_pb2.py. I don't have the python skill to script this into generate_protobufs.py.

It could just be done by hand too: "from s2clientprotocol import" replaced with "from sc2.s2clientprotocol import"