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

feat: Improve protobuf version handling #68

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04]
protoc-version: ["21.x", "23.x"]
protoc-version: ["21.x"]
python-version: ["3.8", "3.11"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
23 changes: 17 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,33 @@ def check_protoc_version():
print("Stopping the setup.")
exit(0)

version_re_compiled = re.compile(r".*\s(?P<major>\d+)\.(?P<minor>\d+)")
version_re_compiled = re.compile(r".*\s(?P<major>\d+)\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?")
installed_version = version_re_compiled.search(output.stdout.decode("utf-8"))
required_version = read_required_version()

if installed_version.group('minor') < required_version.group('minor'):
installed_version_major = installed_version.group('major')
installed_version_minor = installed_version.group('minor')
installed_version_patch = installed_version.group('patch')

# If the installed protobuf version does not include a major number
if installed_version_patch is None:
installed_version_patch = installed_version_minor
installed_version_minor = installed_version_major

if installed_version_minor != required_version.group('minor'):
text = "\n"
text += "The version of Protoc (v{0}.{1})".format(installed_version.group('minor'))
text += "The version of Protoc (v{0}.{1})".format(installed_version_minor,
installed_version_patch)
text += " you have installed is not compatible with the version of\nthe protobuf python package " \
"(v{0}.{1}) ".format(required_version.group('minor'))
"(v{0}.{1}) ".format(required_version.group('minor'), required_version.group('patch'))
text += "Embedded Proto requires. These are your options:\n" \
"\t1. Install a matching version of Protoc.\n" \
"\t2. Change the version of Embedded Proto.\n"

# Check if all versions are above v21.0
if ((21 <= int(installed_version.group('minor'))) and (21 <= int(required_version.group('minor')))) or \
((21 > int(installed_version.group('minor'))) and (21 > int(required_version.group('minor')))):
if ((21 <= int(installed_version_minor)) and (21 <= int(required_version.group('minor')))) or \
((21 > int(installed_version_minor)) and (21 > int(required_version.group('minor')))):


print(" [" + CYELLOW + "Warning" + CEND + "]")
text += "\t3. Ignore the difference at your own risk!\n"
Expand Down