Skip to content

Commit

Permalink
Merge pull request #68 from IronJulo/feature/protobuf-version-issue
Browse files Browse the repository at this point in the history
feat: Improve protobuf version handling
  • Loading branch information
BartHertog authored Dec 5, 2023
2 parents 19ab328 + ee14808 commit c6d3067
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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

0 comments on commit c6d3067

Please sign in to comment.