Skip to content

Commit

Permalink
fix: replace deprecated pkg_resources with importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
timmahrt committed Nov 4, 2023
1 parent 0f0544e commit 8d96fd7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions praatio/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8d96fd7

Please sign in to comment.