|
1 | 1 | import os
|
2 | 2 | from typing import Sequence, Mapping, Any, Union
|
| 3 | +from pathlib import Path |
3 | 4 | import sys
|
4 | 5 |
|
5 | 6 | sys.path.append('../')
|
@@ -54,6 +55,39 @@ def search_directory(path: str) -> None:
|
54 | 55 | # Start the search from the current working directory
|
55 | 56 | search_directory(start_path)
|
56 | 57 |
|
| 58 | +def add_extra_model_paths() -> Path: |
| 59 | + """ |
| 60 | + Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path. |
| 61 | + """ |
| 62 | + from pathlib import Path |
| 63 | + from main import load_extra_path_config |
| 64 | + |
| 65 | + def find_config_file(path: str, name: str = "extra_model_paths.yaml") -> Path: |
| 66 | + # Check if the current directory contains the file |
| 67 | + if name in os.listdir(path): |
| 68 | + directory_path = os.path.join(path, name) |
| 69 | + print(f"{name} found: {directory_path}") |
| 70 | + return Path(directory_path) |
| 71 | + |
| 72 | + # Get the parent directory |
| 73 | + parent_directory = os.path.dirname(path) |
| 74 | + |
| 75 | + # If the parent directory is the same as the current directory, we've reached the root and stop the search |
| 76 | + if parent_directory == path: |
| 77 | + return |
| 78 | + |
| 79 | + # Recursively call the function with the parent directory |
| 80 | + return find_config_file(parent_directory) |
| 81 | + |
| 82 | + start_path = os.getcwd() # Get the current working directory |
| 83 | + file = find_config_file(start_path) |
| 84 | + |
| 85 | + if os.path.isfile(file): |
| 86 | + load_extra_path_config(file) |
| 87 | + else: |
| 88 | + print("Could not find the extra_model_paths config file.") |
| 89 | + |
| 90 | + |
57 | 91 |
|
58 | 92 | def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
59 | 93 | """Returns the value at the given index of a sequence or mapping.
|
|
0 commit comments