|
|
|
@ -36,39 +36,40 @@ import os |
|
|
|
|
import sys |
|
|
|
|
import warnings |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ApiVersionToImplementationType(api_version): |
|
|
|
|
if api_version == 2: |
|
|
|
|
return 'cpp' |
|
|
|
|
if api_version == 1: |
|
|
|
|
raise ValueError('api_version=1 is no longer supported.') |
|
|
|
|
if api_version == 0: |
|
|
|
|
return 'python' |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_implementation_type = None |
|
|
|
|
try: |
|
|
|
|
# pylint: disable=g-import-not-at-top |
|
|
|
|
from google.protobuf.internal import _api_implementation |
|
|
|
|
# The compile-time constants in the _api_implementation module can be used to |
|
|
|
|
# switch to a certain implementation of the Python API at build time. |
|
|
|
|
_api_version = _api_implementation.api_version |
|
|
|
|
_implementation_type = _ApiVersionToImplementationType( |
|
|
|
|
_api_implementation.api_version) |
|
|
|
|
except ImportError: |
|
|
|
|
_api_version = -1 # Unspecified by compiler flags. |
|
|
|
|
|
|
|
|
|
if _api_version == 1: |
|
|
|
|
raise ValueError('api_version=1 is no longer supported.') |
|
|
|
|
pass # Unspecified by compiler flags. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ApiVersionToImplementationType(api_version): |
|
|
|
|
if api_version == 3: |
|
|
|
|
return 'upb' |
|
|
|
|
if api_version == 2: |
|
|
|
|
return 'cpp' |
|
|
|
|
return 'python' |
|
|
|
|
|
|
|
|
|
# TODO(jieluo): Remove _api_version and only keep implementation_type |
|
|
|
|
# http://b/228103078 |
|
|
|
|
_default_implementation_type = _ApiVersionToImplementationType(_api_version) |
|
|
|
|
|
|
|
|
|
if _implementation_type is None: |
|
|
|
|
_implementation_type = 'python' |
|
|
|
|
|
|
|
|
|
# This environment variable can be used to switch to a certain implementation |
|
|
|
|
# of the Python API, overriding the compile-time constants in the |
|
|
|
|
# _api_implementation module. Right now only 'python', 'cpp' and 'upb' are |
|
|
|
|
# valid values. Any other value will raise error. |
|
|
|
|
_implementation_type = os.getenv('PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION', |
|
|
|
|
_default_implementation_type) |
|
|
|
|
_implementation_type) |
|
|
|
|
|
|
|
|
|
if _implementation_type not in ('python', 'cpp', 'upb'): |
|
|
|
|
raise ValueError('PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION {0} is not ' |
|
|
|
|