From 2bd41ecfbb0b2b09168d11db5d7ae07181627374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20R=C3=B3wnicki?= Date: Thu, 6 Feb 2025 23:18:47 +0100 Subject: [PATCH] Platform independent verification of SoX --- pyaudioconvert/__init__.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/pyaudioconvert/__init__.py b/pyaudioconvert/__init__.py index fd15744..16906d0 100644 --- a/pyaudioconvert/__init__.py +++ b/pyaudioconvert/__init__.py @@ -8,25 +8,6 @@ RUN_ID = str(uuid.uuid4())[:4] -# check that sox is installed -def bool_which(program): - - def is_exe(fpath): - return os.path.isfile(fpath) and os.access(fpath, os.X_OK) - - fpath, fname = os.path.split(program) - if fpath: - if is_exe(program): - return True - else: - for path in os.environ["PATH"].split(os.pathsep): - exe_file = os.path.join(path, program) - if is_exe(exe_file): - return True - - return False - - class SoxNotInstalled(Exception): pass @@ -40,8 +21,8 @@ class OverwriteFileError(Exception): try: - assert(bool_which('sox')) -except AssertionError: + assert("sox:" in subprocess.run("sox --version", capture_output=True).stdout.decode()) +except (AssertionError, FileNotFoundError): raise SoxNotInstalled() @@ -57,7 +38,6 @@ def _valid_readable_file(file_path): # def _valid_audiofile(audio_file_path): # return _valid_readable_file(audio_file_path) - def _is_24bit_audio(audio_file_path): # todo what about non-wavs?