mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00

* fix output typing, change mutable list to immutable tuple * import missed type * format --------- Co-authored-by: Leymore <zfz-960727@163.com>
22 lines
652 B
Python
22 lines
652 B
Python
import fnmatch
|
|
import os
|
|
from typing import List, Tuple, Union
|
|
|
|
|
|
def match_files(path: str,
|
|
pattern: Union[str, List],
|
|
fuzzy: bool = False) -> List[Tuple[str, str]]:
|
|
if isinstance(pattern, str):
|
|
pattern = [pattern]
|
|
if fuzzy:
|
|
pattern = [f'*{p}*' for p in pattern]
|
|
files_list = []
|
|
for root, _, files in os.walk(path):
|
|
for name in files:
|
|
for p in pattern:
|
|
if fnmatch.fnmatch(name.lower(), p.lower()):
|
|
files_list.append((name[:-3], os.path.join(root, name)))
|
|
break
|
|
|
|
return sorted(files_list, key=lambda x: x[0])
|