-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link in UPB by default for Bazel's python build rules.
In v21.x, we announced our intent to flip the default implementation of protobuf python from pure python to upb. - https://github.com/protocolbuffers/protobuf/releases/tag/v21.0 We also documented in docs and readme that PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION env var can be set to override the python implementation used. - https://protobuf.dev/reference/python/python-generated/#sharing-messages In practice, we only use upb if it can successfully be imported: - https://github.com/protocolbuffers/protobuf/blob/1c29f34b24eafe4a362ce075c12c62c614fad199/python/google/protobuf/internal/api_implementation.py#L54 - https://github.com/protocolbuffers/protobuf/blob/1c29f34b24eafe4a362ce075c12c62c614fad199/python/google/protobuf/internal/api_implementation.py#L100 Otherwise, we fall back to pure python, even if the env var is set to upb. Since we don't currently link in upb for Bazel, this means the default is still pure python in practice and the environment variable is not respected. This change links in UPB by default and ensures that default python builds and unit tests using Bazel will enable running with python-UPB. #test-continuous PiperOrigin-RevId: 711436307
- Loading branch information
1 parent
5b0fa1d
commit 989870c
Showing
8 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Protocol Buffers - Google's data interchange format | ||
# Copyright 2008 Google Inc. All rights reserved. | ||
# | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file or at | ||
# https://developers.google.com/open-source/licenses/bsd | ||
"""Test that Kokoro is using the intended backend implementation of python.""" | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
from google.protobuf.internal import api_implementation | ||
|
||
|
||
class PythonApiTest(unittest.TestCase): | ||
|
||
def testExpectedBackend(self): | ||
"""Test that a python test is using the expected backend.""" | ||
expected_api_type = os.getenv( | ||
'PROTOCOL_BUFFERS_EXPECTED_PYTHON_BACKEND', 'upb' | ||
) # default is UPB. | ||
|
||
self.assertEqual(expected_api_type, api_implementation.Type()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |