Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions olive/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,15 @@ def all_files(path, ignore=None):
yield member


def copy_dir(src_dir, dst_dir, ignore=None, **kwargs):
def copy_dir(src_dir, dst_dir, ignore=None, ignore_errors=False, **kwargs):
"""Copy a directory recursively using `shutil.copytree`.

Handles shutil.Error exceptions that happen even though all files were copied successfully.

:param src_dir: The source directory. Can be a string or a `Path` object.
:param dst_dir: The destination directory. Can be a string or a `Path` object.
:param ignore: A callable that is used as `ignore` parameter to `shutil.copytree`.
:param ignore_errors: If True, suppress RuntimeError even when not all files were copied.
:param kwargs: Additional kwargs to pass to `shutil.copytree`.
"""
try:
Expand All @@ -449,7 +450,20 @@ def copy_dir(src_dir, dst_dir, ignore=None, **kwargs):
if not (dst_dir / member.relative_to(src_dir)).exists()
]
if not_copied:
raise RuntimeError(f"Failed to copy {not_copied}") from e
if ignore_errors:
preview = not_copied[:5]
extra = len(not_copied) - len(preview)
logger.warning(
"Received shutil.Error '%s' and %d files are missing from destination directory "
"(first %d: %s%s). Ignoring errors and continuing.",
e,
len(not_copied),
len(preview),
preview,
f" … and {extra} more" if extra else "",
)
Comment thread
anisia19 marked this conversation as resolved.
else:
raise RuntimeError(f"Failed to copy {not_copied}") from e
else:
logger.warning(
"Received shutil.Error '%s' but all required file names exist in destination directory. "
Expand Down
3 changes: 3 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from mockey.fixture import patch_mock_module

patch_mock_module()
Comment thread
anisia19 marked this conversation as resolved.
1 change: 1 addition & 0 deletions test/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ evaluate
marshmallow
ml_dtypes
mlflow
mockey<1.0.0
neural-compressor<2.4
nncf>=2.19.0
numpy<2.0.0
Expand Down