mirror of https://github.com/grpc/grpc.git
[Python Stub] Add version check to stubs generated by grpcio_tools (#35906)
The stubs generated by grpcio_tools should always be used with [the same or higher version of grpcio](https://github.com/grpc/grpc/blob/master/tools/distrib/python/grpcio_tools/setup.py#L313), this change will add a run time check for this requirement inside the generated stubs and therefor enforce this requirement. Please note for now we're just printing a warning for incorrect usage, we'll **change it to an error** soon. Example warning message: ``` /usr/local/google/home/xuanwn/workspace/misc/grpc/examples/python/helloworld/helloworld_pb2_grpc.py:21: RuntimeWarning: The grpc package installed is at version 1.60.1, but the generated code in helloworld_pb2_grpc.py depends on grpcio>=1.63.0.dev0. Please upgrade your grpc module to grpcio>=1.63.0.dev0 or downgrade your generated code using grpcio-tools<=1.60.1. This warning will become an error in 1.64.0, scheduled for release on May 14,2024. ``` <!-- If you know who should review your pull request, please assign it to that person, otherwise the pull request would get assigned randomly. If your pull request is for a specific language, please add the appropriate lang label. --> Closes #35906 PiperOrigin-RevId: 615659471pull/36077/head
parent
2c49416713
commit
c910004328
15 changed files with 220 additions and 12 deletions
@ -0,0 +1,38 @@ |
||||
# Copyright 2024 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
"""Test of gRPC Python's utilities.""" |
||||
|
||||
import logging |
||||
import unittest |
||||
|
||||
from grpc._utilities import first_version_is_lower |
||||
|
||||
|
||||
class UtilityTest(unittest.TestCase): |
||||
def testVersionCheck(self): |
||||
self.assertTrue(first_version_is_lower("1.2.3", "1.2.4")) |
||||
self.assertTrue(first_version_is_lower("1.2.4", "10.2.3")) |
||||
self.assertTrue(first_version_is_lower("1.2.3", "1.2.3.dev0")) |
||||
self.assertFalse(first_version_is_lower("NOT_A_VERSION", "1.2.4")) |
||||
self.assertFalse(first_version_is_lower("1.2.3", "NOT_A_VERSION")) |
||||
self.assertFalse(first_version_is_lower("1.2.4", "1.2.3")) |
||||
self.assertFalse(first_version_is_lower("10.2.3", "1.2.4")) |
||||
self.assertFalse(first_version_is_lower("1.2.3dev0", "1.2.3")) |
||||
self.assertFalse(first_version_is_lower("1.2.3", "1.2.3dev0")) |
||||
self.assertFalse(first_version_is_lower("1.2.3.dev0", "1.2.3")) |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
logging.basicConfig() |
||||
unittest.main(verbosity=2) |
@ -0,0 +1,19 @@ |
||||
%YAML 1.2 |
||||
--- | |
||||
# Copyright 2024 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_tools/grpc_version.py.template`!!! |
||||
|
||||
VERSION = '${settings.python_version.pep440()}' |
@ -0,0 +1,17 @@ |
||||
# Copyright 2024 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_tools/grpc_version.py.template`!!! |
||||
|
||||
VERSION = '1.63.0.dev0' |
Loading…
Reference in new issue