From dc25fd181cd100d87e838a21c1ad0f7073c13ba0 Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Thu, 5 Sep 2024 11:28:02 +0900 Subject: [PATCH] Improve error message for missing ffmpeg --- .github/workflows/conda_cpu_test.yml | 2 +- .github/workflows/conda_cuda_test.yml | 4 +--- src/spdl/lib/__init__.py | 12 ++++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/conda_cpu_test.yml b/.github/workflows/conda_cpu_test.yml index 736e6347c..eeaa96489 100644 --- a/.github/workflows/conda_cpu_test.yml +++ b/.github/workflows/conda_cpu_test.yml @@ -41,7 +41,7 @@ jobs: - name: Unit test run: | conda install -c file://${HOME}/package/ spdl - conda install -c conda-forge "ffmpeg==${{ matrix.ffmpeg-version}}" + conda install -c conda-forge "ffmpeg==${{ matrix.ffmpeg-version }}" conda install -c pytorch numpy pytest pytorch numba pytest -v \ tests/spdl_unittest/io/ \ diff --git a/.github/workflows/conda_cuda_test.yml b/.github/workflows/conda_cuda_test.yml index 4a4257542..fec170deb 100644 --- a/.github/workflows/conda_cuda_test.yml +++ b/.github/workflows/conda_cuda_test.yml @@ -48,10 +48,8 @@ jobs: - name: Unit test run: | conda install -c file://${HOME}/package/ spdl - conda install -c conda-forge "ffmpeg==${{ matrix.ffmpeg-version}}" + conda install -c conda-forge "ffmpeg==${{ matrix.ffmpeg-version }}" conda install pytorch pytorch-cuda=${{ inputs.cu-version }} -c pytorch -c nvidia conda install pytest numba - ffmpeg -version - python -c 'import logging;logging.basicConfig(level=logging.DEBUG);from spdl.lib import _libspdl;_libspdl.Demuxer' pytest -v \ tests/spdl_unittest/cuda/ diff --git a/src/spdl/lib/__init__.py b/src/spdl/lib/__init__.py index 92c634fe5..c98d6d02e 100644 --- a/src/spdl/lib/__init__.py +++ b/src/spdl/lib/__init__.py @@ -47,12 +47,14 @@ def _import_libspdl() -> ModuleType: ] # Newer FFmpeg first libs.sort(reverse=True) + err_msgs = {} for lib in libs: _LG.debug("Importing %s", lib) try: ext = importlib.import_module(lib) - except Exception: + except Exception as err: _LG.debug("Failed to import %s.", lib, exc_info=True) + err_msgs[lib] = str(err) continue try: @@ -77,7 +79,9 @@ def _import_libspdl() -> ModuleType: return ext - raise RuntimeError( - f"Failed to import libspdl. Tried {libs}. " - "Enable DEBUG logging to see details about the failure." + msg = ( + "Failed to import libspdl. " + "Enable DEBUG logging to see details about the failure. " + ", ".join(f"{k}: {v}" for k, v in err_msgs.items()) ) + raise RuntimeError(msg)