From 6c008a20067eb8574f4bd94acdd1d18ff7110d91 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 25 Aug 2023 21:23:29 -0600 Subject: [PATCH] script: replace deprecated pkg_resources with importlib.metadata in our python linter: ``` ./test/lint/lint-python.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html import pkg_resources ``` The importlib.metadata library was added in Python 3.8, which is currently our minimum-supported Python version. For more details about importlib.metadata, see https://docs.python.org/3/library/importlib.metadata.html --- test/lint/lint-python.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/lint/lint-python.py b/test/lint/lint-python.py index 539d0acb5d..6010c787cb 100755 --- a/test/lint/lint-python.py +++ b/test/lint/lint-python.py @@ -9,10 +9,12 @@ Check for specified flake8 and mypy warnings in python files. """ import os -import pkg_resources import subprocess import sys +from importlib.metadata import metadata, PackageNotFoundError + + DEPS = ['flake8', 'lief', 'mypy', 'pyzmq'] MYPY_CACHE_DIR = f"{os.getenv('BASE_ROOT_DIR', '')}/test/.mypy_cache" @@ -99,10 +101,10 @@ ENABLED = ( def check_dependencies(): - working_set = {pkg.key for pkg in pkg_resources.working_set} - for dep in DEPS: - if dep not in working_set: + try: + metadata(dep) + except PackageNotFoundError: print(f"Skipping Python linting since {dep} is not installed.") exit(0)