Coverage for physioblocks / io / aliases.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 16:40 +0100

1# SPDX-FileCopyrightText: Copyright INRIA 

2# 

3# SPDX-License-Identifier: LGPL-3.0-only 

4# 

5# Copyright INRIA 

6# 

7# This file is part of PhysioBlocks, a library mostly developed by the 

8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA. 

9# 

10# Authors: 

11# - Colin Drieu 

12# - Dominique Chapelle 

13# - François Kimmig 

14# - Philippe Moireau 

15# 

16# PhysioBlocks is free software: you can redistribute it and/or modify it under the 

17# terms of the GNU Lesser General Public License as published by the Free Software 

18# Foundation, version 3 of the License. 

19# 

20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY 

21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 

22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 

23# 

24# You should have received a copy of the GNU Lesser General Public License along with 

25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>. 

26 

27"""Defines methods to load aliases folders.""" 

28 

29from pathlib import Path 

30 

31from physioblocks.configuration.aliases import add_alias 

32from physioblocks.io.configuration import read_json 

33 

34 

35def load_aliases(path: str) -> None: 

36 """ 

37 Load all aliases recursively in the directory into the **Alias Register**. 

38 

39 .. warning:: 

40 

41 The given key for each alias is its file name without extensions. 

42 It has to be unique. 

43 

44 :param path: the alias directory path to load. 

45 :type path: Path 

46 """ 

47 directory_path = Path(path) 

48 

49 if directory_path.is_dir() is False: 

50 raise OSError( 

51 str.format( 

52 "Provided alias directory is not a folder: {0}", 

53 directory_path, 

54 ) 

55 ) 

56 

57 if directory_path.exists() is False: 

58 raise OSError( 

59 str.format( 

60 "Provided alias directory do not exist: {0}", 

61 directory_path, 

62 ) 

63 ) 

64 

65 for child in directory_path.iterdir(): 

66 if child.is_dir(): 

67 # recursivly load child directories 

68 load_aliases(str(child)) 

69 else: 

70 config_alias = read_json(str(child)) 

71 # get file name without extension as alias id 

72 alias_id = child.name.removesuffix(child.suffix) 

73 add_alias(alias_id, config_alias)