Skip to content

Commit

Permalink
fix: fix conda compatibility issue (#475)
Browse files Browse the repository at this point in the history
* fix: fix conda compatibility issue

* add comment

* typo
  • Loading branch information
parthea authored Jul 12, 2024
1 parent 4d8ee65 commit e2f9c9d
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions proto/marshal/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@

from google.protobuf.internal import containers

# Import protobuf 4.xx first and fallback to earlier version
# if not present.
# Import all message types to ensure that pyext types are recognized
# when upb types exist. Conda's protobuf defaults to pyext despite upb existing.
# See https://github.com/googleapis/proto-plus-python/issues/470
try:
from google._upb import _message
from google._upb import _message as _message_upb
except ImportError:
_message = None
_message_upb = None

try:
from google.protobuf.pyext import _message as _message_pyext
except ImportError:
_message_pyext = None

if not _message:
try:
from google.protobuf.pyext import _message
except ImportError:
_message = None

repeated_composite_types = (containers.RepeatedCompositeFieldContainer,)
repeated_scalar_types = (containers.RepeatedScalarFieldContainer,)
Expand All @@ -44,16 +45,16 @@
# See https://github.com/protocolbuffers/protobuf/issues/16596
map_composite_type_names = ("MessageMapContainer",)

if _message:
repeated_composite_types += (_message.RepeatedCompositeContainer,)
repeated_scalar_types += (_message.RepeatedScalarContainer,)

try:
map_composite_types += (_message.MessageMapContainer,)
except AttributeError:
# The `MessageMapContainer` attribute is not available in Protobuf 5.x+
pass
for message in [_message_upb, _message_pyext]:
if message:
repeated_composite_types += (message.RepeatedCompositeContainer,)
repeated_scalar_types += (message.RepeatedScalarContainer,)

try:
map_composite_types += (message.MessageMapContainer,)
except AttributeError:
# The `MessageMapContainer` attribute is not available in Protobuf 5.x+
pass

__all__ = (
"repeated_composite_types",
Expand Down

0 comments on commit e2f9c9d

Please sign in to comment.