diff --git a/comicapi/utils.py b/comicapi/utils.py index a135d78..6a1bb89 100644 --- a/comicapi/utils.py +++ b/comicapi/utils.py @@ -21,6 +21,7 @@ import pathlib import re import unicodedata from collections import defaultdict +from shutil import which # noqa: F401 from typing import Any, Mapping import pycountry @@ -77,25 +78,6 @@ def add_to_path(dirname: str) -> None: os.environ["PATH"] = dirname + os.pathsep + os.environ["PATH"] -def which(program: str) -> str | None: - """Returns path of the executable, if it exists""" - - def is_exe(fpath: str) -> bool: - return os.path.isfile(fpath) and os.access(fpath, os.X_OK) - - fpath, _ = os.path.split(program) - if fpath: - if is_exe(program): - return program - else: - for path in os.environ["PATH"].split(os.pathsep): - exe_file = os.path.join(path, program) - if is_exe(exe_file): - return exe_file - - return None - - def xlate(data: Any, is_int: bool = False) -> Any: if data is None or data == "": return None diff --git a/tests/comicarchive_test.py b/tests/comicarchive_test.py index 1161282..9bb9b06 100644 --- a/tests/comicarchive_test.py +++ b/tests/comicarchive_test.py @@ -89,7 +89,7 @@ archivers = [ comicapi.comicarchive.FolderArchiver, pytest.param( comicapi.comicarchive.RarArchiver, - marks=pytest.mark.xfail(not comicapi.comicarchive.rar_support, reason="rar support"), + marks=pytest.mark.xfail(not (comicapi.comicarchive.rar_support and shutil.which("rar")), reason="rar support"), ), ]