mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
remove pathlib / fspath changes related to the patch
This commit is contained in:
+14
-7
@@ -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
|
||||
|
||||
|
||||
+12
-7
@@ -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)
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
@@ -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, "
|
||||
|
||||
Reference in New Issue
Block a user