aws / aws-msk-iam-sasl-signer-python

Apache License 2.0
32 stars 10 forks source link

pkg_resources deprecation in Python 3.12 #40

Open stephanwindischmann opened 1 week ago

stephanwindischmann commented 1 week ago

Description

pkg_resources was removed in Python 3.12 and offloaded into the setuptools library. The recommendation (see https://setuptools.pypa.io/en/latest/pkg_resources.html) is to use importlib.metadata.

Deprecatin warning:

/home/windi/.pyenv/versions/3.12.4/lib/python3.12/site-packages/aws_msk_iam_sasl_signer/MSKAuthTokenProvider.py:11: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources

It is a fairly trivial fix, just replace return f"{LIB_NAME}/{pkg_resources.get_distribution(LIB_NAME).version}" in __get_user_agent__() with return f"{LIB_NAME}/{importlib.metadata.version(LIB_NAME)}" e.g.,

import importlib.metadata

# …

def __get_user_agent__():
    """
    Builds the user-agent

    Returns:
        str: The user-agent identifying this signer library.
    """
    return f"{LIB_NAME}/{importlib.metadata.version(LIB_NAME)}"