MCPcopy Create free account
hub / github.com/SourceCode-AI/aura / get_file_location

Function get_file_location

aura/config.py:157–183  ·  view source on GitHub ↗

Lookup a location of a file :param location: relative or absolute file location or a filename :param base_path: base path used for resolving relative paths or filenames :param exc: Flag, raise an exception if the file could not be found/does not exists :return: resolved path to

(location: str, base_path: Optional[str]=None, exc: bool=True)

Source from the content-addressed store, hash-verified

155
156
157def get_file_location(location: str, base_path: Optional[str]=None, exc: bool=True) -> str:
158 """
159 Lookup a location of a file
160
161 :param location: relative or absolute file location or a filename
162 :param base_path: base path used for resolving relative paths or filenames
163 :param exc: Flag, raise an exception if the file could not be found/does not exists
164 :return: resolved path to the given file location
165 """
166 if location.startswith("aura.data."): # Load file as a resource from aura package
167 return location
168
169 if os.path.exists(location):
170 return location
171
172 if base_path is not None:
173 pth = Path(base_path) / location
174 if pth.is_file():
175 return str(pth)
176 else:
177 pth = location
178
179 if exc:
180 # TODO: add location and base path directoly to the exception as variables for easy extraction
181 raise MissingFile(f"Can't find configuration file `{location}` using base path `{base_path}`")
182 else:
183 return pth
184
185
186def get_file_content(location: str, base_path: Optional[str]=None) -> str:

Callers 3

get_file_contentFunction · 0.85
get_pypi_stats_pathFunction · 0.85

Calls 2

MissingFileClass · 0.85
existsMethod · 0.45

Tested by

no test coverage detected