This is an automated email from the ASF dual-hosted git repository.

jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new a856eb9916b Replace usages of deprecated pkg_resources package (#35153)
a856eb9916b is described below

commit a856eb9916b3b75ad2a1116928a005672bce1915
Author: Jack McCluskey <[email protected]>
AuthorDate: Thu Jun 5 12:23:17 2025 -0400

    Replace usages of deprecated pkg_resources package (#35153)
    
    * Remove usages of deprecated pkg_resources package
    
    * use stdlib importlib.resources
    
    * remove extra comma
    
    * linting
    
    * import order
---
 sdks/python/gen_protos.py |  5 ++---
 sdks/python/setup.py      | 18 ++++++++++++------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/sdks/python/gen_protos.py b/sdks/python/gen_protos.py
index a2cd1bd4cef..d07f046fd22 100644
--- a/sdks/python/gen_protos.py
+++ b/sdks/python/gen_protos.py
@@ -21,6 +21,7 @@ Generates Python proto modules and grpc stubs for Beam protos.
 import argparse
 import contextlib
 import glob
+import importlib.resources
 import inspect
 import logging
 import os
@@ -31,8 +32,6 @@ import sys
 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 d6c4088c1be..a98eaab3336 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -31,9 +31,7 @@ from pathlib import Path
 
 # 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 setuptools import Command
 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 @@ different technologies and user communities.
 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 @@ except PackageNotFoundError:
 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 @@ if __name__ == '__main__':
           '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',

Reply via email to