Fix unzip_file() to directory issue (#6666)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
f89bfd7e01
commit
7c0e853237
3 changed files with 15 additions and 12 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue