From 25da6d4de9cad9a049a07af25ca034a1d364ead2 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 9 Oct 2023 16:11:16 -0700 Subject: [PATCH 1/2] Replace deprecated usage of pkg_resources with importlib.resources --- clang_tidy/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clang_tidy/__init__.py b/clang_tidy/__init__.py index c4dac31..0db6379 100644 --- a/clang_tidy/__init__.py +++ b/clang_tidy/__init__.py @@ -2,14 +2,16 @@ import sys from pathlib import Path import functools -import pkg_resources +from importlib.resources import files import os @functools.lru_cache(maxsize=None) def _get_executable(name:str) -> Path: - possibles = [Path(pkg_resources.resource_filename('clang_tidy', f"data/bin/{name}{s}")) - for s in ("", ".exe", ".bin", ".dmg")] + possibles = [ + Path(files("clang_tidy") / f"data/bin/{name}{s}") + for s in ("", ".exe", ".bin", ".dmg") + ] for exe in possibles: if exe.exists(): if os.environ.get("CLANG_TIDY_WHEEL_VERBOSE", None): From d3cb95137c3c71f2e1cecf9313edaa0239df545a Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 11 Jan 2024 08:31:02 -0800 Subject: [PATCH 2/2] Use importlib API on Python 3.9 or later --- clang_tidy/__init__.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/clang_tidy/__init__.py b/clang_tidy/__init__.py index 0db6379..f84a393 100644 --- a/clang_tidy/__init__.py +++ b/clang_tidy/__init__.py @@ -2,16 +2,28 @@ import sys from pathlib import Path import functools -from importlib.resources import files import os +if sys.version_info.minor >= 9: + # Only available on 3.9 or later, and required on 3.12 + from importlib.resources import files +else: + import pkg_resources + @functools.lru_cache(maxsize=None) def _get_executable(name:str) -> Path: - possibles = [ - Path(files("clang_tidy") / f"data/bin/{name}{s}") - for s in ("", ".exe", ".bin", ".dmg") - ] + if sys.version_info.minor >= 9: + # Only available in 3.9 or later, and required in 3.12 + possibles = [ + Path(files("clang_tidy") / f"data/bin/{name}{s}") + for s in ("", ".exe", ".bin", ".dmg") + ] + else: + possibles = [ + Path(pkg_resources.resource_filename("clang_tidy", f"data/bin/{name}{s}")) + for s in ("", ".exe", ".bin", ".dmg") + ] for exe in possibles: if exe.exists(): if os.environ.get("CLANG_TIDY_WHEEL_VERBOSE", None):