|
3 | 3 | from pipelex.tools.config.models import ConfigModel |
4 | 4 | from pipelex.tools.misc.file_utils import copy_file_from_package, copy_folder_from_package, find_files_in_dir |
5 | 5 |
|
| 6 | +PIPELEX_LIBRARIES_PATH = "libraries" |
| 7 | + |
6 | 8 |
|
7 | 9 | class LibraryConfig(ConfigModel): |
8 | | - # Class variables |
9 | 10 | package_name: ClassVar[str] = "pipelex" |
10 | | - internal_library_root: ClassVar[str] = "libraries" |
11 | | - exported_library_root: ClassVar[str] = "pipelex_libraries" |
12 | | - internal_base_pipelines_path: ClassVar[str] = f"{internal_library_root}/pipelines" |
13 | | - exported_pipelines_path: ClassVar[str] = f"{exported_library_root}/pipelines" |
14 | | - exported_base_pipelines_path: ClassVar[str] = f"{exported_library_root}/pipelines/base_library" |
15 | | - loaded_pipelines_path: ClassVar[str] = f"{exported_library_root}/pipelines" |
16 | | - test_pipelines_path: ClassVar[str] = "tests/test_pipelines" |
17 | | - internal_llm_integrations_path: ClassVar[str] = f"{internal_library_root}/llm_integrations" |
18 | | - exported_llm_integrations_path: ClassVar[str] = f"{exported_library_root}/llm_integrations" |
19 | | - internal_llm_deck_path: ClassVar[str] = f"{internal_library_root}/llm_deck" |
20 | | - exported_llm_deck_path: ClassVar[str] = f"{exported_library_root}/llm_deck" |
21 | | - internal_templates_path: ClassVar[str] = f"{internal_library_root}/templates" |
22 | | - exported_templates_path: ClassVar[str] = f"{exported_library_root}/templates" |
23 | | - internal_plugins_path: ClassVar[str] = f"{internal_library_root}/plugins" |
24 | | - exported_plugins_path: ClassVar[str] = f"{exported_library_root}/plugins" |
25 | | - failing_pipelines_path: ClassVar[str] = "tests/test_pipelines/failing_pipelines.toml" |
26 | | - |
27 | | - @classmethod |
28 | | - def get_llm_deck_paths(cls) -> List[str]: |
29 | | - llm_deck_paths = [str(path) for path in find_files_in_dir(dir_path=cls.exported_llm_deck_path, pattern="*.toml", is_recursive=True)] |
| 11 | + config_folder_path: str = "pipelex_libraries" |
| 12 | + |
| 13 | + @property |
| 14 | + def config_file(self) -> str: |
| 15 | + return f"{self.config_folder_path}/config.toml" |
| 16 | + |
| 17 | + @property |
| 18 | + def pipelines_path(self) -> str: |
| 19 | + return f"{self.config_folder_path}/pipelines" |
| 20 | + |
| 21 | + @property |
| 22 | + def base_pipelines_path(self) -> str: |
| 23 | + return f"{self.config_folder_path}/pipelines/base_library" |
| 24 | + |
| 25 | + @property |
| 26 | + def llm_integrations_path(self) -> str: |
| 27 | + return f"{self.config_folder_path}/llm_integrations" |
| 28 | + |
| 29 | + @property |
| 30 | + def llm_deck_path(self) -> str: |
| 31 | + return f"{self.config_folder_path}/llm_deck" |
| 32 | + |
| 33 | + @property |
| 34 | + def templates_path(self) -> str: |
| 35 | + return f"{self.config_folder_path}/templates" |
| 36 | + |
| 37 | + @property |
| 38 | + def plugins_path(self) -> str: |
| 39 | + return f"{self.config_folder_path}/plugins" |
| 40 | + |
| 41 | + @property |
| 42 | + def test_pipelines_path(self) -> str: |
| 43 | + return "tests/test_pipelines" |
| 44 | + |
| 45 | + @property |
| 46 | + def failing_pipelines_path(self) -> str: |
| 47 | + return "tests/test_pipelines/failing_pipelines.toml" |
| 48 | + |
| 49 | + def get_llm_deck_paths(self) -> List[str]: |
| 50 | + llm_deck_paths = [str(path) for path in find_files_in_dir(dir_path=self.llm_deck_path, pattern="*.toml", is_recursive=True)] |
30 | 51 | llm_deck_paths.sort() |
31 | 52 | return llm_deck_paths |
32 | 53 |
|
33 | | - @classmethod |
34 | | - def get_templates_paths(cls) -> List[str]: |
35 | | - return [str(path) for path in find_files_in_dir(dir_path=cls.exported_templates_path, pattern="*.toml", is_recursive=True)] |
| 54 | + def get_templates_paths(self) -> List[str]: |
| 55 | + return [str(path) for path in find_files_in_dir(dir_path=self.templates_path, pattern="*.toml", is_recursive=True)] |
36 | 56 |
|
37 | | - @classmethod |
38 | | - def get_plugin_config_path(cls) -> str: |
39 | | - return f"{cls.exported_plugins_path}/plugin_config.toml" |
| 57 | + def get_default_plugin_config_path(self) -> str: |
| 58 | + """Get the default plugin config path.""" |
| 59 | + return f"{self.plugins_path}/plugin_config.toml" |
40 | 60 |
|
41 | | - @classmethod |
42 | | - def export_libraries(cls, overwrite: bool = False) -> None: |
| 61 | + def export_libraries(self, overwrite: bool = False) -> None: |
43 | 62 | """Duplicate pipelex libraries files in the client project, preserving directory structure.""" |
44 | 63 | # pipelines |
45 | 64 | copy_folder_from_package( |
46 | | - package_name=cls.package_name, |
47 | | - folder_path_in_package=cls.internal_base_pipelines_path, |
48 | | - target_dir=cls.exported_base_pipelines_path, |
| 65 | + package_name=self.package_name, |
| 66 | + folder_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/pipelines", |
| 67 | + target_dir=self.base_pipelines_path, |
49 | 68 | overwrite=overwrite, |
50 | 69 | ) |
51 | 70 | copy_file_from_package( |
52 | | - package_name=cls.package_name, |
53 | | - file_path_in_package=f"{cls.internal_library_root}/__init__.py", |
54 | | - target_path=f"{cls.exported_library_root}/__init__.py", |
| 71 | + package_name=self.package_name, |
| 72 | + file_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/__init__.py", |
| 73 | + target_path=f"{self.config_folder_path}/__init__.py", |
55 | 74 | overwrite=overwrite, |
56 | 75 | ) |
57 | 76 | copy_file_from_package( |
58 | | - package_name=cls.package_name, |
59 | | - file_path_in_package=f"{cls.internal_base_pipelines_path}/__init__.py", |
60 | | - target_path=f"{cls.exported_pipelines_path}/__init__.py", |
| 77 | + package_name=self.package_name, |
| 78 | + file_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/pipelines/__init__.py", |
| 79 | + target_path=f"{self.pipelines_path}/__init__.py", |
61 | 80 | overwrite=overwrite, |
62 | 81 | ) |
63 | 82 | copy_file_from_package( |
64 | | - package_name=cls.package_name, |
65 | | - file_path_in_package=f"{cls.internal_base_pipelines_path}/__init__.py", |
66 | | - target_path=f"{cls.exported_base_pipelines_path}/__init__.py", |
| 83 | + package_name=self.package_name, |
| 84 | + file_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/pipelines/__init__.py", |
| 85 | + target_path=f"{self.base_pipelines_path}/__init__.py", |
67 | 86 | overwrite=overwrite, |
68 | 87 | ) |
69 | | - |
70 | 88 | # llm_integrations |
71 | 89 | copy_folder_from_package( |
72 | | - package_name=cls.package_name, |
73 | | - folder_path_in_package=cls.internal_llm_integrations_path, |
74 | | - target_dir=cls.exported_llm_integrations_path, |
| 90 | + package_name=self.package_name, |
| 91 | + folder_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/llm_integrations", |
| 92 | + target_dir=self.llm_integrations_path, |
75 | 93 | overwrite=overwrite, |
76 | 94 | ) |
77 | 95 |
|
78 | 96 | # llm_deck |
79 | 97 | copy_folder_from_package( |
80 | | - package_name=cls.package_name, |
81 | | - folder_path_in_package=cls.internal_llm_deck_path, |
82 | | - target_dir=cls.exported_llm_deck_path, |
| 98 | + package_name=self.package_name, |
| 99 | + folder_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/llm_deck", |
| 100 | + target_dir=self.llm_deck_path, |
83 | 101 | overwrite=overwrite, |
84 | 102 | non_overwrite_files=["overrides.toml"], |
85 | 103 | ) |
86 | 104 |
|
87 | 105 | # templates |
88 | 106 | copy_folder_from_package( |
89 | | - package_name=cls.package_name, |
90 | | - folder_path_in_package=cls.internal_templates_path, |
91 | | - target_dir=cls.exported_templates_path, |
| 107 | + package_name=self.package_name, |
| 108 | + folder_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/templates", |
| 109 | + target_dir=self.templates_path, |
92 | 110 | overwrite=overwrite, |
93 | 111 | ) |
94 | 112 |
|
95 | 113 | # plugins |
96 | 114 | copy_folder_from_package( |
97 | | - package_name=cls.package_name, |
98 | | - folder_path_in_package=cls.internal_plugins_path, |
99 | | - target_dir=cls.exported_plugins_path, |
| 115 | + package_name=self.package_name, |
| 116 | + folder_path_in_package=f"{PIPELEX_LIBRARIES_PATH}/plugins", |
| 117 | + target_dir=self.plugins_path, |
100 | 118 | overwrite=overwrite, |
101 | 119 | ) |
0 commit comments