From 45c2c72b60f5183e9533f51535b6bbecde03ff44 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 15 Apr 2020 17:47:52 +0300 Subject: [PATCH] remote: don't use PathInfo.from_posix (#3637) Using it to load dirs takes around 50 sec compared to 0.4 with simple `replace()`. Path objects are great, but not when you need lots of them. Related to #3635 --- dvc/path_info.py | 4 ---- dvc/remote/base.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dvc/path_info.py b/dvc/path_info.py index 4f757b00b..e502130aa 100644 --- a/dvc/path_info.py +++ b/dvc/path_info.py @@ -33,10 +33,6 @@ class PathInfo(pathlib.PurePath, _BasePath): cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo return cls._from_parts(args) - @classmethod - def from_posix(cls, s): - return cls(PosixPathInfo(s)) - def as_posix(self): f = self._flavour # Unlike original implementation [1] that uses `str()` we actually need diff --git a/dvc/remote/base.py b/dvc/remote/base.py index 0001ee5c6..93e22cdc2 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -21,7 +21,7 @@ from dvc.exceptions import ( RemoteCacheRequiredError, ) from dvc.ignore import DvcIgnore -from dvc.path_info import PathInfo, URLInfo +from dvc.path_info import PathInfo, URLInfo, WindowsPathInfo from dvc.progress import Tqdm from dvc.remote.slow_link_detection import slow_link_guard from dvc.state import StateNoop @@ -285,10 +285,13 @@ class RemoteBASE(object): ) return [] - for info in d: - # NOTE: here is a BUG, see comment to .as_posix() below - relative_path = PathInfo.from_posix(info[self.PARAM_RELPATH]) - info[self.PARAM_RELPATH] = relative_path.fspath + if self.path_cls == WindowsPathInfo: + # only need to convert it for Windows + for info in d: + # NOTE: here is a BUG, see comment to .as_posix() below + info[self.PARAM_RELPATH] = info[self.PARAM_RELPATH].replace( + "/", self.path_cls.sep + ) return d