MCPcopy Create free account
hub / github.com/MotrixLab/FineMoGen / check_input_path

Function check_input_path

mogen/utils/path_utils.py:190–232  ·  view source on GitHub ↗

Check input folder or file. Args: input_path (str): input folder or file path. allowed_suffix (List[str], optional): Check the suffix of `input_path`. If folder, should be [] or ['']. If could both be folder or file, should be [suffixs..., ''].

(
    input_path: str,
    allowed_suffix: List[str] = [],
    tag: str = 'input file',
    path_type: Literal['file', 'dir', 'auto'] = 'auto',
)

Source from the content-addressed store, hash-verified

188
189
190def check_input_path(
191 input_path: str,
192 allowed_suffix: List[str] = [],
193 tag: str = 'input file',
194 path_type: Literal['file', 'dir', 'auto'] = 'auto',
195):
196 """Check input folder or file.
197
198 Args:
199 input_path (str): input folder or file path.
200 allowed_suffix (List[str], optional):
201 Check the suffix of `input_path`. If folder, should be [] or [''].
202 If could both be folder or file, should be [suffixs..., ''].
203 Defaults to [].
204 tag (str, optional): The `string` tag to specify the output type.
205 Defaults to 'output file'.
206 path_type (Literal[, optional):
207 Choose `file` for file and `directory` for folder.
208 Choose `auto` if allowed to be both.
209 Defaults to 'auto'.
210
211 Raises:
212 FileNotFoundError: file does not exists or suffix does not match.
213
214 Returns:
215 None
216 """
217 if path_type.lower() == 'dir':
218 allowed_suffix = []
219 exist_result = check_path_existence(input_path, path_type=path_type)
220
221 if exist_result in [
222 Existence.FileExist, Existence.DirectoryExistEmpty,
223 Existence.DirectoryExistNotEmpty
224 ]:
225 suffix_matched = \
226 check_path_suffix(input_path, allowed_suffix=allowed_suffix)
227 if not suffix_matched:
228 raise FileNotFoundError(
229 f'The {tag} should be {", ".join(allowed_suffix)}:' +
230 f'{input_path}.')
231 else:
232 raise FileNotFoundError(f'The {tag} does not exist: {input_path}.')

Callers

nothing calls this directly

Calls 2

check_path_existenceFunction · 0.85
check_path_suffixFunction · 0.85

Tested by

no test coverage detected