From 674541f9225ee96acd237bfb8791ace3738ffa49 Mon Sep 17 00:00:00 2001 From: rxxg Date: Thu, 9 Jan 2020 17:57:15 +0100 Subject: [PATCH] Use pyfastcopy for non-Windows systems using Python < 3.8 --- dvc/system.py | 19 +++++++++++++++---- setup.py | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dvc/system.py b/dvc/system.py index a6fc77bf4..7a6a70250 100644 --- a/dvc/system.py +++ b/dvc/system.py @@ -1,7 +1,7 @@ import errno import logging import os -import speedcopy +import platform from dvc.compat import fspath from dvc.exceptions import DvcException @@ -18,7 +18,20 @@ class System(object): @staticmethod def copy(src, dest): src, dest = fspath(src), fspath(dest) - return speedcopy.copyfile(src, 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) @staticmethod def hardlink(source, link_name): @@ -90,8 +103,6 @@ class System(object): @staticmethod def reflink(source, link_name): - import platform - source, link_name = fspath(source), fspath(link_name) system = platform.system() diff --git a/setup.py b/setup.py index 5008f9ce3..13792fbc4 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ install_requires = [ "pywin32>=225; sys_platform == 'win32'", "networkx>=2.1,<2.4", "speedcopy @ git+https://github.com/rxxg/speedcopy@5", + "pyfastcopy>=1.0.3", ]