From 083a630b44287acc323602d7060ea676db086dad Mon Sep 17 00:00:00 2001 From: rxxg Date: Thu, 16 Jan 2020 17:08:07 +0100 Subject: [PATCH] Fallback to standard Python code in case of missing packages --- dvc/system.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/dvc/system.py b/dvc/system.py index 7a6a70250..c300daac5 100644 --- a/dvc/system.py +++ b/dvc/system.py @@ -2,13 +2,30 @@ import errno import logging import os import platform +import shutil from dvc.compat import fspath from dvc.exceptions import DvcException - logger = logging.getLogger(__name__) +if platform.system() == "Windows": + try: + import speedcopy + + speedcopy.patch_copyfile() + except ImportError: + pass +else: + import sys + + if sys.version_info < (3, 8): + try: + # Importing the module monkey-patches shutil.copyfile + import pyfastcopy # noqa: F401 + except ImportError: + pass + class System(object): @staticmethod @@ -18,20 +35,7 @@ class System(object): @staticmethod def copy(src, dest): src, dest = fspath(src), fspath(dest) - system = platform.system() - if system == "Windows": - import speedcopy - - return speedcopy.copyfile(src, dest) - else: - import shutil - import sys - - if sys.version_info < (3, 8): - # Importing the module monkey-patches shutil.copyfile - import pyfastcopy # noqa: F401 - - return shutil.copyfile(src, dest) + return shutil.copyfile(src, dest) @staticmethod def hardlink(source, link_name):