From 8d96fd782bf01a6c2dc50b68380cff28b55e8b46 Mon Sep 17 00:00:00 2001 From: Tim Mahrt Date: Sat, 4 Nov 2023 19:07:37 +0900 Subject: [PATCH] fix: replace deprecated pkg_resources with importlib --- praatio/utilities/utils.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/praatio/utilities/utils.py b/praatio/utilities/utils.py index 513bfa8..68c5f39 100644 --- a/praatio/utilities/utils.py +++ b/praatio/utilities/utils.py @@ -6,7 +6,7 @@ import subprocess import itertools import wave -from pkg_resources import resource_filename +import importlib.resources as pkg_resources from typing_extensions import Literal from typing import Any, Iterator, List, Tuple, NoReturn, Type, Optional @@ -15,11 +15,15 @@ Interval = constants.Interval -# Get the folder one level above the current folder -scriptsPath = resource_filename( - "praatio", - "praatScripts", -) +# New in python 3.9 +if hasattr(pkg_resources, "files"): + scriptsPath = pkg_resources.files("praatio") / "praatScripts" +# Deprecated in python 3.11 +else: + scriptsPath = pkg_resources.path( + "praatio", + "praatScripts", + ) def find(list, value, reverse) -> Optional[int]: @@ -386,7 +390,6 @@ def findAll(txt: str, subStr: str) -> List[int]: def runPraatScript( praatEXE: str, scriptFN: str, argList: List[Any], cwd: str = None ) -> None: - # Popen gives a not-very-transparent error if not os.path.exists(praatEXE): raise errors.FileNotFound(praatEXE)