From 9d64ac34bc8fe122fdd9de3b38d3c0e68a9e2872 Mon Sep 17 00:00:00 2001 From: ali-ramadhan Date: Wed, 13 Aug 2025 14:24:57 -0600 Subject: [PATCH] warn user if ffmpeg is not available --- matplotloom/__init__.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/matplotloom/__init__.py b/matplotloom/__init__.py index e3064b0..76147c0 100644 --- a/matplotloom/__init__.py +++ b/matplotloom/__init__.py @@ -1,3 +1,38 @@ +import subprocess +import shutil +import warnings + from .loom import Loom __version__ = "0.8.1" +__all__ = ["Loom"] + + +def _check_ffmpeg_availability(): + """Check if ffmpeg is available on the system.""" + try: + # more reliable cross-platform + if shutil.which("ffmpeg") is not None: + return True + + # Fallback: try running ffmpeg with subprocess + subprocess.run( + ["ffmpeg", "-version"], + capture_output=True, + check=True, + timeout=5 + ) + return True + except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError): + return False + + +if not _check_ffmpeg_availability(): + warnings.warn( + "ffmpeg is not available on your system. " + "matplotloom requires ffmpeg to create animations. " + "Please install ffmpeg to use this library. " + "Visit https://ffmpeg.org/download.html for installation instructions.", + UserWarning, + stacklevel=2 + )