Skip to content

Commit

Permalink
Add templating and support for Python 3.13 (grpc#37643)
Browse files Browse the repository at this point in the history
This PR adds templating for Python versions and updates the maximum supported Python version to 3.13. The following major changes related to templating are added:
 - Minimum supported Python version and list of supported versions in `setup.py` are fetched using new template generated files called `python_version.py`
 - Dockerfiles for the different Python Linux builds are now template generated.
 - The "Supported Python Versions" section from READMEs of ancillary and main packages have been removed

Note: All the `python_version.py` files and Linux build `Dockerfiles` except `tools/dockerfile/grpc_artifact_python_linux_armv7/Dockerfile` in the PR are generated from the respective templates.

Further non-templated additions to add support for Python 3.13:
 - install scripts and artifacts for windows, macos and linux are added manually. Later, these can be templated as well.
 - updated cython bounds to 3.x
 - updated twine version to solve [cgi module import error](pypa/twine#1046)
 - the twine update introduces a dependency on cryptography>=2.0. But the cryptography package doesn't support 32-bit Linux images and hence `twine check` has been disabled for x86 manylinux and x86 musllinux artifacts.

Closes grpc#37643

PiperOrigin-RevId: 678954495
  • Loading branch information
sreenithi authored and paulosjca committed Nov 25, 2024
1 parent 86eea57 commit b3ad5d1
Show file tree
Hide file tree
Showing 105 changed files with 1,260 additions and 218 deletions.
1 change: 1 addition & 0 deletions PYTHON-MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include src/python/grpcio/_parallel_compile_patch.py
include src/python/grpcio/_spawn_patch.py
include src/python/grpcio/commands.py
include src/python/grpcio/grpc_version.py
include src/python/grpcio/python_version.py
include src/python/grpcio/grpc_core_dependencies.py
include src/python/grpcio/precompiled.py
include src/python/grpcio/support.py
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ load("@com_google_protobuf//bazel:system_python.bzl", "system_python")

system_python(
name = "system_python",
minimum_python_version = "3.7",
minimum_python_version = "3.8",
)

load("@system_python//:pip.bzl", system_pip_parse = "pip_parse")
Expand Down
6 changes: 3 additions & 3 deletions bazel/grpc_python_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def grpc_python_deps():
http_archive(
name = "cython",
build_file = "@com_github_grpc_grpc//third_party:cython.BUILD",
sha256 = "a2da56cc22be823acf49741b9aa3aa116d4f07fa8e8b35a3cb08b8447b37c607",
strip_prefix = "cython-0.29.35",
sha256 = "2ec7d66d23d6da2328fb24f5c1bec6c63a59ec2e91027766ab904f417e1078aa",
strip_prefix = "cython-3.0.11",
urls = [
"https://github.com/cython/cython/archive/0.29.35.tar.gz",
"https://github.com/cython/cython/archive/3.0.11.tar.gz",
],
)
1 change: 1 addition & 0 deletions black.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extend-exclude = '''
| test/cpp/naming/resolver_component_tests_runner.py # AUTO-GENERATED
# AUTO-GENERATED from a template:
| grpc_version.py
| python_version.py
| src/python/grpcio/grpc_core_dependencies.py
| src/python/grpcio/grpc/_grpcio_metadata.py
# AUTO-GENERATED BY make_grpcio_tools.py
Expand Down
7 changes: 7 additions & 0 deletions build_handwritten.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ settings:
csharp_major_version: 2
g_stands_for: groovy
protobuf_version: 3.28.1
supported_python_versions:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
version: 1.68.0-dev
configs:
asan:
Expand Down
27 changes: 15 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,29 @@
import _parallel_compile_patch
import _spawn_patch
import grpc_core_dependencies
import python_version

import commands
import grpc_version

_parallel_compile_patch.monkeypatch_compile_maybe()
_spawn_patch.monkeypatch_spawn()


LICENSE = "Apache License 2.0"

CLASSIFIERS = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
]
CLASSIFIERS = (
[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
+ [
f"Programming Language :: Python :: {x}"
for x in python_version.SUPPORTED_PYTHON_VERSIONS
]
+ ["License :: OSI Approved :: Apache Software License"]
)


def _env_bool_value(env_name, default):
Expand Down Expand Up @@ -596,7 +599,7 @@ def cython_extensions_and_necessity():
packages=list(PACKAGES),
package_dir=PACKAGE_DIRECTORIES,
package_data=PACKAGE_DATA,
python_requires=">=3.8",
python_requires=f">={python_version.MIN_PYTHON_VERSION}",
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRES,
setup_requires=SETUP_REQUIRES,
Expand Down
3 changes: 0 additions & 3 deletions src/python/grpcio/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Package for gRPC Python.
.. |compat_check_pypi| image:: https://python-compatibility-tools.appspot.com/one_badge_image?package=grpcio
:target: https://python-compatibility-tools.appspot.com/one_badge_target?package=grpcio

Supported Python Versions
-------------------------
Python >= 3.8

Installation
------------
Expand Down
20 changes: 20 additions & 0 deletions src/python/grpcio/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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/src/python/grpcio/python_version.py.template`!!!

SUPPORTED_PYTHON_VERSIONS = ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

MIN_PYTHON_VERSION = 3.8
MAX_PYTHON_VERSION = 3.13
1 change: 1 addition & 0 deletions src/python/grpcio_admin/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include grpc_version.py
include python_version.py
recursive-include grpc_admin *.py
global-exclude *.pyc
include LICENSE
20 changes: 20 additions & 0 deletions src/python/grpcio_admin/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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/src/python/grpcio_admin/python_version.py.template`!!!

SUPPORTED_PYTHON_VERSIONS = ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

MIN_PYTHON_VERSION = 3.8
MAX_PYTHON_VERSION = 3.13
5 changes: 4 additions & 1 deletion src/python/grpcio_admin/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Break import-style to ensure we can actually find our local modules.
import python_version

import grpc_version

CLASSIFIERS = [
Expand All @@ -44,6 +46,7 @@
)
SETUP_REQUIRES = INSTALL_REQUIRES


setuptools.setup(
name="grpcio-admin",
version=grpc_version.VERSION,
Expand All @@ -56,7 +59,7 @@
url="https://grpc.io",
package_dir=PACKAGE_DIRECTORIES,
packages=setuptools.find_packages("."),
python_requires=">=3.8",
python_requires=f">={python_version.MIN_PYTHON_VERSION}",
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
)
1 change: 1 addition & 0 deletions src/python/grpcio_channelz/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include grpc_version.py
include python_version.py
recursive-include grpc_channelz *.py *.pyi
global-exclude *.pyc
include LICENSE
3 changes: 0 additions & 3 deletions src/python/grpcio_channelz/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ gRPC Python Channelz package

Channelz is a live debug tool in gRPC Python.

Supported Python Versions
-------------------------
Python >= 3.8

Dependencies
------------
Expand Down
2 changes: 1 addition & 1 deletion src/python/grpcio_channelz/grpc_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_channelz/grpc_version.py.template`!!!
# AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_channelz/python_version.py.template`!!!

VERSION = '1.68.0.dev0'
20 changes: 20 additions & 0 deletions src/python/grpcio_channelz/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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/src/python/grpcio_channelz/python_version.py.template`!!!

SUPPORTED_PYTHON_VERSIONS = ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

MIN_PYTHON_VERSION = 3.8
MAX_PYTHON_VERSION = 3.13
29 changes: 17 additions & 12 deletions src/python/grpcio_channelz/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Break import-style to ensure we can actually find our local modules.
import python_version

import grpc_version


Expand All @@ -44,17 +46,19 @@ def run(self):
pass


CLASSIFIERS = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
]
CLASSIFIERS = (
[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
+ [
f"Programming Language :: Python :: {x}"
for x in python_version.SUPPORTED_PYTHON_VERSIONS
]
+ ["License :: OSI Approved :: Apache Software License"]
)


PACKAGE_DIRECTORIES = {
"": ".",
Expand Down Expand Up @@ -85,6 +89,7 @@ def run(self):
"build_package_protos": _NoOpCommand,
}


setuptools.setup(
name="grpcio-channelz",
version=grpc_version.VERSION,
Expand All @@ -97,7 +102,7 @@ def run(self):
url="https://grpc.io",
package_dir=PACKAGE_DIRECTORIES,
packages=setuptools.find_packages("."),
python_requires=">=3.8",
python_requires=f">={python_version.MIN_PYTHON_VERSION}",
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
cmdclass=COMMAND_CLASS,
Expand Down
1 change: 1 addition & 0 deletions src/python/grpcio_csds/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include grpc_version.py
include python_version.py
recursive-include grpc_csds *.py
global-exclude *.pyc
include LICENSE
20 changes: 20 additions & 0 deletions src/python/grpcio_csds/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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/src/python/grpcio_csds/python_version.py.template`!!!

SUPPORTED_PYTHON_VERSIONS = ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

MIN_PYTHON_VERSION = 3.8
MAX_PYTHON_VERSION = 3.13
4 changes: 3 additions & 1 deletion src/python/grpcio_csds/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Break import-style to ensure we can actually find our local modules.
import python_version

import grpc_version

CLASSIFIERS = [
Expand Down Expand Up @@ -57,7 +59,7 @@
url="https://grpc.io",
package_dir=PACKAGE_DIRECTORIES,
packages=setuptools.find_packages("."),
python_requires=">=3.8",
python_requires=f">={python_version.MIN_PYTHON_VERSION}",
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
)
1 change: 1 addition & 0 deletions src/python/grpcio_csm_observability/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
graft src/python/grpcio_csm_observability/grpc_csm_observability.egg-info
graft grpc_csm_observability
include grpc_version.py
include python_version.py
include README.rst
3 changes: 0 additions & 3 deletions src/python/grpcio_csm_observability/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ gRPC Python CSM Observability

Package for gRPC Python CSM Observability.

Supported Python Versions
-------------------------
Python >= 3.8

Installation
------------
Expand Down
20 changes: 20 additions & 0 deletions src/python/grpcio_csm_observability/python_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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/src/python/grpcio_csm_observability/python_version.py.template`!!!

SUPPORTED_PYTHON_VERSIONS = ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

MIN_PYTHON_VERSION = 3.8
MAX_PYTHON_VERSION = 3.13
4 changes: 3 additions & 1 deletion src/python/grpcio_csm_observability/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# Ensure we're in the proper directory whether or not we're being used by pip.
os.chdir(os.path.dirname(os.path.abspath(__file__)))

import python_version

import grpc_version

CLASSIFIERS = [
Expand Down Expand Up @@ -58,6 +60,6 @@
classifiers=CLASSIFIERS,
package_dir=PACKAGE_DIRECTORIES,
packages=setuptools.find_packages("."),
python_requires=">=3.8",
python_requires=f">={python_version.MIN_PYTHON_VERSION}",
install_requires=INSTALL_REQUIRES,
)
1 change: 1 addition & 0 deletions src/python/grpcio_health_checking/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include grpc_version.py
include python_version.py
recursive-include grpc_health *.py *.pyi
global-exclude *.pyc
include LICENSE
Loading

0 comments on commit b3ad5d1

Please sign in to comment.