From 7e8bdbd6035221c4ebae2058b21011f9b7ad6e7a Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Thu, 5 Dec 2019 19:37:15 -0600 Subject: [PATCH] remove pathlib / fspath changes related to the patch --- dvc/analytics.py | 21 ++++++++++++++------- dvc/config.py | 19 ++++++++++++------- dvc/lock.py | 6 +++--- dvc/utils/compat.py | 6 ------ 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/dvc/analytics.py b/dvc/analytics.py index 6501ece8f..0be3ed91a 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -1,5 +1,6 @@ import json import logging +import os import platform import requests import sys @@ -16,7 +17,7 @@ from dvc.lock import Lock, LockError from dvc.repo import Repo from dvc.scm import SCM from dvc.utils import env2bool, is_binary, makedirs -from dvc.utils.compat import str, FileNotFoundError, convert_to_unicode +from dvc.utils.compat import str, FileNotFoundError logger = logging.getLogger(__name__) @@ -132,18 +133,24 @@ def find_or_create_user_id(): IDs are generated randomly with UUID. """ config_dir = Config.get_global_config_dir() - fname = config_dir / "user_id" - lockfile = fname.with_suffix(".lock") + fname = os.path.join(config_dir, "user_id") + lockfile = os.path.join(config_dir, "user_id.lock") + + # Since the `fname` and `lockfile` are under the global config, + # we need to make sure such directory exist already + makedirs(config_dir, exist_ok=True) try: with Lock(lockfile): try: - user_id = json.loads(fname.read_text())["user_id"] + with open(fname, "r") as fobj: + user_id = json.load(fobj)["user_id"] + except (FileNotFoundError, ValueError, AttributeError): user_id = str(uuid.uuid4()) - makedirs(fname.parent, exist_ok=True) - data = convert_to_unicode(json.dumps({"user_id": user_id})) - fname.write_text(data) + + with open(fname, "w") as fobj: + json.dump({"user_id": user_id}, fobj) return user_id diff --git a/dvc/config.py b/dvc/config.py index 32c7a0977..62823deb6 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -13,7 +13,7 @@ from voluptuous import All, Any, Lower, Range, Coerce, Match from dvc.exceptions import DvcException from dvc.exceptions import NotDvcRepoError -from dvc.utils.compat import open, str, pathlib, fspath +from dvc.utils.compat import open, str logger = logging.getLogger(__name__) @@ -284,8 +284,8 @@ class Config(object): # pylint: disable=too-many-instance-attributes """ from appdirs import user_config_dir - return pathlib.Path( - user_config_dir(appname=Config.APPNAME, appauthor=Config.APPAUTHOR) + return user_config_dir( + appname=Config.APPNAME, appauthor=Config.APPAUTHOR ) @staticmethod @@ -297,8 +297,8 @@ class Config(object): # pylint: disable=too-many-instance-attributes """ from appdirs import site_config_dir - return pathlib.Path( - site_config_dir(appname=Config.APPNAME, appauthor=Config.APPAUTHOR) + return site_config_dir( + appname=Config.APPNAME, appauthor=Config.APPAUTHOR ) @staticmethod @@ -342,8 +342,13 @@ class Config(object): # pylint: disable=too-many-instance-attributes return ret def _load_configs(self): - system_config_file = fspath(self.get_system_config_dir() / self.CONFIG) - global_config_file = fspath(self.get_global_config_dir() / self.CONFIG) + system_config_file = os.path.join( + self.get_system_config_dir(), self.CONFIG + ) + + global_config_file = os.path.join( + self.get_global_config_dir(), self.CONFIG + ) self._system_config = configobj.ConfigObj(system_config_file) self._global_config = configobj.ConfigObj(global_config_file) diff --git a/dvc/lock.py b/dvc/lock.py index d4925e963..147118c0f 100644 --- a/dvc/lock.py +++ b/dvc/lock.py @@ -10,7 +10,7 @@ from funcy.py3 import lkeep from dvc.exceptions import DvcException from dvc.utils import makedirs -from dvc.utils.compat import is_py3, fspath +from dvc.utils.compat import is_py3 DEFAULT_TIMEOUT = 5 @@ -58,7 +58,7 @@ if is_py3: # [1] https://github.com/iterative/dvc/issues/2582 self._hostname = socket.gethostname() - self._lockfile = fspath(lockfile) + self._lockfile = lockfile self._lifetime = timedelta(days=365) # Lock for good by default self._separator = flufl.lock.SEP self._set_claimfile() @@ -111,7 +111,7 @@ else: """ def __init__(self, lockfile, tmp_dir=None): - self.lockfile = fspath(lockfile) + self.lockfile = lockfile self._lock = None @property diff --git a/dvc/utils/compat.py b/dvc/utils/compat.py index ab079c1d0..372c8d2c6 100644 --- a/dvc/utils/compat.py +++ b/dvc/utils/compat.py @@ -207,12 +207,6 @@ except ImportError: except AttributeError: if hasattr(path_type, "__fspath__"): raise - - # Support for pathlib.Path in Python 3.5, since it doesn't - # implement `__fspath__` - if isinstance(path, pathlib.Path): - return str(path) - else: raise TypeError( "expected str, bytes or os.PathLike object, "