ras-commander 0.35.0__py3-none-any.whl → 0.37.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,142 @@
1
+ import os
2
+ from pathlib import Path
3
+ from typing import Optional
4
+ from ras_commander import get_logger, log_call
5
+
6
+ logger = get_logger(__name__)
7
+
8
+ class RasGpt:
9
+ """
10
+ A class containing helper functions for the RAS Commander GPT.
11
+ """
12
+
13
+ # READ Functions to allow GPT to read library files quickly
14
+
15
+ @classmethod
16
+ @log_call
17
+ def read_library_guide(cls) -> Optional[str]:
18
+ """
19
+ Reads and returns the contents of the Comprehensive_Library_Guide.md file.
20
+
21
+ Returns:
22
+ Optional[str]: The contents of the file, or None if the file is not found.
23
+ """
24
+ file_path = Path(__file__).parent.parent / "docs" / "Comprehensive_Library_Guide.md"
25
+ return cls._read_file(file_path)
26
+
27
+
28
+ # ADD FOR read_reaadme and read_function_list
29
+ # Need to add a function list separate from the Library Guide
30
+
31
+ # ADD for read_example_list which will read the example folder README.ModuleNotFoundError
32
+
33
+
34
+
35
+
36
+
37
+ @classmethod
38
+ @log_call
39
+ def read_style_guide(cls) -> Optional[str]:
40
+ """
41
+ Reads and returns the contents of the STYLE_GUIDE.md file.
42
+
43
+ Returns:
44
+ Optional[str]: The contents of the file, or None if the file is not found.
45
+ """
46
+ file_path = Path(__file__).parent.parent / "docs" / "STYLE_GUIDE.md"
47
+ return cls._read_file(file_path)
48
+
49
+
50
+ # READ CLASS FILE FUNCTIONS:
51
+
52
+ @classmethod
53
+ @log_call
54
+ def read_class_rascmdr(cls) -> Optional[str]:
55
+ """
56
+ Reads and returns the contents of the RasCmdr.py file.
57
+
58
+ Returns:
59
+ Optional[str]: The contents of the file, or None if the file is not found.
60
+ """
61
+ file_path = Path(__file__).parent / "RasCmdr.py"
62
+ return cls._read_file(file_path)
63
+
64
+ # add one for each class file
65
+
66
+
67
+
68
+
69
+
70
+ # Public Helper Functions:
71
+
72
+
73
+ @classmethod
74
+ @log_call
75
+ def get_file_structure(cls, directory: Optional[str] = None) -> str:
76
+ """
77
+ Returns a string representation of the file structure of the ras_commander package.
78
+
79
+ Args:
80
+ directory (Optional[str]): The directory to start from. If None, uses the package root.
81
+
82
+ Returns:
83
+ str: A string representation of the file structure.
84
+ """
85
+ if directory is None:
86
+ directory = Path(__file__).parent
87
+
88
+ return cls._get_directory_structure(directory)
89
+
90
+
91
+
92
+
93
+ # Private Helper Functions:
94
+
95
+ @staticmethod
96
+ def _read_file(file_path: Path) -> Optional[str]:
97
+ """
98
+ Helper method to read the contents of a file.
99
+
100
+ Args:
101
+ file_path (Path): The path to the file to be read.
102
+
103
+ Returns:
104
+ Optional[str]: The contents of the file, or None if the file is not found.
105
+ """
106
+ try:
107
+ with open(file_path, 'r', encoding='utf-8') as file:
108
+ return file.read()
109
+ except FileNotFoundError:
110
+ logger.error(f"File not found: {file_path}")
111
+ return None
112
+ except Exception as e:
113
+ logger.error(f"Error reading file {file_path}: {str(e)}")
114
+ return None
115
+
116
+
117
+ @staticmethod
118
+ def _get_directory_structure(directory: Path, prefix: str = "") -> str:
119
+ """
120
+ Helper method to recursively build the directory structure string.
121
+
122
+ Args:
123
+ directory (Path): The directory to process.
124
+ prefix (str): The prefix to use for the current level.
125
+
126
+ Returns:
127
+ str: A string representation of the directory structure.
128
+ """
129
+ if not directory.is_dir():
130
+ return ""
131
+
132
+ output = []
133
+ for item in sorted(directory.iterdir()):
134
+ if item.name.startswith('.'):
135
+ continue
136
+ if item.is_dir():
137
+ output.append(f"{prefix}{item.name}/")
138
+ output.append(RasGpt._get_directory_structure(item, prefix + " "))
139
+ else:
140
+ output.append(f"{prefix}{item.name}")
141
+
142
+ return "\n".join(output)