diff --git a/sdks/python/gen_protos.py b/sdks/python/gen_protos.py index a2cd1bd4cef3..d07f046fd229 100644 --- a/sdks/python/gen_protos.py +++ b/sdks/python/gen_protos.py @@ -21,6 +21,7 @@ import argparse import contextlib import glob +import importlib.resources import inspect import logging import os @@ -31,8 +32,6 @@ from collections import defaultdict from importlib import import_module -import pkg_resources - LOG = logging.getLogger() LOG.setLevel(logging.INFO) @@ -474,7 +473,7 @@ def generate_proto_files(force=False): protoc_gen_mypy = _find_protoc_gen_mypy() from grpc_tools import protoc - builtin_protos = pkg_resources.resource_filename('grpc_tools', '_proto') + builtin_protos = importlib.resources.files('grpc_tools') / '_proto' args = ( [sys.executable] + # expecting to be called from command line ['--proto_path=%s' % builtin_protos] + diff --git a/sdks/python/setup.py b/sdks/python/setup.py index d6c4088c1be4..a98eaab33361 100644 --- a/sdks/python/setup.py +++ b/sdks/python/setup.py @@ -31,9 +31,7 @@ # pylint: disable=ungrouped-imports import setuptools -from pkg_resources import normalize_path -from pkg_resources import parse_version -from pkg_resources import to_filename +from packaging.version import parse from setuptools import Command # pylint: disable=wrong-import-order @@ -43,6 +41,14 @@ from distutils.errors import DistutilsError # isort:skip +def to_filename(name: str) -> str: + return name.replace('-', '_') + + +def normalize_path(filename): + return os.path.normcase(os.path.realpath(os.path.normpath(filename))) + + class mypy(Command): user_options = [] @@ -101,7 +107,7 @@ def get_version(): RECOMMENDED_MIN_PIP_VERSION = '19.3.0' try: _PIP_VERSION = distribution('pip').version - if parse_version(_PIP_VERSION) < parse_version(RECOMMENDED_MIN_PIP_VERSION): + if parse(_PIP_VERSION) < parse(RECOMMENDED_MIN_PIP_VERSION): warnings.warn( "You are using version {0} of pip. " \ "However, the recommended min version is {1}.".format( @@ -116,7 +122,7 @@ def get_version(): REQUIRED_CYTHON_VERSION = '3.0.0' try: _CYTHON_VERSION = distribution('cython').version - if parse_version(_CYTHON_VERSION) < parse_version(REQUIRED_CYTHON_VERSION): + if parse(_CYTHON_VERSION) < parse(REQUIRED_CYTHON_VERSION): warnings.warn( "You are using version {0} of cython. " \ "However, version {1} is recommended.".format( @@ -355,7 +361,7 @@ def get_portability_package_data(): 'fasteners>=0.3,<1.0', # TODO(https://github.com/grpc/grpc/issues/37710): Unpin grpc 'grpcio>=1.33.1,<2,!=1.48.0,!=1.59.*,!=1.60.*,!=1.61.*,!=1.62.0,!=1.62.1,<1.66.0; python_version <= "3.12"', # pylint: disable=line-too-long - 'grpcio>=1.67.0; python_version >= "3.13"', + 'grpcio>=1.67.0; python_version >= "3.13"', 'hdfs>=2.1.0,<3.0.0', 'httplib2>=0.8,<0.23.0', 'jsonschema>=4.0.0,<5.0.0',