Add suffix checks (#4711)

* Add suffix checks

* Cleanup

* Cleanup2

* Cleanup3
This commit is contained in:
Glenn Jocher authored and GitHub committed 2021-09-08 14:36:12 +02:00
1 parent 8e5f9ddbdb
commit a2b3c71636
7 files changed
+41 -21

No files matched your search

+16 -1
View File
@@ -242,8 +242,23 @@ def check_imshow():
return False
def check_file(file):
def check_suffix(file='yolov5s.pt', suffix=('.pt',), msg=''):
# Check file(s) for acceptable suffixes
if any(suffix):
if isinstance(suffix, str):
suffix = [suffix]
for f in file if isinstance(file, (list, tuple)) else [file]:
assert Path(f).suffix.lower() in suffix, f"{msg}{f} acceptable suffix is {suffix}"
def check_yaml(file, suffix=('.yaml', '.yml')):
# Check YAML file(s) for acceptable suffixes
return check_file(file, suffix)
def check_file(file, suffix=''):
# Search/download file (if necessary) and return path
check_suffix(file, suffix)
file = str(file) # convert to str()
if Path(file).is_file() or file == '': # exists
return file