From 7c0e85323716c46a605d529bcb9b28f618e63a88 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 30 Nov 2023 00:32:51 +0100 Subject: [PATCH] Fix `unzip_file()` to directory issue (#6666) Signed-off-by: Glenn Jocher Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/en/integrations/clearml.md | 4 ++-- ultralytics/utils/checks.py | 13 +++++++------ ultralytics/utils/downloads.py | 10 ++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/en/integrations/clearml.md b/docs/en/integrations/clearml.md index 43b28a9be0..ca3e85fab4 100644 --- a/docs/en/integrations/clearml.md +++ b/docs/en/integrations/clearml.md @@ -171,8 +171,8 @@ This setup is applicable to cloud VMs, local GPUs, or laptops. ClearML Autoscale ClearML's user-friendly interface allows easy cloning, editing, and enqueuing of tasks. Users can clone an existing experiment, adjust parameters or other details through the UI, and enqueue the task for execution. This streamlined process ensures that the ClearML Agent executing the task uses updated configurations, making it ideal for iterative experimentation and model fine-tuning. -

- Cloning, Editing, and Enqueuing with ClearML +


+ Cloning, Editing, and Enqueuing with ClearML

## Summary diff --git a/ultralytics/utils/checks.py b/ultralytics/utils/checks.py index cbc1894a5e..ed804fff5f 100644 --- a/ultralytics/utils/checks.py +++ b/ultralytics/utils/checks.py @@ -196,11 +196,13 @@ def check_version(current: str = '0.0.0', if not required: # if required is '' or None return True + op = '' + version = '' result = True c = parse_version(current) # '1.2.3' -> (1, 2, 3) for r in required.strip(',').split(','): - op, v = re.match(r'([^0-9]*)([\d.]+)', r).groups() # split '>=22.04' -> ('>=', '22.04') - v = parse_version(v) # '1.2.3' -> (1, 2, 3) + op, version = re.match(r'([^0-9]*)([\d.]+)', r).groups() # split '>=22.04' -> ('>=', '22.04') + v = parse_version(version) # '1.2.3' -> (1, 2, 3) if op == '==' and c != v: result = False elif op == '!=' and c == v: @@ -214,12 +216,11 @@ def check_version(current: str = '0.0.0', elif op == '<' and not (c < v): result = False if not result: - warning_message = \ - f'WARNING ⚠️ {name}{op}{required} is required, but {name}=={current} is currently installed {msg}' + warning = f'WARNING ⚠️ {name}{op}{version} is required, but {name}=={current} is currently installed {msg}' if hard: - raise ModuleNotFoundError(emojis(warning_message)) # assert version requirements met + raise ModuleNotFoundError(emojis(warning)) # assert version requirements met if verbose: - LOGGER.warning(warning_message) + LOGGER.warning(warning) return result diff --git a/ultralytics/utils/downloads.py b/ultralytics/utils/downloads.py index 98bf1ee5bd..e26474498b 100644 --- a/ultralytics/utils/downloads.py +++ b/ultralytics/utils/downloads.py @@ -161,9 +161,11 @@ def unzip_file(file, path=None, exclude=('.DS_Store', '__MACOSX'), exist_ok=Fals files = [f for f in zipObj.namelist() if all(x not in f for x in exclude)] top_level_dirs = {Path(f).parts[0] for f in files} - if len(top_level_dirs) > 1 or not files[0].endswith('/'): # zip has multiple files at top level + if len(top_level_dirs) > 1 or (len(files) > 1 and not files[0].endswith('/')): + # Zip has multiple files at top level path = extract_path = Path(path) / Path(file).stem # i.e. ../datasets/coco8 - else: # zip has 1 top-level directory + else: + # Zip has 1 top-level directory extract_path = path # i.e. ../datasets path = Path(path) / list(top_level_dirs)[0] # i.e. ../datasets/coco8 @@ -338,11 +340,11 @@ def safe_download(url, if unzip and f.exists() and f.suffix in ('', '.zip', '.tar', '.gz'): from zipfile import is_zipfile - unzip_dir = dir or f.parent # unzip to dir if provided else unzip in place + unzip_dir = (dir or f.parent).resolve() # unzip to dir if provided else unzip in place if is_zipfile(f): unzip_dir = unzip_file(file=f, path=unzip_dir, progress=progress) # unzip elif f.suffix in ('.tar', '.gz'): - LOGGER.info(f'Unzipping {f} to {unzip_dir.resolve()}...') + LOGGER.info(f'Unzipping {f} to {unzip_dir}...') subprocess.run(['tar', 'xf' if f.suffix == '.tar' else 'xfz', f, '--directory', unzip_dir], check=True) if delete: f.unlink() # remove zip