Coverage for src/videodataset/__init__.py: 84%

19 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2025-12-25 11:33 +0800

1""" 

2Copyright (c) 2025 agibot. All rights reserved. 

3 

4videodataset: A GPU-accelerated library that enables random frame access and efficient video decoding for data loading. 

5""" 

6 

7from __future__ import annotations 

8 

9import importlib 

10import os 

11import platform 

12 

13 

14def _setup_environment() -> None: 

15 """Setup environment variables and paths""" 

16 if platform.system() == "Linux": 

17 # Linux: Update LD_LIBRARY_PATH 

18 lib_paths: list[str] = [] 

19 

20 # Add torch library path for _decoder extension 

21 try: 

22 torch = importlib.import_module("torch") 

23 lib_paths.append(torch.__path__[0] + "/lib") 

24 except ImportError as e: 

25 err_msg = "Unable to import torch. Please ensure torch is installed." 

26 raise ImportError(err_msg) from e 

27 

28 if "LD_LIBRARY_PATH" in os.environ: 

29 lib_paths.extend(os.environ["LD_LIBRARY_PATH"].split(":")) 

30 

31 os.environ["LD_LIBRARY_PATH"] = ":".join(filter(None, lib_paths)) 

32 

33 

34_setup_environment() 

35 

36from videodataset._decoder import VideoDecoder # noqa: E402 

37 

38__all__ = ["VideoDecoder"]