mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
Drop Python 3.5 support (#3792)
* drop python 3.5 support * dvc: remove fspath() use inside os.path calls * dvc: replace dvc.compat.fspath with os.fspath * tests: replace dvc.compat.fspath with os.fspath * utils: relpath() should use fspath/str * utils: os.readlink doesn't support path-like obj on Windows until 3.8
This commit is contained in:
@@ -46,9 +46,6 @@ jobs:
|
||||
env:
|
||||
- PYTHON_VERSION=3.8.0
|
||||
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
|
||||
- name: "3.5 on Linux"
|
||||
language: python
|
||||
python: 3.5
|
||||
- name: "3.6 on Linux"
|
||||
language: python
|
||||
python: 3.6
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
"""Python version compatibility code"""
|
||||
|
||||
# Backport os.fspath() from Python 3.6
|
||||
try:
|
||||
from os import fspath # noqa: F821
|
||||
|
||||
fspath_py35 = lambda s: s # noqa: E731
|
||||
except ImportError:
|
||||
|
||||
def fspath(path):
|
||||
"""Return the path representation of a path-like object.
|
||||
|
||||
If str or bytes is passed in, it is returned unchanged. Otherwise the
|
||||
os.PathLike interface is used to get the path representation. If the
|
||||
path representation is not str or bytes, TypeError is raised. If the
|
||||
provided path is not str, bytes, or os.PathLike, TypeError is raised.
|
||||
"""
|
||||
if isinstance(path, (str, bytes)):
|
||||
return path
|
||||
|
||||
# Work from the object's type to match method resolution of other magic
|
||||
# methods.
|
||||
path_type = type(path)
|
||||
try:
|
||||
path_repr = path_type.__fspath__(path)
|
||||
except AttributeError:
|
||||
if hasattr(path_type, "__fspath__"):
|
||||
raise
|
||||
else:
|
||||
raise TypeError(
|
||||
"expected str, bytes or os.PathLike object, "
|
||||
"not " + path_type.__name__
|
||||
)
|
||||
if isinstance(path_repr, (str, bytes)):
|
||||
return path_repr
|
||||
else:
|
||||
raise TypeError(
|
||||
"expected {}.__fspath__() to return str or bytes, "
|
||||
"not {}".format(path_type.__name__, type(path_repr).__name__)
|
||||
)
|
||||
|
||||
fspath_py35 = fspath
|
||||
@@ -5,7 +5,6 @@ import dpath.util
|
||||
import yaml
|
||||
from voluptuous import Any
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.dependency.local import LocalDependency
|
||||
from dvc.exceptions import DvcException
|
||||
|
||||
@@ -87,7 +86,7 @@ class ParamsDependency(LocalDependency):
|
||||
if not self.exists:
|
||||
return {}
|
||||
|
||||
with self.repo.tree.open(fspath_py35(self.path_info), "r") as fobj:
|
||||
with self.repo.tree.open(self.path_info, "r") as fobj:
|
||||
try:
|
||||
config = yaml.safe_load(fobj)
|
||||
except yaml.YAMLError as exc:
|
||||
|
||||
@@ -7,7 +7,6 @@ from distutils.dir_util import copy_tree
|
||||
|
||||
from funcy import cached_property, retry, suppress, wrap_with
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.config import NoRemoteError, NotDvcRepoError
|
||||
from dvc.exceptions import (
|
||||
CheckoutError,
|
||||
@@ -84,7 +83,7 @@ class ExternalRepo(Repo):
|
||||
path_info = PathInfo(self.root_dir) / path
|
||||
|
||||
with suppress(OutputNotFoundError):
|
||||
(out,) = self.find_outs_by_path(fspath(path_info), strict=False)
|
||||
(out,) = self.find_outs_by_path(path_info, strict=False)
|
||||
|
||||
try:
|
||||
if out and out.use_cache:
|
||||
@@ -95,7 +94,7 @@ class ExternalRepo(Repo):
|
||||
if os.path.isabs(path):
|
||||
raise FileNotFoundError
|
||||
|
||||
fs_copy(fspath(path_info), fspath(to_info))
|
||||
fs_copy(path_info, to_info)
|
||||
except FileNotFoundError:
|
||||
raise PathMissingError(path, self.url)
|
||||
|
||||
@@ -188,7 +187,7 @@ class ExternalGitRepo:
|
||||
if os.path.isabs(path):
|
||||
raise FileNotFoundError
|
||||
|
||||
fs_copy(os.path.join(self.root_dir, path), fspath(to_info))
|
||||
fs_copy(os.path.join(self.root_dir, path), to_info)
|
||||
except FileNotFoundError:
|
||||
raise PathMissingError(path, self.url)
|
||||
|
||||
|
||||
+2
-3
@@ -2,7 +2,6 @@ import logging
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.istextfile import istextfile
|
||||
from dvc.output.base import BaseOutput
|
||||
@@ -38,7 +37,7 @@ class LocalOutput(BaseOutput):
|
||||
if not p.is_absolute():
|
||||
p = self.stage.wdir / p
|
||||
|
||||
abs_p = os.path.abspath(os.path.normpath(fspath_py35(p)))
|
||||
abs_p = os.path.abspath(os.path.normpath(p))
|
||||
return self.REMOTE.path_cls(abs_p)
|
||||
|
||||
def __str__(self):
|
||||
@@ -75,7 +74,7 @@ class LocalOutput(BaseOutput):
|
||||
if not self.metric:
|
||||
return
|
||||
|
||||
path = fspath_py35(self.path_info)
|
||||
path = os.fspath(self.path_info)
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ class PathInfo(pathlib.PurePath, _BasePath):
|
||||
return "{}: '{}'".format(type(self).__name__, self)
|
||||
|
||||
# This permits passing it to file utils directly in Python 3.6+
|
||||
# With Python 2.7, Python 3.5+ we are stuck with path_info.fspath for now
|
||||
def __fspath__(self):
|
||||
return pathlib.PurePath.__str__(self)
|
||||
|
||||
|
||||
+12
-13
@@ -8,7 +8,6 @@ from functools import partial
|
||||
from funcy import cached_property, concat
|
||||
from shortuuid import uuid
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.exceptions import DownloadError, DvcException, UploadError
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.progress import Tqdm
|
||||
@@ -95,7 +94,7 @@ class LocalRemote(BaseRemote):
|
||||
def exists(self, path_info):
|
||||
assert is_working_tree(self.repo.tree)
|
||||
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||
return self.repo.tree.exists(fspath_py35(path_info))
|
||||
return self.repo.tree.exists(path_info)
|
||||
|
||||
def makedirs(self, path_info):
|
||||
makedirs(path_info, exist_ok=True, mode=self._dir_mode)
|
||||
@@ -129,11 +128,11 @@ class LocalRemote(BaseRemote):
|
||||
|
||||
@staticmethod
|
||||
def isfile(path_info):
|
||||
return os.path.isfile(fspath_py35(path_info))
|
||||
return os.path.isfile(path_info)
|
||||
|
||||
@staticmethod
|
||||
def isdir(path_info):
|
||||
return os.path.isdir(fspath_py35(path_info))
|
||||
return os.path.isdir(path_info)
|
||||
|
||||
def iscopy(self, path_info):
|
||||
return not (
|
||||
@@ -142,7 +141,7 @@ class LocalRemote(BaseRemote):
|
||||
|
||||
@staticmethod
|
||||
def getsize(path_info):
|
||||
return os.path.getsize(fspath_py35(path_info))
|
||||
return os.path.getsize(path_info)
|
||||
|
||||
def walk_files(self, path_info):
|
||||
assert is_working_tree(self.repo.tree)
|
||||
@@ -182,8 +181,8 @@ class LocalRemote(BaseRemote):
|
||||
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
||||
try:
|
||||
System.copy(from_info, tmp_info)
|
||||
os.chmod(fspath_py35(tmp_info), self._file_mode)
|
||||
os.rename(fspath_py35(tmp_info), fspath_py35(to_info))
|
||||
os.chmod(tmp_info, self._file_mode)
|
||||
os.rename(tmp_info, to_info)
|
||||
except Exception:
|
||||
self.remove(tmp_info)
|
||||
raise
|
||||
@@ -231,8 +230,8 @@ class LocalRemote(BaseRemote):
|
||||
System.reflink(from_info, tmp_info)
|
||||
# NOTE: reflink has its own separate inode, so you can set permissions
|
||||
# that are different from the source.
|
||||
os.chmod(fspath_py35(tmp_info), self._file_mode)
|
||||
os.rename(fspath_py35(tmp_info), fspath_py35(to_info))
|
||||
os.chmod(tmp_info, self._file_mode)
|
||||
os.rename(tmp_info, to_info)
|
||||
|
||||
def cache_exists(self, checksums, jobs=None, name=None):
|
||||
return [
|
||||
@@ -255,7 +254,7 @@ class LocalRemote(BaseRemote):
|
||||
copyfile(
|
||||
from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
|
||||
)
|
||||
os.rename(tmp_file, fspath_py35(to_info))
|
||||
os.rename(tmp_file, to_info)
|
||||
|
||||
def _download(
|
||||
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||
@@ -266,7 +265,7 @@ class LocalRemote(BaseRemote):
|
||||
|
||||
@staticmethod
|
||||
def open(path_info, mode="r", encoding=None):
|
||||
return open(fspath_py35(path_info), mode=mode, encoding=encoding)
|
||||
return open(path_info, mode=mode, encoding=encoding)
|
||||
|
||||
@index_locked
|
||||
def status(
|
||||
@@ -635,7 +634,7 @@ class LocalRemote(BaseRemote):
|
||||
self._unprotect_file(path)
|
||||
|
||||
def protect(self, path_info):
|
||||
path = fspath_py35(path_info)
|
||||
path = os.fspath(path_info)
|
||||
mode = self.CACHE_MODE
|
||||
|
||||
try:
|
||||
@@ -718,6 +717,6 @@ class LocalRemote(BaseRemote):
|
||||
if not self.exists(path_info):
|
||||
return False
|
||||
|
||||
mode = os.stat(fspath_py35(path_info)).st_mode
|
||||
mode = os.stat(path_info).st_mode
|
||||
|
||||
return stat.S_IMODE(mode) == self.CACHE_MODE
|
||||
|
||||
@@ -4,7 +4,6 @@ from functools import wraps
|
||||
|
||||
from funcy import cached_property, cat, first
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.config import Config
|
||||
from dvc.exceptions import (
|
||||
FileMissingError,
|
||||
@@ -515,7 +514,6 @@ class Repo(object):
|
||||
raise IsADirectoryError("Can't open a dir")
|
||||
|
||||
cache_file = self.cache.local.checksum_to_path_info(out.checksum)
|
||||
cache_file = fspath_py35(cache_file)
|
||||
|
||||
if os.path.exists(cache_file):
|
||||
return open(cache_file, mode=mode, encoding=encoding)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import CheckoutError, CheckoutErrorSuggestGit
|
||||
from dvc.progress import Tqdm
|
||||
from dvc.utils import relpath
|
||||
@@ -23,7 +22,7 @@ def _fspath_dir(path, root):
|
||||
if not os.path.exists(str(path)):
|
||||
return str(path)
|
||||
|
||||
path = relpath(fspath(path), root)
|
||||
path = relpath(path, root)
|
||||
return os.path.join(path, "") if os.path.isdir(path) else path
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import os
|
||||
|
||||
import yaml
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.exceptions import NoMetricsError
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.repo import locked
|
||||
@@ -58,10 +57,10 @@ def _read_metrics(repo, metrics, rev):
|
||||
|
||||
res = {}
|
||||
for metric in metrics:
|
||||
if not tree.exists(fspath_py35(metric)):
|
||||
if not tree.exists(metric):
|
||||
continue
|
||||
|
||||
with tree.open(fspath_py35(metric), "r") as fobj:
|
||||
with tree.open(metric, "r") as fobj:
|
||||
try:
|
||||
# NOTE this also supports JSON
|
||||
val = yaml.safe_load(fobj)
|
||||
|
||||
@@ -2,7 +2,6 @@ import logging
|
||||
|
||||
import yaml
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.dependency.param import ParamsDependency
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.path_info import PathInfo
|
||||
@@ -30,10 +29,10 @@ def _collect_configs(repo):
|
||||
def _read_params(repo, configs, rev):
|
||||
res = {}
|
||||
for config in configs:
|
||||
if not repo.tree.exists(fspath_py35(config)):
|
||||
if not repo.tree.exists(config):
|
||||
continue
|
||||
|
||||
with repo.tree.open(fspath_py35(config), "r") as fobj:
|
||||
with repo.tree.open(config, "r") as fobj:
|
||||
try:
|
||||
res[str(config)] = yaml.safe_load(fobj)
|
||||
except yaml.YAMLError:
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import os
|
||||
import stat
|
||||
|
||||
from dvc.compat import fspath
|
||||
|
||||
|
||||
class BaseTree(object):
|
||||
"""Abstract class to represent access to files"""
|
||||
@@ -66,8 +64,6 @@ class WorkingTree(BaseTree):
|
||||
- it could raise exceptions, there is no onerror argument
|
||||
"""
|
||||
|
||||
top = fspath(top)
|
||||
|
||||
def onerror(e):
|
||||
raise e
|
||||
|
||||
|
||||
+3
-4
@@ -6,7 +6,6 @@ import re
|
||||
import sqlite3
|
||||
from urllib.parse import urlencode, urlunparse
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.utils import current_timestamp, relpath, to_chunks
|
||||
from dvc.utils.fs import get_inode, get_mtime_and_size, remove
|
||||
@@ -363,7 +362,7 @@ class State(object): # pylint: disable=too-many-instance-attributes
|
||||
"""
|
||||
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||
assert checksum is not None
|
||||
assert os.path.exists(fspath_py35(path_info))
|
||||
assert os.path.exists(path_info)
|
||||
|
||||
actual_mtime, actual_size = get_mtime_and_size(
|
||||
path_info, self.repo.tree
|
||||
@@ -393,7 +392,7 @@ class State(object): # pylint: disable=too-many-instance-attributes
|
||||
doesn't exist in the state database.
|
||||
"""
|
||||
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||
path = fspath_py35(path_info)
|
||||
path = os.fspath(path_info)
|
||||
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
@@ -421,7 +420,7 @@ class State(object): # pylint: disable=too-many-instance-attributes
|
||||
"""
|
||||
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||
|
||||
if not os.path.exists(fspath_py35(path_info)):
|
||||
if not os.path.exists(path_info):
|
||||
return
|
||||
|
||||
mtime, _ = get_mtime_and_size(path_info, self.repo.tree)
|
||||
|
||||
+4
-8
@@ -5,7 +5,6 @@ import platform
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import DvcException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -30,12 +29,10 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def copy(src, dest):
|
||||
src, dest = fspath(src), fspath(dest)
|
||||
return shutil.copyfile(src, dest)
|
||||
|
||||
@staticmethod
|
||||
def hardlink(source, link_name):
|
||||
source, link_name = fspath(source), fspath(link_name)
|
||||
try:
|
||||
os.link(source, link_name)
|
||||
except OSError as exc:
|
||||
@@ -43,7 +40,6 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def symlink(source, link_name):
|
||||
source, link_name = fspath(source), fspath(link_name)
|
||||
try:
|
||||
os.symlink(source, link_name)
|
||||
except OSError as exc:
|
||||
@@ -103,7 +99,7 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def reflink(source, link_name):
|
||||
source, link_name = fspath(source), fspath(link_name)
|
||||
source, link_name = os.fspath(source), os.fspath(link_name)
|
||||
|
||||
system = platform.system()
|
||||
try:
|
||||
@@ -163,7 +159,7 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def inode(path):
|
||||
path = fspath(path)
|
||||
path = os.fspath(path)
|
||||
|
||||
if System.is_unix():
|
||||
import ctypes
|
||||
@@ -191,7 +187,7 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def is_symlink(path):
|
||||
path = fspath(path)
|
||||
path = os.fspath(path)
|
||||
|
||||
if System.is_unix():
|
||||
return os.path.islink(path)
|
||||
@@ -207,7 +203,7 @@ class System(object):
|
||||
|
||||
@staticmethod
|
||||
def is_hardlink(path):
|
||||
path = fspath(path)
|
||||
path = os.fspath(path)
|
||||
|
||||
if System.is_unix():
|
||||
return os.stat(path).st_nlink > 1
|
||||
|
||||
@@ -15,8 +15,6 @@ import nanotime
|
||||
from ruamel.yaml import YAML
|
||||
from shortuuid import uuid
|
||||
|
||||
from dvc.compat import fspath, fspath_py35
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LOCAL_CHUNK_SIZE = 2 ** 20 # 1 MB
|
||||
@@ -34,8 +32,6 @@ def file_md5(fname):
|
||||
from dvc.progress import Tqdm
|
||||
from dvc.istextfile import istextfile
|
||||
|
||||
fname = fspath_py35(fname)
|
||||
|
||||
if os.path.exists(fname):
|
||||
hash_md5 = hashlib.md5()
|
||||
binary = not istextfile(fname)
|
||||
@@ -220,7 +216,7 @@ def fix_env(env=None):
|
||||
|
||||
def tmp_fname(fname):
|
||||
""" Temporary name for a partial download """
|
||||
return fspath(fname) + "." + uuid() + ".tmp"
|
||||
return os.fspath(fname) + "." + uuid() + ".tmp"
|
||||
|
||||
|
||||
def current_timestamp():
|
||||
@@ -320,8 +316,8 @@ def _visual_center(line, width):
|
||||
|
||||
|
||||
def relpath(path, start=os.curdir):
|
||||
path = fspath(path)
|
||||
start = os.path.abspath(fspath(start))
|
||||
path = os.fspath(path)
|
||||
start = os.path.abspath(os.fspath(start))
|
||||
|
||||
# Windows path on different drive than curdir doesn't have relpath
|
||||
if os.name == "nt" and not os.path.commonprefix(
|
||||
|
||||
+9
-17
@@ -11,7 +11,7 @@ from shortuuid import uuid
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.scm.tree import is_working_tree
|
||||
from dvc.system import System
|
||||
from dvc.utils import dict_md5, fspath, fspath_py35
|
||||
from dvc.utils import dict_md5
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -33,7 +33,7 @@ def get_inode(path):
|
||||
|
||||
def get_mtime_and_size(path, tree):
|
||||
|
||||
if os.path.isdir(fspath_py35(path)):
|
||||
if os.path.isdir(path):
|
||||
assert is_working_tree(tree)
|
||||
|
||||
size = 0
|
||||
@@ -53,7 +53,7 @@ def get_mtime_and_size(path, tree):
|
||||
# max(mtime(f) for f in non_ignored_files)
|
||||
mtime = dict_md5(files_mtimes)
|
||||
else:
|
||||
base_stat = os.stat(fspath_py35(path))
|
||||
base_stat = os.stat(path)
|
||||
size = base_stat.st_size
|
||||
mtime = base_stat.st_mtime
|
||||
mtime = int(nanotime.timestamp(mtime))
|
||||
@@ -72,8 +72,8 @@ class BasePathNotInCheckedPathException(DvcException):
|
||||
|
||||
|
||||
def contains_symlink_up_to(path, base_path):
|
||||
base_path = fspath(base_path)
|
||||
path = fspath(path)
|
||||
base_path = os.fspath(base_path)
|
||||
path = os.fspath(path)
|
||||
|
||||
if base_path not in path:
|
||||
raise BasePathNotInCheckedPathException(path, base_path)
|
||||
@@ -95,14 +95,12 @@ def move(src, dst, mode=None):
|
||||
of data is happening.
|
||||
"""
|
||||
|
||||
src = fspath(src)
|
||||
dst = fspath(dst)
|
||||
|
||||
dst = os.path.abspath(dst)
|
||||
tmp = "{}.{}".format(dst, uuid())
|
||||
|
||||
if os.path.islink(src):
|
||||
shutil.copy(os.readlink(src), tmp)
|
||||
# readlink does not accept path-like obj for Windows in Python <3.8
|
||||
shutil.copy(os.readlink(os.fspath(src)), tmp)
|
||||
os.unlink(src)
|
||||
else:
|
||||
shutil.move(src, tmp)
|
||||
@@ -137,7 +135,6 @@ def _unlink(path, onerror):
|
||||
def remove(path):
|
||||
logger.debug("Removing '%s'", path)
|
||||
|
||||
path = fspath_py35(path)
|
||||
try:
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path, onerror=_chmod)
|
||||
@@ -152,7 +149,7 @@ def path_isin(child, parent):
|
||||
"""Check if given `child` path is inside `parent`."""
|
||||
|
||||
def normalize_path(path):
|
||||
return os.path.normpath(fspath_py35(path))
|
||||
return os.path.normpath(path)
|
||||
|
||||
parent = os.path.join(normalize_path(parent), "")
|
||||
child = normalize_path(child)
|
||||
@@ -160,8 +157,6 @@ def path_isin(child, parent):
|
||||
|
||||
|
||||
def makedirs(path, exist_ok=False, mode=None):
|
||||
path = fspath_py35(path)
|
||||
|
||||
if mode is None:
|
||||
os.makedirs(path, exist_ok=exist_ok)
|
||||
return
|
||||
@@ -182,9 +177,6 @@ def copyfile(src, dest, no_progress_bar=False, name=None):
|
||||
from dvc.progress import Tqdm
|
||||
from dvc.system import System
|
||||
|
||||
src = fspath_py35(src)
|
||||
dest = fspath_py35(dest)
|
||||
|
||||
name = name if name else os.path.basename(dest)
|
||||
total = os.stat(src).st_size
|
||||
|
||||
@@ -211,6 +203,6 @@ def copyfile(src, dest, no_progress_bar=False, name=None):
|
||||
|
||||
|
||||
def walk_files(directory):
|
||||
for root, _, files in os.walk(fspath(directory)):
|
||||
for root, _, files in os.walk(directory):
|
||||
for f in files:
|
||||
yield os.path.join(root, f)
|
||||
|
||||
@@ -93,7 +93,7 @@ azure = ["azure-storage-blob==2.1.0"]
|
||||
oss = ["oss2==2.6.1"]
|
||||
ssh = ["paramiko>=2.5.0"]
|
||||
hdfs = [
|
||||
# pyarrow-0.16.0 import fails on 3.5 and 3.7 (works on 3.6 though)
|
||||
# pyarrow-0.16.0 import fails on 3.7 (works on 3.6 though)
|
||||
# due to: https://issues.apache.org/jira/browse/ARROW-7852
|
||||
"pyarrow==0.15.1; python_version < '3.8'",
|
||||
"pyarrow==0.16.0; python_version == '3.8'",
|
||||
@@ -159,11 +159,10 @@ setup(
|
||||
},
|
||||
keywords="data-science data-version-control machine-learning git"
|
||||
" developer-tools reproducibility collaboration ai",
|
||||
python_requires=">=3.5",
|
||||
python_requires=">=3.6",
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
|
||||
+5
-10
@@ -50,7 +50,6 @@ from contextlib import contextmanager
|
||||
import pytest
|
||||
from funcy import lmap, retry
|
||||
|
||||
from dvc.compat import fspath, fspath_py35
|
||||
from dvc.logger import disable_other_loggers
|
||||
from dvc.utils.fs import makedirs
|
||||
|
||||
@@ -82,10 +81,6 @@ class TmpDir(pathlib.Path):
|
||||
self._init()
|
||||
return self
|
||||
|
||||
# Not needed in Python 3.6+
|
||||
def __fspath__(self):
|
||||
return str(self)
|
||||
|
||||
def init(self, *, scm=False, dvc=False):
|
||||
from dvc.repo import Repo
|
||||
from dvc.scm.git import Git
|
||||
@@ -93,7 +88,7 @@ class TmpDir(pathlib.Path):
|
||||
assert not scm or not hasattr(self, "scm")
|
||||
assert not dvc or not hasattr(self, "dvc")
|
||||
|
||||
str_path = fspath(self)
|
||||
str_path = os.fspath(self)
|
||||
|
||||
if scm:
|
||||
_git_init(str_path)
|
||||
@@ -184,7 +179,7 @@ class TmpDir(pathlib.Path):
|
||||
def chdir(self):
|
||||
old = os.getcwd()
|
||||
try:
|
||||
os.chdir(fspath_py35(self))
|
||||
os.chdir(self)
|
||||
yield
|
||||
finally:
|
||||
os.chdir(old)
|
||||
@@ -203,7 +198,7 @@ class TmpDir(pathlib.Path):
|
||||
def _coerce_filenames(filenames):
|
||||
if isinstance(filenames, (str, bytes, pathlib.PurePath)):
|
||||
filenames = [filenames]
|
||||
return lmap(fspath, filenames)
|
||||
return lmap(os.fspath, filenames)
|
||||
|
||||
|
||||
class WindowsTmpDir(TmpDir, pathlib.PureWindowsPath):
|
||||
@@ -218,7 +213,7 @@ class PosixTmpDir(TmpDir, pathlib.PurePosixPath):
|
||||
def make_tmp_dir(tmp_path_factory, request):
|
||||
def make(name, *, scm=False, dvc=False):
|
||||
path = tmp_path_factory.mktemp(name) if isinstance(name, str) else name
|
||||
new_dir = TmpDir(fspath_py35(path))
|
||||
new_dir = TmpDir(path)
|
||||
new_dir.init(scm=scm, dvc=dvc)
|
||||
request.addfinalizer(new_dir.close)
|
||||
return new_dir
|
||||
@@ -290,7 +285,7 @@ def git_dir(make_tmp_dir):
|
||||
def setup_remote(make_tmp_dir):
|
||||
def create(repo, url=None, name="upstream", default=True):
|
||||
if not url:
|
||||
url = fspath(make_tmp_dir("local_remote"))
|
||||
url = os.fspath(make_tmp_dir("local_remote"))
|
||||
with repo.config.edit() as conf:
|
||||
conf["remote"][name] = {"url": url}
|
||||
if default:
|
||||
|
||||
@@ -3,7 +3,6 @@ import posixpath
|
||||
|
||||
import configobj
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.main import main
|
||||
from dvc.remote import GDriveRemote
|
||||
from dvc.repo import Repo
|
||||
@@ -39,7 +38,7 @@ def test_relative_user_credentials_file_config_setting(tmp_dir, dvc):
|
||||
)
|
||||
|
||||
# We need to load repo again to test updates to the config
|
||||
str_path = fspath(tmp_dir)
|
||||
str_path = os.fspath(tmp_dir)
|
||||
repo = Repo(str_path)
|
||||
|
||||
# Check that in config we got the path relative to the config file itself
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import DownloadError, UploadError
|
||||
from dvc.remote.base import BaseRemote
|
||||
from dvc.remote.index import RemoteIndex
|
||||
@@ -10,7 +11,7 @@ from dvc.utils.fs import remove
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def remote(tmp_dir, dvc, tmp_path_factory, mocker):
|
||||
url = fspath(tmp_path_factory.mktemp("upstream"))
|
||||
url = os.fspath(tmp_path_factory.mktemp("upstream"))
|
||||
dvc.config["remote"]["upstream"] = {"url": url}
|
||||
dvc.config["core"]["remote"] = "upstream"
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ from mock import call, patch
|
||||
|
||||
import dvc as dvc_module
|
||||
from dvc.cache import Cache
|
||||
from dvc.compat import fspath
|
||||
from dvc.dvcfile import DVC_FILE_SUFFIX
|
||||
from dvc.exceptions import (
|
||||
DvcException,
|
||||
@@ -531,7 +530,7 @@ def temporary_windows_drive(tmp_path_factory):
|
||||
target_path = tmp_path_factory.mktemp("tmp_windows_drive")
|
||||
|
||||
set_up_result = windll.kernel32.DefineDosDeviceW(
|
||||
0, new_drive, fspath(target_path)
|
||||
0, new_drive, os.fspath(target_path)
|
||||
)
|
||||
if set_up_result == 0:
|
||||
raise RuntimeError("Failed to mount windows drive!")
|
||||
@@ -541,7 +540,7 @@ def temporary_windows_drive(tmp_path_factory):
|
||||
yield os.path.join(new_drive, os.sep)
|
||||
|
||||
tear_down_result = windll.kernel32.DefineDosDeviceW(
|
||||
DDD_REMOVE_DEFINITION, new_drive, fspath(target_path)
|
||||
DDD_REMOVE_DEFINITION, new_drive, os.fspath(target_path)
|
||||
)
|
||||
if tear_down_result == 0:
|
||||
raise RuntimeError("Could not unmount windows drive!")
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import os
|
||||
|
||||
import mock
|
||||
|
||||
from dvc.analytics import _scm_in_use
|
||||
from dvc.compat import fspath
|
||||
from dvc.main import main
|
||||
from dvc.repo import Repo
|
||||
|
||||
|
||||
@mock.patch("dvc.analytics.send")
|
||||
def test_daemon_analytics(mock_send, tmp_path):
|
||||
report = fspath(tmp_path)
|
||||
report = os.fspath(tmp_path)
|
||||
assert 0 == main(["daemon", "analytics", report])
|
||||
|
||||
mock_send.assert_called_with(report)
|
||||
|
||||
@@ -4,7 +4,6 @@ import pytest
|
||||
|
||||
from dvc import api
|
||||
from dvc.api import UrlNotDvcRepoError
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import FileMissingError
|
||||
from dvc.main import main
|
||||
from dvc.path_info import URLInfo
|
||||
@@ -51,7 +50,7 @@ def test_get_url_requires_dvc(tmp_dir, scm):
|
||||
tmp_dir.scm_gen({"foo": "foo"}, commit="initial")
|
||||
|
||||
with pytest.raises(UrlNotDvcRepoError, match="not a DVC repository"):
|
||||
api.get_url("foo", repo=fspath(tmp_dir))
|
||||
api.get_url("foo", repo=os.fspath(tmp_dir))
|
||||
|
||||
with pytest.raises(UrlNotDvcRepoError):
|
||||
api.get_url("foo", repo="file://{}".format(tmp_dir))
|
||||
@@ -109,7 +108,7 @@ def test_missing(remote_url, tmp_dir, dvc):
|
||||
def test_open_scm_controlled(tmp_dir, erepo_dir):
|
||||
erepo_dir.scm_gen({"scm_controlled": "file content"}, commit="create file")
|
||||
|
||||
with api.open("scm_controlled", repo=fspath(erepo_dir)) as fd:
|
||||
with api.open("scm_controlled", repo=os.fspath(erepo_dir)) as fd:
|
||||
assert fd.read() == "file content"
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import pytest
|
||||
from flaky.flaky_decorator import flaky
|
||||
|
||||
from dvc.cache import NamedCache
|
||||
from dvc.compat import fspath
|
||||
from dvc.data_cloud import DataCloud
|
||||
from dvc.external_repo import clean_repos
|
||||
from dvc.main import main
|
||||
@@ -725,8 +724,8 @@ def test_pull_git_imports(request, tmp_dir, dvc, scm, erepo):
|
||||
erepo.scm_gen({"dir": {"bar": "bar"}}, commit="second")
|
||||
erepo.scm_gen("foo", "foo", commit="first")
|
||||
|
||||
dvc.imp(fspath(erepo), "foo")
|
||||
dvc.imp(fspath(erepo), "dir", out="new_dir", rev="HEAD~")
|
||||
dvc.imp(os.fspath(erepo), "foo")
|
||||
dvc.imp(os.fspath(erepo), "dir", out="new_dir", rev="HEAD~")
|
||||
|
||||
assert dvc.pull()["fetched"] == 0
|
||||
|
||||
@@ -752,8 +751,8 @@ def test_pull_external_dvc_imports(tmp_dir, dvc, scm, erepo_dir):
|
||||
os.remove("foo")
|
||||
shutil.rmtree("dir")
|
||||
|
||||
dvc.imp(fspath(erepo_dir), "foo")
|
||||
dvc.imp(fspath(erepo_dir), "dir", out="new_dir", rev="HEAD~")
|
||||
dvc.imp(os.fspath(erepo_dir), "foo")
|
||||
dvc.imp(os.fspath(erepo_dir), "dir", out="new_dir", rev="HEAD~")
|
||||
|
||||
assert dvc.pull()["fetched"] == 0
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import os
|
||||
import pytest
|
||||
from funcy import first
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.utils.fs import remove
|
||||
|
||||
@@ -38,7 +37,7 @@ def test_no_cache_entry(tmp_dir, scm, dvc):
|
||||
tmp_dir.dvc_gen({"dir": {"1": "1", "2": "2"}})
|
||||
tmp_dir.dvc_gen("file", "second")
|
||||
|
||||
remove(fspath(tmp_dir / ".dvc" / "cache"))
|
||||
remove(tmp_dir / ".dvc" / "cache")
|
||||
(tmp_dir / ".dvc" / "tmp" / "state").unlink()
|
||||
|
||||
dir_checksum = "5fb6b29836c388e093ca0715c872fe2a.dir"
|
||||
|
||||
@@ -2,7 +2,6 @@ import os
|
||||
|
||||
from mock import patch
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.external_repo import external_repo
|
||||
from dvc.remote import LocalRemote
|
||||
from dvc.scm.git import Git
|
||||
@@ -16,7 +15,7 @@ def test_external_repo(erepo_dir):
|
||||
erepo_dir.dvc_gen("file", "branch", commit="create file on branch")
|
||||
erepo_dir.dvc_gen("file", "master", commit="create file on master")
|
||||
|
||||
url = fspath(erepo_dir)
|
||||
url = os.fspath(erepo_dir)
|
||||
|
||||
with patch.object(Git, "clone", wraps=Git.clone) as mock:
|
||||
with external_repo(url) as repo:
|
||||
@@ -31,7 +30,7 @@ def test_external_repo(erepo_dir):
|
||||
|
||||
|
||||
def test_source_change(erepo_dir):
|
||||
url = fspath(erepo_dir)
|
||||
url = os.fspath(erepo_dir)
|
||||
with external_repo(url) as repo:
|
||||
old_rev = repo.scm.get_rev()
|
||||
|
||||
@@ -89,7 +88,7 @@ def test_pull_subdir_file(tmp_dir, erepo_dir):
|
||||
erepo_dir.dvc_add(subdir / "file", commit="create file")
|
||||
|
||||
dest = tmp_dir / "file"
|
||||
with external_repo(fspath(erepo_dir)) as repo:
|
||||
with external_repo(os.fspath(erepo_dir)) as repo:
|
||||
repo.pull_to(os.path.join("subdir", "file"), dest)
|
||||
|
||||
assert dest.is_file()
|
||||
@@ -111,7 +110,7 @@ def test_relative_remote(erepo_dir, tmp_dir, setup_remote):
|
||||
(erepo_dir / "file").unlink()
|
||||
remove(erepo_dir.dvc.cache.local.cache_dir)
|
||||
|
||||
url = fspath(erepo_dir)
|
||||
url = os.fspath(erepo_dir)
|
||||
|
||||
with external_repo(url) as repo:
|
||||
assert os.path.isabs(repo.config["remote"]["upstream"]["url"])
|
||||
|
||||
@@ -6,7 +6,6 @@ import configobj
|
||||
import pytest
|
||||
from git import Repo
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import CollectCacheError
|
||||
from dvc.main import main
|
||||
from dvc.remote.local import LocalRemote
|
||||
@@ -303,7 +302,7 @@ def test_gc_cloud_positive(tmp_dir, dvc, tmp_path_factory, setup_remote):
|
||||
|
||||
|
||||
def test_gc_cloud_remove_order(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
storage = fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
storage = os.fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
dvc.config["remote"]["local_remote"] = {"url": storage}
|
||||
dvc.config["core"]["remote"] = "local_remote"
|
||||
|
||||
|
||||
+37
-27
@@ -4,7 +4,6 @@ import os
|
||||
import pytest
|
||||
|
||||
from dvc.cache import Cache
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import PathMissingError
|
||||
from dvc.main import main
|
||||
from dvc.repo import Repo
|
||||
@@ -18,7 +17,7 @@ def test_get_repo_file(tmp_dir, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("file", "contents", commit="create file")
|
||||
|
||||
Repo.get(fspath(erepo_dir), "file", "file_imported")
|
||||
Repo.get(os.fspath(erepo_dir), "file", "file_imported")
|
||||
|
||||
assert os.path.isfile("file_imported")
|
||||
assert (tmp_dir / "file_imported").read_text() == "contents"
|
||||
@@ -28,10 +27,10 @@ def test_get_repo_dir(tmp_dir, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen({"dir": {"file": "contents"}}, commit="create dir")
|
||||
|
||||
Repo.get(fspath(erepo_dir), "dir", "dir_imported")
|
||||
Repo.get(os.fspath(erepo_dir), "dir", "dir_imported")
|
||||
|
||||
assert os.path.isdir("dir_imported")
|
||||
trees_equal(fspath(erepo_dir / "dir"), "dir_imported")
|
||||
trees_equal(erepo_dir / "dir", "dir_imported")
|
||||
|
||||
|
||||
def test_get_git_file(tmp_dir, erepo_dir):
|
||||
@@ -40,7 +39,7 @@ def test_get_git_file(tmp_dir, erepo_dir):
|
||||
|
||||
erepo_dir.scm_gen({src: "hello"}, commit="add a regular file")
|
||||
|
||||
Repo.get(fspath(erepo_dir), src, dst)
|
||||
Repo.get(os.fspath(erepo_dir), src, dst)
|
||||
|
||||
assert (tmp_dir / dst).is_file()
|
||||
assert (tmp_dir / dst).read_text() == "hello"
|
||||
@@ -52,10 +51,10 @@ def test_get_git_dir(tmp_dir, erepo_dir):
|
||||
|
||||
erepo_dir.scm_gen({src: {"file.txt": "hello"}}, commit="add a regular dir")
|
||||
|
||||
Repo.get(fspath(erepo_dir), src, dst)
|
||||
Repo.get(os.fspath(erepo_dir), src, dst)
|
||||
|
||||
assert (tmp_dir / dst).is_dir()
|
||||
trees_equal(fspath(erepo_dir / src), fspath(tmp_dir / dst))
|
||||
trees_equal(erepo_dir / src, tmp_dir / dst)
|
||||
|
||||
|
||||
def test_cache_type_is_properly_overridden(tmp_dir, erepo_dir):
|
||||
@@ -69,7 +68,7 @@ def test_cache_type_is_properly_overridden(tmp_dir, erepo_dir):
|
||||
erepo_dir.dvc_gen("file", "contents", "create file")
|
||||
assert System.is_symlink(erepo_dir / "file")
|
||||
|
||||
Repo.get(fspath(erepo_dir), "file", "file_imported")
|
||||
Repo.get(os.fspath(erepo_dir), "file", "file_imported")
|
||||
|
||||
assert not System.is_symlink("file_imported")
|
||||
assert (tmp_dir / "file_imported").read_text() == "contents"
|
||||
@@ -79,20 +78,20 @@ def test_get_repo_rev(tmp_dir, erepo_dir):
|
||||
with erepo_dir.chdir(), erepo_dir.branch("branch", new=True):
|
||||
erepo_dir.dvc_gen("file", "contents", commit="create file on branch")
|
||||
|
||||
Repo.get(fspath(erepo_dir), "file", "file_imported", rev="branch")
|
||||
Repo.get(os.fspath(erepo_dir), "file", "file_imported", rev="branch")
|
||||
assert (tmp_dir / "file_imported").read_text() == "contents"
|
||||
|
||||
|
||||
def test_get_from_non_dvc_repo(tmp_dir, git_dir):
|
||||
git_dir.scm_gen({"some_file": "contents"}, commit="create file")
|
||||
|
||||
Repo.get(fspath(git_dir), "some_file", "file_imported")
|
||||
Repo.get(os.fspath(git_dir), "some_file", "file_imported")
|
||||
assert (tmp_dir / "file_imported").read_text() == "contents"
|
||||
|
||||
|
||||
def test_get_a_dvc_file(tmp_dir, erepo_dir):
|
||||
with pytest.raises(GetDVCFileError):
|
||||
Repo.get(fspath(erepo_dir), "some_file.dvc")
|
||||
Repo.get(os.fspath(erepo_dir), "some_file.dvc")
|
||||
|
||||
|
||||
# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
|
||||
@@ -102,9 +101,11 @@ def test_get_full_dvc_path(tmp_dir, erepo_dir, tmp_path_factory):
|
||||
external_data.write_text("ext_data")
|
||||
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_add(fspath(external_data), commit="add external data")
|
||||
erepo_dir.dvc_add(os.fspath(external_data), commit="add external data")
|
||||
|
||||
Repo.get(fspath(erepo_dir), fspath(external_data), "ext_data_imported")
|
||||
Repo.get(
|
||||
os.fspath(erepo_dir), os.fspath(external_data), "ext_data_imported"
|
||||
)
|
||||
assert (tmp_dir / "ext_data_imported").read_text() == "ext_data"
|
||||
|
||||
|
||||
@@ -120,7 +121,7 @@ def test_non_cached_output(tmp_dir, erepo_dir):
|
||||
)
|
||||
erepo_dir.scm_add([src, src + ".dvc"], commit="add non-cached output")
|
||||
|
||||
Repo.get(fspath(erepo_dir), src, dst)
|
||||
Repo.get(os.fspath(erepo_dir), src, dst)
|
||||
|
||||
assert (tmp_dir / dst).is_file()
|
||||
# NOTE: using strip() to account for `echo` differences on win and *nix
|
||||
@@ -130,17 +131,17 @@ def test_non_cached_output(tmp_dir, erepo_dir):
|
||||
# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
|
||||
def test_absolute_file_outside_repo(tmp_dir, erepo_dir):
|
||||
with pytest.raises(PathMissingError):
|
||||
Repo.get(fspath(erepo_dir), "/root/")
|
||||
Repo.get(os.fspath(erepo_dir), "/root/")
|
||||
|
||||
|
||||
def test_absolute_file_outside_git_repo(tmp_dir, git_dir):
|
||||
with pytest.raises(PathMissingError):
|
||||
Repo.get(fspath(git_dir), "/root/")
|
||||
Repo.get(os.fspath(git_dir), "/root/")
|
||||
|
||||
|
||||
def test_unknown_path(tmp_dir, erepo_dir):
|
||||
with pytest.raises(PathMissingError):
|
||||
Repo.get(fspath(erepo_dir), "a_non_existing_file")
|
||||
Repo.get(os.fspath(erepo_dir), "a_non_existing_file")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dname", [".", "dir", "dir/subdir"])
|
||||
@@ -150,7 +151,7 @@ def test_get_to_dir(tmp_dir, erepo_dir, dname):
|
||||
|
||||
makedirs(dname, exist_ok=True)
|
||||
|
||||
Repo.get(fspath(erepo_dir), "file", dname)
|
||||
Repo.get(os.fspath(erepo_dir), "file", dname)
|
||||
|
||||
assert (tmp_dir / dname).is_dir()
|
||||
assert (tmp_dir / dname / "file").read_text() == "contents"
|
||||
@@ -164,7 +165,7 @@ def test_get_from_non_dvc_master(tmp_dir, git_dir, caplog):
|
||||
caplog.clear()
|
||||
|
||||
with caplog.at_level(logging.INFO, logger="dvc"):
|
||||
Repo.get(fspath(git_dir), "some_file", out="some_dst", rev="branch")
|
||||
Repo.get(os.fspath(git_dir), "some_file", out="some_dst", rev="branch")
|
||||
|
||||
assert caplog.text == ""
|
||||
assert (tmp_dir / "some_dst").read_text() == "some text"
|
||||
@@ -183,17 +184,19 @@ def test_get_file_from_dir(tmp_dir, erepo_dir):
|
||||
commit="create dir",
|
||||
)
|
||||
|
||||
Repo.get(fspath(erepo_dir), os.path.join("dir", "1"))
|
||||
Repo.get(os.fspath(erepo_dir), os.path.join("dir", "1"))
|
||||
assert (tmp_dir / "1").read_text() == "1"
|
||||
|
||||
Repo.get(fspath(erepo_dir), os.path.join("dir", "2"), out="file")
|
||||
Repo.get(os.fspath(erepo_dir), os.path.join("dir", "2"), out="file")
|
||||
assert (tmp_dir / "file").read_text() == "2"
|
||||
|
||||
Repo.get(fspath(erepo_dir), os.path.join("dir", "subdir"))
|
||||
Repo.get(os.fspath(erepo_dir), os.path.join("dir", "subdir"))
|
||||
assert (tmp_dir / "subdir" / "foo").read_text() == "foo"
|
||||
assert (tmp_dir / "subdir" / "bar").read_text() == "bar"
|
||||
|
||||
Repo.get(fspath(erepo_dir), os.path.join("dir", "subdir", "foo"), out="X")
|
||||
Repo.get(
|
||||
os.fspath(erepo_dir), os.path.join("dir", "subdir", "foo"), out="X"
|
||||
)
|
||||
assert (tmp_dir / "X").read_text() == "foo"
|
||||
|
||||
|
||||
@@ -205,14 +208,21 @@ def test_get_url_positive(tmp_dir, erepo_dir, caplog, setup_remote):
|
||||
|
||||
caplog.clear()
|
||||
with caplog.at_level(logging.ERROR, logger="dvc"):
|
||||
assert main(["get", fspath(erepo_dir), "foo", "--show-url"]) == 0
|
||||
assert main(["get", os.fspath(erepo_dir), "foo", "--show-url"]) == 0
|
||||
assert caplog.text == ""
|
||||
|
||||
|
||||
def test_get_url_not_existing(tmp_dir, erepo_dir, caplog):
|
||||
with caplog.at_level(logging.ERROR, logger="dvc"):
|
||||
assert (
|
||||
main(["get", fspath(erepo_dir), "not-existing-file", "--show-url"])
|
||||
main(
|
||||
[
|
||||
"get",
|
||||
os.fspath(erepo_dir),
|
||||
"not-existing-file",
|
||||
"--show-url",
|
||||
]
|
||||
)
|
||||
== 1
|
||||
)
|
||||
assert "failed to show URL" in caplog.text
|
||||
@@ -222,7 +232,7 @@ def test_get_url_git_only_repo(tmp_dir, scm, caplog):
|
||||
tmp_dir.scm_gen({"foo": "foo"}, commit="initial")
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
assert main(["get", fspath(tmp_dir), "foo", "--show-url"]) == 1
|
||||
assert main(["get", os.fspath(tmp_dir), "foo", "--show-url"]) == 1
|
||||
assert "failed to show URL" in caplog.text
|
||||
|
||||
|
||||
@@ -240,5 +250,5 @@ def test_get_pipeline_tracked_outs(
|
||||
dvc.scm.commit("add pipeline stage")
|
||||
|
||||
with git_dir.chdir():
|
||||
Repo.get("file:///{}".format(fspath(tmp_dir)), "bar", out="baz")
|
||||
Repo.get("file:///{}".format(os.fspath(tmp_dir)), "bar", out="baz")
|
||||
assert (git_dir / "baz").read_text() == "foo"
|
||||
|
||||
@@ -4,7 +4,6 @@ import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.compat import fspath, fspath_py35
|
||||
from dvc.exceptions import DvcIgnoreInCollectedDirError
|
||||
from dvc.ignore import (
|
||||
DvcIgnore,
|
||||
@@ -101,7 +100,9 @@ def test_ignore_collecting_dvcignores(tmp_dir, dvc, dname):
|
||||
assert len(dvc.tree.dvcignore.ignores) == 3
|
||||
assert DvcIgnoreDirs([".git", ".hg", ".dvc"]) in dvc.tree.dvcignore.ignores
|
||||
assert (
|
||||
DvcIgnorePatterns(fspath(top_ignore_file), WorkingTree(dvc.root_dir))
|
||||
DvcIgnorePatterns(
|
||||
os.fspath(top_ignore_file), WorkingTree(dvc.root_dir)
|
||||
)
|
||||
in dvc.tree.dvcignore.ignores
|
||||
)
|
||||
assert any(
|
||||
@@ -139,13 +140,13 @@ def test_match_nested(tmp_dir, dvc):
|
||||
)
|
||||
|
||||
remote = LocalRemote(dvc, {})
|
||||
result = {fspath(f) for f in remote.walk_files(".")}
|
||||
result = {os.fspath(f) for f in remote.walk_files(".")}
|
||||
assert result == {".dvcignore", "foo"}
|
||||
|
||||
|
||||
def test_ignore_external(tmp_dir, scm, dvc, tmp_path_factory):
|
||||
tmp_dir.gen(".dvcignore", "*.backup\ntmp")
|
||||
ext_dir = TmpDir(fspath_py35(tmp_path_factory.mktemp("external_dir")))
|
||||
ext_dir = TmpDir(os.fspath(tmp_path_factory.mktemp("external_dir")))
|
||||
ext_dir.gen({"y.backup": "y", "tmp": "ext tmp"})
|
||||
|
||||
remote = LocalRemote(dvc, {})
|
||||
|
||||
+44
-45
@@ -6,7 +6,6 @@ from mock import patch
|
||||
|
||||
import dvc.data_cloud as cloud
|
||||
from dvc.cache import Cache
|
||||
from dvc.compat import fspath
|
||||
from dvc.config import NoRemoteError
|
||||
from dvc.dvcfile import Dvcfile
|
||||
from dvc.exceptions import DownloadError, PathMissingError
|
||||
@@ -19,13 +18,13 @@ def test_import(tmp_dir, scm, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported")
|
||||
|
||||
assert os.path.isfile("foo_imported")
|
||||
assert (tmp_dir / "foo_imported").read_text() == "foo content"
|
||||
assert scm.repo.git.check_ignore("foo_imported")
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev_lock": erepo_dir.scm.get_rev(),
|
||||
}
|
||||
|
||||
@@ -37,12 +36,12 @@ def test_import_git_file(tmp_dir, scm, dvc, git_dir, src_is_dvc):
|
||||
|
||||
git_dir.scm_gen("src", "hello", commit="add a git file")
|
||||
|
||||
stage = tmp_dir.dvc.imp(fspath(git_dir), "src", "dst")
|
||||
stage = tmp_dir.dvc.imp(os.fspath(git_dir), "src", "dst")
|
||||
|
||||
assert (tmp_dir / "dst").read_text() == "hello"
|
||||
assert tmp_dir.scm.repo.git.check_ignore(fspath(tmp_dir / "dst"))
|
||||
assert tmp_dir.scm.repo.git.check_ignore(os.fspath(tmp_dir / "dst"))
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(git_dir),
|
||||
"url": os.fspath(git_dir),
|
||||
"rev_lock": git_dir.scm.get_rev(),
|
||||
}
|
||||
|
||||
@@ -59,12 +58,10 @@ def test_import_cached_file(erepo_dir, tmp_dir, dvc, scm, monkeypatch):
|
||||
|
||||
remote_exception = NoRemoteError("dvc import")
|
||||
with patch.object(cloud.DataCloud, "pull", side_effect=remote_exception):
|
||||
tmp_dir.dvc.imp(fspath(erepo_dir), src, dst)
|
||||
tmp_dir.dvc.imp(os.fspath(erepo_dir), src, dst)
|
||||
|
||||
assert (tmp_dir / dst).is_file()
|
||||
assert filecmp.cmp(
|
||||
fspath(erepo_dir / src), fspath(tmp_dir / dst), shallow=False
|
||||
)
|
||||
assert filecmp.cmp(erepo_dir / src, tmp_dir / dst, shallow=False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("src_is_dvc", [True, False])
|
||||
@@ -74,13 +71,13 @@ def test_import_git_dir(tmp_dir, scm, dvc, git_dir, src_is_dvc):
|
||||
|
||||
git_dir.scm_gen({"src": {"file.txt": "hello"}}, commit="add a dir")
|
||||
|
||||
stage = dvc.imp(fspath(git_dir), "src", "dst")
|
||||
stage = dvc.imp(os.fspath(git_dir), "src", "dst")
|
||||
|
||||
assert (tmp_dir / "dst").is_dir()
|
||||
trees_equal(fspath(git_dir / "src"), fspath(tmp_dir / "dst"))
|
||||
assert tmp_dir.scm.repo.git.check_ignore(fspath(tmp_dir / "dst"))
|
||||
trees_equal(git_dir / "src", tmp_dir / "dst")
|
||||
assert tmp_dir.scm.repo.git.check_ignore(os.fspath(tmp_dir / "dst"))
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(git_dir),
|
||||
"url": os.fspath(git_dir),
|
||||
"rev_lock": git_dir.scm.get_rev(),
|
||||
}
|
||||
|
||||
@@ -89,13 +86,13 @@ def test_import_dir(tmp_dir, scm, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen({"dir": {"foo": "foo content"}}, commit="create dir")
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "dir", "dir_imported")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "dir", "dir_imported")
|
||||
|
||||
assert os.path.isdir("dir_imported")
|
||||
trees_equal(fspath(erepo_dir / "dir"), "dir_imported")
|
||||
trees_equal(erepo_dir / "dir", "dir_imported")
|
||||
assert scm.repo.git.check_ignore("dir_imported")
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev_lock": erepo_dir.scm.get_rev(),
|
||||
}
|
||||
|
||||
@@ -113,25 +110,27 @@ def test_import_file_from_dir(tmp_dir, scm, dvc, erepo_dir):
|
||||
commit="create dir",
|
||||
)
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), os.path.join("dir", "1"))
|
||||
stage = dvc.imp(os.fspath(erepo_dir), os.path.join("dir", "1"))
|
||||
|
||||
assert (tmp_dir / "1").read_text() == "1"
|
||||
assert scm.repo.git.check_ignore("1")
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev_lock": erepo_dir.scm.get_rev(),
|
||||
}
|
||||
|
||||
dvc.imp(fspath(erepo_dir), os.path.join("dir", "2"), out="file")
|
||||
dvc.imp(os.fspath(erepo_dir), os.path.join("dir", "2"), out="file")
|
||||
assert (tmp_dir / "file").read_text() == "2"
|
||||
assert (tmp_dir / "file.dvc").exists()
|
||||
|
||||
dvc.imp(fspath(erepo_dir), os.path.join("dir", "subdir"))
|
||||
dvc.imp(os.fspath(erepo_dir), os.path.join("dir", "subdir"))
|
||||
assert (tmp_dir / "subdir" / "foo").read_text() == "foo"
|
||||
assert (tmp_dir / "subdir" / "bar").read_text() == "bar"
|
||||
assert (tmp_dir / "subdir.dvc").exists()
|
||||
|
||||
dvc.imp(fspath(erepo_dir), os.path.join("dir", "subdir", "foo"), out="X")
|
||||
dvc.imp(
|
||||
os.fspath(erepo_dir), os.path.join("dir", "subdir", "foo"), out="X"
|
||||
)
|
||||
assert (tmp_dir / "X").read_text() == "foo"
|
||||
assert (tmp_dir / "X.dvc").exists()
|
||||
|
||||
@@ -147,17 +146,17 @@ def test_import_non_cached(erepo_dir, tmp_dir, dvc, scm):
|
||||
single_stage=True,
|
||||
)
|
||||
|
||||
erepo_dir.scm_add([fspath(erepo_dir / src)], commit="add a non-cached out")
|
||||
erepo_dir.scm_add(
|
||||
[os.fspath(erepo_dir / src)], commit="add a non-cached out"
|
||||
)
|
||||
|
||||
stage = tmp_dir.dvc.imp(fspath(erepo_dir), src, dst)
|
||||
stage = tmp_dir.dvc.imp(os.fspath(erepo_dir), src, dst)
|
||||
|
||||
assert (tmp_dir / dst).is_file()
|
||||
assert filecmp.cmp(
|
||||
fspath(erepo_dir / src), fspath(tmp_dir / dst), shallow=False
|
||||
)
|
||||
assert filecmp.cmp(erepo_dir / src, tmp_dir / dst, shallow=False)
|
||||
assert tmp_dir.scm.repo.git.check_ignore(dst)
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev_lock": erepo_dir.scm.get_rev(),
|
||||
}
|
||||
|
||||
@@ -168,12 +167,12 @@ def test_import_rev(tmp_dir, scm, dvc, erepo_dir):
|
||||
erepo_dir.dvc_gen("foo", "foo content", commit="create foo on branch")
|
||||
rev = erepo_dir.scm.get_rev()
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="branch")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported", rev="branch")
|
||||
|
||||
assert (tmp_dir / "foo_imported").read_text() == "foo content"
|
||||
assert scm.repo.git.check_ignore("foo_imported")
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev": "branch",
|
||||
"rev_lock": rev,
|
||||
}
|
||||
@@ -182,7 +181,7 @@ def test_import_rev(tmp_dir, scm, dvc, erepo_dir):
|
||||
def test_pull_imported_stage(tmp_dir, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")
|
||||
dvc.imp(fspath(erepo_dir), "foo", "foo_imported")
|
||||
dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported")
|
||||
|
||||
dst_stage = Dvcfile(dvc, "foo_imported.dvc").stage
|
||||
dst_cache = dst_stage.outs[0].cache_path
|
||||
@@ -207,7 +206,7 @@ def test_cache_type_is_properly_overridden(tmp_dir, scm, dvc, erepo_dir):
|
||||
erepo_dir.dvc_gen("foo", "foo content", "create foo")
|
||||
assert System.is_symlink(erepo_dir / "foo")
|
||||
|
||||
dvc.imp(fspath(erepo_dir), "foo", "foo_imported")
|
||||
dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported")
|
||||
|
||||
assert not System.is_symlink("foo_imported")
|
||||
assert (tmp_dir / "foo_imported").read_text() == "foo content"
|
||||
@@ -218,7 +217,7 @@ def test_pull_imported_directory_stage(tmp_dir, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen({"dir": {"foo": "foo content"}}, commit="create dir")
|
||||
|
||||
dvc.imp(fspath(erepo_dir), "dir", "dir_imported")
|
||||
dvc.imp(os.fspath(erepo_dir), "dir", "dir_imported")
|
||||
|
||||
remove("dir_imported")
|
||||
remove(dvc.cache.local.cache_dir)
|
||||
@@ -226,13 +225,13 @@ def test_pull_imported_directory_stage(tmp_dir, dvc, erepo_dir):
|
||||
dvc.pull(["dir_imported.dvc"])
|
||||
|
||||
assert os.path.isdir("dir_imported")
|
||||
trees_equal(fspath(erepo_dir / "dir"), "dir_imported")
|
||||
trees_equal(erepo_dir / "dir", "dir_imported")
|
||||
|
||||
|
||||
def test_download_error_pulling_imported_stage(tmp_dir, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")
|
||||
dvc.imp(fspath(erepo_dir), "foo", "foo_imported")
|
||||
dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported")
|
||||
|
||||
dst_stage = Dvcfile(dvc, "foo_imported.dvc").stage
|
||||
dst_cache = dst_stage.outs[0].cache_path
|
||||
@@ -253,7 +252,7 @@ def test_import_to_dir(dname, tmp_dir, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "foo", dname)
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "foo", dname)
|
||||
|
||||
dst = os.path.join(dname, "foo")
|
||||
|
||||
@@ -269,12 +268,12 @@ def test_pull_non_workspace(tmp_dir, scm, dvc, erepo_dir):
|
||||
with erepo_dir.branch("branch", new=True):
|
||||
erepo_dir.dvc_gen("foo", "branch content", commit="modify foo")
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="branch")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported", rev="branch")
|
||||
tmp_dir.scm_add([stage.relpath], commit="imported branch")
|
||||
scm.tag("ref-to-branch")
|
||||
|
||||
# Overwrite via import
|
||||
dvc.imp(fspath(erepo_dir), "foo", "foo_imported", rev="master")
|
||||
dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported", rev="master")
|
||||
|
||||
remove(stage.outs[0].cache_path)
|
||||
dvc.fetch(all_tags=True)
|
||||
@@ -283,18 +282,18 @@ def test_pull_non_workspace(tmp_dir, scm, dvc, erepo_dir):
|
||||
|
||||
def test_import_non_existing(erepo_dir, tmp_dir, dvc):
|
||||
with pytest.raises(PathMissingError):
|
||||
tmp_dir.dvc.imp(fspath(erepo_dir), "invalid_output")
|
||||
tmp_dir.dvc.imp(os.fspath(erepo_dir), "invalid_output")
|
||||
|
||||
# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
|
||||
with pytest.raises(PathMissingError):
|
||||
tmp_dir.dvc.imp(fspath(erepo_dir), "/root/", "root")
|
||||
tmp_dir.dvc.imp(os.fspath(erepo_dir), "/root/", "root")
|
||||
|
||||
|
||||
def test_pull_no_rev_lock(erepo_dir, tmp_dir, dvc):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("foo", "contents", commit="create foo")
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "foo", "foo_imported")
|
||||
assert "rev" not in stage.deps[0].def_repo
|
||||
stage.deps[0].def_repo.pop("rev_lock")
|
||||
|
||||
@@ -314,19 +313,19 @@ def test_import_from_bare_git_repo(
|
||||
):
|
||||
import git
|
||||
|
||||
git.Repo.init(fspath(tmp_dir), bare=True)
|
||||
git.Repo.init(os.fspath(tmp_dir), bare=True)
|
||||
|
||||
setup_remote(erepo_dir.dvc)
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen({"foo": "foo"}, commit="initial")
|
||||
erepo_dir.dvc.push()
|
||||
|
||||
erepo_dir.scm.repo.create_remote("origin", fspath(tmp_dir))
|
||||
erepo_dir.scm.repo.create_remote("origin", os.fspath(tmp_dir))
|
||||
erepo_dir.scm.repo.remote("origin").push("master")
|
||||
|
||||
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
|
||||
with dvc_repo.chdir():
|
||||
dvc_repo.dvc.imp(fspath(tmp_dir), "foo")
|
||||
dvc_repo.dvc.imp(os.fspath(tmp_dir), "foo")
|
||||
|
||||
|
||||
def test_import_pipeline_tracked_outs(
|
||||
@@ -344,7 +343,7 @@ def test_import_pipeline_tracked_outs(
|
||||
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc.imp(
|
||||
"file:///{}".format(fspath(tmp_dir)), "bar", out="baz"
|
||||
"file:///{}".format(os.fspath(tmp_dir)), "bar", out="baz"
|
||||
)
|
||||
assert (erepo_dir / "baz").read_text() == "foo"
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.main import main
|
||||
from dvc.stage import Stage
|
||||
from dvc.utils.fs import makedirs
|
||||
@@ -44,7 +43,7 @@ def test_should_remove_outs_before_import(tmp_dir, dvc, mocker, erepo_dir):
|
||||
erepo_dir.gen({"foo": "foo"})
|
||||
|
||||
remove_outs_call_counter = mocker.spy(Stage, "remove_outs")
|
||||
ret = main(["import-url", fspath(erepo_dir / "foo")])
|
||||
ret = main(["import-url", os.fspath(erepo_dir / "foo")])
|
||||
|
||||
assert ret == 0
|
||||
assert remove_outs_call_counter.mock.call_count == 1
|
||||
@@ -99,7 +98,7 @@ def test_import_stage_accompanies_target(tmp_dir, dvc, erepo_dir):
|
||||
erepo_dir.dvc_gen("file1", "file1 content", commit="commit file")
|
||||
|
||||
tmp_dir.gen({"dir": {}})
|
||||
erepo = {"url": fspath(erepo_dir)}
|
||||
erepo = {"url": os.fspath(erepo_dir)}
|
||||
dvc.imp_url("file1", out=os.path.join("dir", "imported_file"), erepo=erepo)
|
||||
|
||||
assert (tmp_dir / "dir" / "imported_file").exists()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.config import Config
|
||||
from dvc.exceptions import InitError
|
||||
from dvc.main import main
|
||||
@@ -64,7 +63,7 @@ def test_init_no_scm_cli(tmp_dir):
|
||||
|
||||
dvc_path = tmp_dir / DvcRepo.DVC_DIR
|
||||
assert dvc_path.is_dir()
|
||||
assert Config(fspath(dvc_path))["core"]["no_scm"]
|
||||
assert Config(os.fspath(dvc_path))["core"]["no_scm"]
|
||||
|
||||
|
||||
def test_init_quiet_should_not_display_welcome_screen(tmp_dir, scm, caplog):
|
||||
@@ -83,8 +82,8 @@ def test_allow_init_dvc_subdir(tmp_dir, scm, monkeypatch):
|
||||
assert main(["init", "--subdir"]) == 0
|
||||
|
||||
repo = DvcRepo("subdir")
|
||||
assert repo.root_dir == fspath(tmp_dir / "subdir")
|
||||
assert repo.scm.root_dir == fspath(tmp_dir)
|
||||
assert repo.root_dir == os.fspath(tmp_dir / "subdir")
|
||||
assert repo.scm.root_dir == os.fspath(tmp_dir)
|
||||
|
||||
|
||||
def test_subdir_init_no_option(tmp_dir, scm, monkeypatch, caplog):
|
||||
@@ -100,5 +99,5 @@ def test_subdir_init_no_option(tmp_dir, scm, monkeypatch, caplog):
|
||||
"{} is not tracked by any supported SCM tool (e.g. Git). "
|
||||
"Use `--no-scm` if you don't want to use any SCM or "
|
||||
"`--subdir` if initializing inside a subdirectory of a parent SCM "
|
||||
"repository.".format(fspath(tmp_dir / "subdir"))
|
||||
"repository.".format(os.fspath(tmp_dir / "subdir"))
|
||||
) in caplog.text
|
||||
|
||||
@@ -5,7 +5,7 @@ import sys
|
||||
import pytest
|
||||
|
||||
from dvc.exceptions import GitHookAlreadyExistsError
|
||||
from dvc.utils import file_md5, fspath
|
||||
from dvc.utils import file_md5
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
@@ -52,7 +52,7 @@ class TestInstall(object):
|
||||
storage_path = temp / "dvc_storage"
|
||||
|
||||
with dvc.config.edit() as conf:
|
||||
conf["remote"]["store"] = {"url": fspath(storage_path)}
|
||||
conf["remote"]["store"] = {"url": os.fspath(storage_path)}
|
||||
conf["core"]["remote"] = "store"
|
||||
tmp_dir.dvc_gen("file", "file_content", "commit message")
|
||||
|
||||
@@ -61,8 +61,8 @@ class TestInstall(object):
|
||||
storage_path / file_checksum[:2] / file_checksum[2:]
|
||||
)
|
||||
|
||||
scm.repo.clone(fspath(git_remote))
|
||||
scm.repo.create_remote("origin", fspath(git_remote))
|
||||
scm.repo.clone(os.fspath(git_remote))
|
||||
scm.repo.create_remote("origin", os.fspath(git_remote))
|
||||
|
||||
assert not expected_storage_path.is_file()
|
||||
scm.repo.git.push("origin", "master")
|
||||
|
||||
+17
-18
@@ -3,7 +3,6 @@ import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import PathMissingError
|
||||
from dvc.repo import Repo
|
||||
from dvc.scm.base import CloneError
|
||||
@@ -55,7 +54,7 @@ def test_ls_repo(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
files = Repo.ls(fspath(tmp_dir))
|
||||
files = Repo.ls(os.fspath(tmp_dir))
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -77,7 +76,7 @@ def test_ls_repo_with_color(tmp_dir, dvc, scm, mocker, monkeypatch, caplog):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
monkeypatch.setenv("LS_COLORS", "rs=0:di=01;34:*.xml=01;31:*.dvc=01;33:")
|
||||
cli_args = parse_args(["list", fspath(tmp_dir)])
|
||||
cli_args = parse_args(["list", os.fspath(tmp_dir)])
|
||||
cmd = cli_args.func(cli_args)
|
||||
|
||||
caplog.clear()
|
||||
@@ -101,7 +100,7 @@ def test_ls_repo_recursive(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
files = Repo.ls(fspath(tmp_dir), recursive=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), recursive=True)
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -128,7 +127,7 @@ def test_ls_repo_outs_only_recursive(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
files = Repo.ls(fspath(tmp_dir), recursive=True, outs_only=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), recursive=True, outs_only=True)
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -144,7 +143,7 @@ def test_ls_repo_with_path_dir(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
files = Repo.ls(fspath(tmp_dir), path="model")
|
||||
files = Repo.ls(os.fspath(tmp_dir), path="model")
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -163,7 +162,7 @@ def test_ls_repo_with_path_dir_outs_only_empty(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen({"folder/.keep": "content"}, commit="add .keep")
|
||||
|
||||
with pytest.raises(PathMissingError):
|
||||
Repo.ls(fspath(tmp_dir), path="folder", outs_only=True)
|
||||
Repo.ls(os.fspath(tmp_dir), path="folder", outs_only=True)
|
||||
|
||||
|
||||
def test_ls_repo_with_path_subdir(tmp_dir, dvc, scm):
|
||||
@@ -171,7 +170,7 @@ def test_ls_repo_with_path_subdir(tmp_dir, dvc, scm):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = os.path.join("data", "subcontent")
|
||||
files = Repo.ls(fspath(tmp_dir), path)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path)
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -188,7 +187,7 @@ def test_ls_repo_with_path_subdir_outs_only(tmp_dir, dvc, scm):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = os.path.join("data", "subcontent")
|
||||
files = Repo.ls(fspath(tmp_dir), path, outs_only=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, outs_only=True)
|
||||
match_files(files, ((("data.xml",), True), (("statistics",), False),))
|
||||
|
||||
|
||||
@@ -197,7 +196,7 @@ def test_ls_repo_with_path_subdir_outs_only_recursive(tmp_dir, dvc, scm):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = os.path.join("data", "subcontent")
|
||||
files = Repo.ls(fspath(tmp_dir), path, outs_only=True, recursive=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, outs_only=True, recursive=True)
|
||||
match_files(
|
||||
files, ((("data.xml",), True), (("statistics", "data.csv"), True),)
|
||||
)
|
||||
@@ -208,7 +207,7 @@ def test_ls_repo_with_path_file_out(tmp_dir, dvc, scm):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = os.path.join("data", "subcontent", "data.xml")
|
||||
files = Repo.ls(fspath(tmp_dir), path)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path)
|
||||
match_files(files, ((("data.xml",), True),))
|
||||
|
||||
|
||||
@@ -217,7 +216,7 @@ def test_ls_repo_with_file_path_fs(tmp_dir, dvc, scm):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = "README.md"
|
||||
files = Repo.ls(fspath(tmp_dir), path, recursive=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, recursive=True)
|
||||
match_files(files, ((("README.md",), False),))
|
||||
|
||||
|
||||
@@ -226,7 +225,7 @@ def test_ls_repo_with_missed_path(tmp_dir, dvc, scm):
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
with pytest.raises(PathMissingError) as exc_info:
|
||||
Repo.ls(fspath(tmp_dir), path="missed_path")
|
||||
Repo.ls(os.fspath(tmp_dir), path="missed_path")
|
||||
assert not exc_info.value.output_only
|
||||
|
||||
|
||||
@@ -236,7 +235,7 @@ def test_ls_repo_with_missed_path_outs_only(tmp_dir, dvc, scm):
|
||||
|
||||
with pytest.raises(PathMissingError) as exc_info:
|
||||
Repo.ls(
|
||||
fspath(tmp_dir),
|
||||
os.fspath(tmp_dir),
|
||||
path="missed_path",
|
||||
recursive=True,
|
||||
outs_only=True,
|
||||
@@ -247,7 +246,7 @@ def test_ls_repo_with_missed_path_outs_only(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_with_removed_dvc_dir(tmp_dir, dvc, scm):
|
||||
create_dvc_pipeline(tmp_dir, dvc)
|
||||
|
||||
files = Repo.ls(fspath(tmp_dir))
|
||||
files = Repo.ls(os.fspath(tmp_dir))
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -264,7 +263,7 @@ def test_ls_repo_with_removed_dvc_dir(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_with_removed_dvc_dir_recursive(tmp_dir, dvc, scm):
|
||||
create_dvc_pipeline(tmp_dir, dvc)
|
||||
|
||||
files = Repo.ls(fspath(tmp_dir), recursive=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), recursive=True)
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -282,7 +281,7 @@ def test_ls_repo_with_removed_dvc_dir_with_path_dir(tmp_dir, dvc, scm):
|
||||
create_dvc_pipeline(tmp_dir, dvc)
|
||||
|
||||
path = "out"
|
||||
files = Repo.ls(fspath(tmp_dir), path)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path)
|
||||
match_files(files, ((("file",), True),))
|
||||
|
||||
|
||||
@@ -290,7 +289,7 @@ def test_ls_repo_with_removed_dvc_dir_with_path_file(tmp_dir, dvc, scm):
|
||||
create_dvc_pipeline(tmp_dir, dvc)
|
||||
|
||||
path = os.path.join("out", "file")
|
||||
files = Repo.ls(fspath(tmp_dir), path)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path)
|
||||
match_files(files, ((("file",), True),))
|
||||
|
||||
|
||||
|
||||
+8
-11
@@ -1,6 +1,7 @@
|
||||
import csv
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from collections import OrderedDict
|
||||
|
||||
@@ -9,7 +10,6 @@ import yaml
|
||||
from bs4 import BeautifulSoup
|
||||
from funcy import first
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.repo.plot import NoDataOrTemplateProvided
|
||||
from dvc.repo.plot.data import (
|
||||
NoMetricInHistoryError,
|
||||
@@ -244,9 +244,7 @@ def test_plot_multiple_revs_default(tmp_dir, scm, dvc):
|
||||
|
||||
|
||||
def test_plot_multiple_revs(tmp_dir, scm, dvc):
|
||||
shutil.copy(
|
||||
fspath(tmp_dir / ".dvc" / "plot" / "default.json"), "template.json"
|
||||
)
|
||||
shutil.copy(tmp_dir / ".dvc" / "plot" / "default.json", "template.json")
|
||||
|
||||
metric_1 = [{"y": 2}, {"y": 3}]
|
||||
_write_json(tmp_dir, metric_1, "metric.json")
|
||||
@@ -326,8 +324,7 @@ def test_throw_on_no_metric_at_all(tmp_dir, scm, dvc, caplog):
|
||||
def custom_template(tmp_dir, dvc):
|
||||
custom_template = tmp_dir / "custom_template.json"
|
||||
shutil.copy(
|
||||
fspath(tmp_dir / ".dvc" / "plot" / "default.json"),
|
||||
fspath(custom_template),
|
||||
tmp_dir / ".dvc" / "plot" / "default.json", custom_template,
|
||||
)
|
||||
return custom_template
|
||||
|
||||
@@ -338,7 +335,7 @@ def test_custom_template(tmp_dir, scm, dvc, custom_template):
|
||||
_run_with_metric(tmp_dir, "metric.json", "init", "v1")
|
||||
|
||||
plot_string = dvc.plot(
|
||||
"metric.json", fspath(custom_template), x_field="a", y_field="b"
|
||||
"metric.json", os.fspath(custom_template), x_field="a", y_field="b"
|
||||
)
|
||||
|
||||
plot_content = json.loads(plot_string)
|
||||
@@ -367,7 +364,7 @@ def test_custom_template_with_specified_data(
|
||||
|
||||
plot_string = dvc.plot(
|
||||
datafile=None,
|
||||
template=fspath(custom_template),
|
||||
template=os.fspath(custom_template),
|
||||
x_field="a",
|
||||
y_field="b",
|
||||
)
|
||||
@@ -383,8 +380,8 @@ def test_custom_template_with_specified_data(
|
||||
|
||||
def test_plot_override_specified_data_source(tmp_dir, scm, dvc):
|
||||
shutil.copy(
|
||||
fspath(tmp_dir / ".dvc" / "plot" / "default.json"),
|
||||
fspath(tmp_dir / "newtemplate.json"),
|
||||
tmp_dir / ".dvc" / "plot" / "default.json",
|
||||
tmp_dir / "newtemplate.json",
|
||||
)
|
||||
_replace(
|
||||
tmp_dir / "newtemplate.json",
|
||||
@@ -437,7 +434,7 @@ def test_plot_choose_columns(tmp_dir, scm, dvc, custom_template):
|
||||
|
||||
plot_string = dvc.plot(
|
||||
"metric.json",
|
||||
fspath(custom_template),
|
||||
os.fspath(custom_template),
|
||||
fields={"b", "c"},
|
||||
x_field="b",
|
||||
y_field="c",
|
||||
|
||||
@@ -5,7 +5,6 @@ import configobj
|
||||
import pytest
|
||||
from mock import patch
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.config import Config
|
||||
from dvc.exceptions import DownloadError, UploadError
|
||||
from dvc.main import main
|
||||
@@ -239,7 +238,7 @@ def test_external_dir_resource_on_no_cache(tmp_dir, dvc, tmp_path_factory):
|
||||
|
||||
dvc.cache.local = None
|
||||
with pytest.raises(RemoteCacheRequiredError):
|
||||
dvc.run(deps=[fspath(external_dir)], single_stage=True)
|
||||
dvc.run(deps=[os.fspath(external_dir)], single_stage=True)
|
||||
|
||||
|
||||
def test_push_order(tmp_dir, dvc, tmp_path_factory, mocker, setup_remote):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
|
||||
from dvc.cache import Cache
|
||||
from dvc.compat import fspath
|
||||
from dvc.repo import Repo
|
||||
from dvc.system import System
|
||||
|
||||
@@ -54,7 +53,7 @@ def test_destroy(tmp_dir, dvc, run_copy):
|
||||
"dir/subdir",
|
||||
"dir/subdir/file",
|
||||
]:
|
||||
assert not System.is_symlink(fspath(tmp_dir / path))
|
||||
assert not System.is_symlink(tmp_dir / path)
|
||||
|
||||
|
||||
def test_collect(tmp_dir, scm, dvc, run_copy):
|
||||
@@ -101,7 +100,7 @@ def test_collect(tmp_dir, scm, dvc, run_copy):
|
||||
|
||||
def test_stages(tmp_dir, dvc):
|
||||
def stages():
|
||||
return set(stage.relpath for stage in Repo(fspath(tmp_dir)).stages)
|
||||
return set(stage.relpath for stage in Repo(os.fspath(tmp_dir)).stages)
|
||||
|
||||
tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"})
|
||||
|
||||
|
||||
+11
-12
@@ -17,7 +17,6 @@ from flaky.flaky_decorator import flaky
|
||||
from google.cloud import storage as gc
|
||||
from mock import patch
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.dvcfile import DVC_FILE, Dvcfile
|
||||
from dvc.exceptions import (
|
||||
CyclicGraphError,
|
||||
@@ -1429,16 +1428,16 @@ def repro_dir(tmp_dir, dvc, run_copy):
|
||||
stages = {}
|
||||
|
||||
origin_copy = tmp_dir / "origin_copy"
|
||||
stage = run_copy("origin_data", fspath(origin_copy), single_stage=True)
|
||||
stage = run_copy("origin_data", os.fspath(origin_copy), single_stage=True)
|
||||
assert stage is not None
|
||||
assert origin_copy.read_text() == "origin data content"
|
||||
stages["origin_copy"] = stage
|
||||
|
||||
origin_copy_2 = tmp_dir / "dir" / "origin_copy_2"
|
||||
stage = run_copy(
|
||||
fspath(origin_copy),
|
||||
fspath(origin_copy_2),
|
||||
fname=fspath(origin_copy_2) + ".dvc",
|
||||
os.fspath(origin_copy),
|
||||
os.fspath(origin_copy_2),
|
||||
fname=os.fspath(origin_copy_2) + ".dvc",
|
||||
single_stage=True,
|
||||
)
|
||||
assert stage is not None
|
||||
@@ -1448,9 +1447,9 @@ def repro_dir(tmp_dir, dvc, run_copy):
|
||||
dir_file_path = tmp_dir / "data_dir" / "dir_file"
|
||||
dir_file_copy = tmp_dir / "dir" / "subdir" / "dir_file_copy"
|
||||
stage = run_copy(
|
||||
fspath(dir_file_path),
|
||||
fspath(dir_file_copy),
|
||||
fname=fspath(dir_file_copy) + ".dvc",
|
||||
os.fspath(dir_file_path),
|
||||
os.fspath(dir_file_copy),
|
||||
fname=os.fspath(dir_file_copy) + ".dvc",
|
||||
single_stage=True,
|
||||
)
|
||||
assert stage is not None
|
||||
@@ -1459,8 +1458,8 @@ def repro_dir(tmp_dir, dvc, run_copy):
|
||||
|
||||
last_stage = tmp_dir / "dir" / DVC_FILE
|
||||
stage = dvc.run(
|
||||
fname=fspath(last_stage),
|
||||
deps=[fspath(origin_copy_2), fspath(dir_file_copy)],
|
||||
fname=os.fspath(last_stage),
|
||||
deps=[os.fspath(origin_copy_2), os.fspath(dir_file_copy)],
|
||||
single_stage=True,
|
||||
)
|
||||
assert stage is not None
|
||||
@@ -1468,11 +1467,11 @@ def repro_dir(tmp_dir, dvc, run_copy):
|
||||
|
||||
# Unrelated are to verify that reproducing `dir` will not trigger them too
|
||||
assert (
|
||||
run_copy(fspath(origin_copy), "unrelated1", single_stage=True)
|
||||
run_copy(os.fspath(origin_copy), "unrelated1", single_stage=True)
|
||||
is not None
|
||||
)
|
||||
assert (
|
||||
run_copy(fspath(dir_file_path), "unrelated2", single_stage=True)
|
||||
run_copy(os.fspath(dir_file_path), "unrelated2", single_stage=True)
|
||||
is not None
|
||||
)
|
||||
|
||||
|
||||
+24
-25
@@ -3,7 +3,6 @@ import os
|
||||
import pytest
|
||||
from git import Repo
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.scm import SCM, Git, NoSCM
|
||||
from dvc.scm.base import SCMError
|
||||
from dvc.system import System
|
||||
@@ -12,26 +11,26 @@ from tests.utils import get_gitignore_content
|
||||
|
||||
|
||||
def test_init_none(tmp_dir):
|
||||
assert isinstance(SCM(fspath(tmp_dir), no_scm=True), NoSCM)
|
||||
assert isinstance(SCM(os.fspath(tmp_dir), no_scm=True), NoSCM)
|
||||
|
||||
|
||||
def test_init_git(tmp_dir):
|
||||
Repo.init(fspath(tmp_dir))
|
||||
assert isinstance(SCM(fspath(tmp_dir)), Git)
|
||||
Repo.init(os.fspath(tmp_dir))
|
||||
assert isinstance(SCM(os.fspath(tmp_dir)), Git)
|
||||
|
||||
|
||||
def test_init_no_git(tmp_dir):
|
||||
with pytest.raises(SCMError):
|
||||
SCM(fspath(tmp_dir))
|
||||
SCM(os.fspath(tmp_dir))
|
||||
|
||||
|
||||
def test_init_sub_dir(tmp_dir):
|
||||
Repo.init(fspath(tmp_dir))
|
||||
Repo.init(os.fspath(tmp_dir))
|
||||
subdir = tmp_dir / "dir"
|
||||
subdir.mkdir()
|
||||
|
||||
scm = SCM(fspath(subdir))
|
||||
assert scm.root_dir == fspath(tmp_dir)
|
||||
scm = SCM(os.fspath(subdir))
|
||||
assert scm.root_dir == os.fspath(tmp_dir)
|
||||
|
||||
|
||||
class TestSCMGit(TestGit):
|
||||
@@ -74,7 +73,7 @@ def _count_gitignore_entries(line):
|
||||
|
||||
|
||||
def test_ignore(tmp_dir, scm):
|
||||
foo = fspath(tmp_dir / "foo")
|
||||
foo = os.fspath(tmp_dir / "foo")
|
||||
target = "/foo"
|
||||
|
||||
scm.ignore(foo)
|
||||
@@ -93,54 +92,54 @@ def test_ignored(tmp_dir, scm):
|
||||
tmp_dir.gen({"dir1": {"file1.jpg": "cont", "file2.txt": "cont"}})
|
||||
tmp_dir.gen({".gitignore": "dir1/*.jpg"})
|
||||
|
||||
assert scm._ignored(fspath(tmp_dir / "dir1" / "file1.jpg"))
|
||||
assert not scm._ignored(fspath(tmp_dir / "dir1" / "file2.txt"))
|
||||
assert scm._ignored(os.fspath(tmp_dir / "dir1" / "file1.jpg"))
|
||||
assert not scm._ignored(os.fspath(tmp_dir / "dir1" / "file2.txt"))
|
||||
|
||||
|
||||
def test_get_gitignore(tmp_dir, scm):
|
||||
tmp_dir.gen({"file1": "contents", "dir": {}})
|
||||
|
||||
data_dir = fspath(tmp_dir / "file1")
|
||||
data_dir = os.fspath(tmp_dir / "file1")
|
||||
entry, gitignore = scm._get_gitignore(data_dir)
|
||||
assert entry == "/file1"
|
||||
assert gitignore == fspath(tmp_dir / ".gitignore")
|
||||
assert gitignore == os.fspath(tmp_dir / ".gitignore")
|
||||
|
||||
data_dir = fspath(tmp_dir / "dir")
|
||||
data_dir = os.fspath(tmp_dir / "dir")
|
||||
entry, gitignore = scm._get_gitignore(data_dir)
|
||||
|
||||
assert entry == "/dir"
|
||||
assert gitignore == fspath(tmp_dir / ".gitignore")
|
||||
assert gitignore == os.fspath(tmp_dir / ".gitignore")
|
||||
|
||||
|
||||
def test_get_gitignore_symlink(tmp_dir, scm):
|
||||
tmp_dir.gen({"dir": {"subdir": {"data": "contents"}}})
|
||||
link = fspath(tmp_dir / "link")
|
||||
target = fspath(tmp_dir / "dir" / "subdir" / "data")
|
||||
link = os.fspath(tmp_dir / "link")
|
||||
target = os.fspath(tmp_dir / "dir" / "subdir" / "data")
|
||||
System.symlink(target, link)
|
||||
entry, gitignore = scm._get_gitignore(link)
|
||||
assert entry == "/link"
|
||||
assert gitignore == fspath(tmp_dir / ".gitignore")
|
||||
assert gitignore == os.fspath(tmp_dir / ".gitignore")
|
||||
|
||||
|
||||
def test_get_gitignore_subdir(tmp_dir, scm):
|
||||
tmp_dir.gen({"dir1": {"file1": "cont", "dir2": {}}})
|
||||
|
||||
data_dir = fspath(tmp_dir / "dir1" / "file1")
|
||||
data_dir = os.fspath(tmp_dir / "dir1" / "file1")
|
||||
entry, gitignore = scm._get_gitignore(data_dir)
|
||||
assert entry == "/file1"
|
||||
assert gitignore == fspath(tmp_dir / "dir1" / ".gitignore")
|
||||
assert gitignore == os.fspath(tmp_dir / "dir1" / ".gitignore")
|
||||
|
||||
data_dir = fspath(tmp_dir / "dir1" / "dir2")
|
||||
data_dir = os.fspath(tmp_dir / "dir1" / "dir2")
|
||||
entry, gitignore = scm._get_gitignore(data_dir)
|
||||
assert entry == "/dir2"
|
||||
assert gitignore == fspath(tmp_dir / "dir1" / ".gitignore")
|
||||
assert gitignore == os.fspath(tmp_dir / "dir1" / ".gitignore")
|
||||
|
||||
|
||||
def test_gitignore_should_end_with_newline(tmp_dir, scm):
|
||||
tmp_dir.gen({"foo": "foo", "bar": "bar"})
|
||||
|
||||
foo = fspath(tmp_dir / "foo")
|
||||
bar = fspath(tmp_dir / "bar")
|
||||
foo = os.fspath(tmp_dir / "foo")
|
||||
bar = os.fspath(tmp_dir / "bar")
|
||||
gitignore = tmp_dir / ".gitignore"
|
||||
|
||||
scm.ignore(foo)
|
||||
@@ -153,7 +152,7 @@ def test_gitignore_should_end_with_newline(tmp_dir, scm):
|
||||
def test_gitignore_should_append_newline_to_gitignore(tmp_dir, scm):
|
||||
tmp_dir.gen({"foo": "foo", "bar": "bar"})
|
||||
|
||||
bar_path = fspath(tmp_dir / "bar")
|
||||
bar_path = os.fspath(tmp_dir / "bar")
|
||||
gitignore = tmp_dir / ".gitignore"
|
||||
|
||||
gitignore.write_text("/foo")
|
||||
|
||||
@@ -2,7 +2,6 @@ import os
|
||||
|
||||
from mock import patch
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.main import main
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
@@ -30,7 +29,7 @@ def test_status_non_dvc_repo_import(tmp_dir, dvc, git_dir):
|
||||
with git_dir.branch("branch", new=True):
|
||||
git_dir.scm_gen("file", "first version", commit="first version")
|
||||
|
||||
dvc.imp(fspath(git_dir), "file", "file", rev="branch")
|
||||
dvc.imp(os.fspath(git_dir), "file", "file", rev="branch")
|
||||
|
||||
assert dvc.status(["file.dvc"]) == {}
|
||||
|
||||
@@ -47,7 +46,7 @@ def test_status_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
|
||||
git_dir.scm_gen("file", "first version", commit="first verison")
|
||||
old_rev = git_dir.scm.get_rev()
|
||||
|
||||
dvc.imp(fspath(git_dir), "file", "file")
|
||||
dvc.imp(os.fspath(git_dir), "file", "file")
|
||||
|
||||
assert dvc.status(["file.dvc"]) == {}
|
||||
|
||||
@@ -63,7 +62,7 @@ def test_status_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
|
||||
(status,) = dvc.status(["file.dvc"])["file.dvc"]
|
||||
assert status == {
|
||||
"changed deps": {
|
||||
"file ({})".format(fspath(git_dir)): "update available"
|
||||
"file ({})".format(os.fspath(git_dir)): "update available"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-16
@@ -2,7 +2,6 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.compat import fspath, fspath_py35
|
||||
from dvc.dvcfile import Dvcfile
|
||||
|
||||
|
||||
@@ -14,7 +13,7 @@ def test_update_import(tmp_dir, dvc, erepo_dir, cached):
|
||||
gen("version", "branch", "add version file")
|
||||
old_rev = erepo_dir.scm.get_rev()
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "version", "version", rev="branch")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "version", "version", rev="branch")
|
||||
|
||||
assert (tmp_dir / "version").read_text() == "branch"
|
||||
assert stage.deps[0].def_repo["rev_lock"] == old_rev
|
||||
@@ -39,13 +38,13 @@ def test_update_import_after_remote_updates_to_dvc(tmp_dir, dvc, erepo_dir):
|
||||
erepo_dir.scm_gen("version", "branch", commit="add version file")
|
||||
old_rev = erepo_dir.scm.get_rev()
|
||||
|
||||
stage = dvc.imp(fspath(erepo_dir), "version", "version", rev="branch")
|
||||
stage = dvc.imp(os.fspath(erepo_dir), "version", "version", rev="branch")
|
||||
|
||||
imported = tmp_dir / "version"
|
||||
assert imported.is_file()
|
||||
assert imported.read_text() == "branch"
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev": "branch",
|
||||
"rev_lock": old_rev,
|
||||
}
|
||||
@@ -74,7 +73,7 @@ def test_update_import_after_remote_updates_to_dvc(tmp_dir, dvc, erepo_dir):
|
||||
|
||||
stage = Dvcfile(dvc, stage.path).stage
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(erepo_dir),
|
||||
"url": os.fspath(erepo_dir),
|
||||
"rev": "branch",
|
||||
"rev_lock": new_rev,
|
||||
}
|
||||
@@ -85,7 +84,7 @@ def test_update_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
|
||||
git_dir.scm_gen("file", "first version", commit="first version")
|
||||
old_rev = git_dir.scm.get_rev()
|
||||
|
||||
stage = dvc.imp(fspath(git_dir), "file", "file")
|
||||
stage = dvc.imp(os.fspath(git_dir), "file", "file")
|
||||
|
||||
with git_dir.chdir():
|
||||
git_dir.init(dvc=True)
|
||||
@@ -100,7 +99,7 @@ def test_update_before_and_after_dvc_init(tmp_dir, dvc, git_dir):
|
||||
"file.dvc": [
|
||||
{
|
||||
"changed deps": {
|
||||
"file ({})".format(fspath(git_dir)): "update available"
|
||||
"file ({})".format(os.fspath(git_dir)): "update available"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -118,7 +117,7 @@ def test_update_import_url(tmp_dir, dvc, tmp_path_factory):
|
||||
src.write_text("file content")
|
||||
|
||||
dst = tmp_dir / "imported_file"
|
||||
stage = dvc.imp_url(fspath(src), fspath(dst))
|
||||
stage = dvc.imp_url(os.fspath(src), os.fspath(dst))
|
||||
|
||||
assert dst.is_file()
|
||||
assert dst.read_text() == "file content"
|
||||
@@ -138,7 +137,7 @@ def test_update_rev(tmp_dir, dvc, scm, git_dir):
|
||||
with git_dir.chdir():
|
||||
git_dir.scm_gen({"foo": "foo"}, commit="first")
|
||||
|
||||
dvc.imp(fspath(git_dir), "foo")
|
||||
dvc.imp(os.fspath(git_dir), "foo")
|
||||
assert (tmp_dir / "foo.dvc").exists()
|
||||
|
||||
with git_dir.chdir(), git_dir.branch("branch1", new=True):
|
||||
@@ -151,20 +150,20 @@ def test_update_rev(tmp_dir, dvc, scm, git_dir):
|
||||
|
||||
stage = dvc.update(["foo.dvc"], rev="branch1")[0]
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(git_dir),
|
||||
"url": os.fspath(git_dir),
|
||||
"rev": "branch1",
|
||||
"rev_lock": branch1_head,
|
||||
}
|
||||
with open(fspath_py35(tmp_dir / "foo")) as f:
|
||||
with open(tmp_dir / "foo") as f:
|
||||
assert "foobar" == f.read()
|
||||
|
||||
stage = dvc.update(["foo.dvc"], rev="branch2")[0]
|
||||
assert stage.deps[0].def_repo == {
|
||||
"url": fspath(git_dir),
|
||||
"url": os.fspath(git_dir),
|
||||
"rev": "branch2",
|
||||
"rev_lock": branch2_head,
|
||||
}
|
||||
with open(fspath_py35(tmp_dir / "foo")) as f:
|
||||
with open(tmp_dir / "foo") as f:
|
||||
assert "foobar foo" == f.read()
|
||||
|
||||
|
||||
@@ -178,16 +177,19 @@ def test_update_recursive(tmp_dir, dvc, erepo_dir):
|
||||
|
||||
tmp_dir.gen({"dir": {"subdir": {}}})
|
||||
stage1 = dvc.imp(
|
||||
fspath(erepo_dir), "foo1", os.path.join("dir", "foo1"), rev="branch",
|
||||
os.fspath(erepo_dir),
|
||||
"foo1",
|
||||
os.path.join("dir", "foo1"),
|
||||
rev="branch",
|
||||
)
|
||||
stage2 = dvc.imp(
|
||||
fspath(erepo_dir),
|
||||
os.fspath(erepo_dir),
|
||||
"foo2",
|
||||
os.path.join("dir", "subdir", "foo2"),
|
||||
rev="branch",
|
||||
)
|
||||
stage3 = dvc.imp(
|
||||
fspath(erepo_dir),
|
||||
os.fspath(erepo_dir),
|
||||
"foo3",
|
||||
os.path.join("dir", "subdir", "foo3"),
|
||||
rev="branch",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from dvc.compat import fspath_py35
|
||||
from dvc.repo.tree import DvcTree
|
||||
|
||||
|
||||
@@ -54,7 +53,7 @@ def test_isdir_isfile(tmp_dir, dvc):
|
||||
assert not tree.isfile("datafile")
|
||||
|
||||
dvc.add(["datadir", "datafile"])
|
||||
shutil.rmtree(fspath_py35(tmp_dir / "datadir"))
|
||||
shutil.rmtree(tmp_dir / "datadir")
|
||||
(tmp_dir / "datafile").unlink()
|
||||
|
||||
assert tree.isdir("datadir")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
|
||||
from dvc.compat import fspath
|
||||
from tests.basic_env import TestDvcGit
|
||||
|
||||
|
||||
@@ -23,7 +22,7 @@ def test_walk_with_submodules(tmp_dir, scm, git_dir):
|
||||
{"foo": "foo", "bar": "bar", "dir": {"data": "data"}},
|
||||
commit="add dir and files",
|
||||
)
|
||||
scm.repo.create_submodule("submodule", "submodule", url=fspath(git_dir))
|
||||
scm.repo.create_submodule("submodule", "submodule", url=os.fspath(git_dir))
|
||||
scm.commit("added submodule")
|
||||
|
||||
files = []
|
||||
|
||||
@@ -2,7 +2,6 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.compat import fspath
|
||||
from dvc.lock import LockError
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.rwlock import (
|
||||
@@ -14,7 +13,7 @@ from dvc.rwlock import (
|
||||
|
||||
|
||||
def test_rwlock(tmp_path):
|
||||
path = fspath(tmp_path)
|
||||
path = os.fspath(tmp_path)
|
||||
foo = PathInfo("foo")
|
||||
|
||||
with rwlock(path, "cmd1", [foo], []):
|
||||
@@ -34,7 +33,7 @@ def test_rwlock(tmp_path):
|
||||
|
||||
|
||||
def test_rwlock_reentrant(tmp_path):
|
||||
path = fspath(tmp_path)
|
||||
path = os.fspath(tmp_path)
|
||||
foo = PathInfo("foo")
|
||||
|
||||
with rwlock(path, "cmd1", [], [foo]):
|
||||
@@ -57,7 +56,7 @@ def test_rwlock_reentrant(tmp_path):
|
||||
|
||||
|
||||
def test_rwlock_subdirs(tmp_path):
|
||||
path = fspath(tmp_path)
|
||||
path = os.fspath(tmp_path)
|
||||
foo = PathInfo("foo")
|
||||
subfoo = PathInfo("foo/subfoo")
|
||||
|
||||
@@ -82,7 +81,7 @@ def test_rwlock_subdirs(tmp_path):
|
||||
|
||||
|
||||
def test_broken_rwlock(tmp_path):
|
||||
dir_path = fspath(tmp_path)
|
||||
dir_path = os.fspath(tmp_path)
|
||||
path = tmp_path / "rwlock"
|
||||
|
||||
path.write_text('{"broken": "format"}', encoding="utf-8")
|
||||
|
||||
+12
-13
@@ -6,7 +6,6 @@ import pytest
|
||||
from mock import patch
|
||||
|
||||
import dvc
|
||||
from dvc.compat import fspath
|
||||
from dvc.ignore import CleanTree
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.scm.tree import WorkingTree
|
||||
@@ -156,11 +155,11 @@ def test_move(tmp_dir):
|
||||
assert not os.path.isfile(src)
|
||||
assert len(os.listdir(dest)) == 1
|
||||
|
||||
os.makedirs(dest_info.fspath)
|
||||
assert len(os.listdir(dest_info.fspath)) == 0
|
||||
os.makedirs(dest_info)
|
||||
assert len(os.listdir(dest_info)) == 0
|
||||
move(src_info, dest_info)
|
||||
assert not os.path.isfile(src_info.fspath)
|
||||
assert len(os.listdir(dest_info.fspath)) == 1
|
||||
assert not os.path.isfile(src_info)
|
||||
assert len(os.listdir(dest_info)) == 1
|
||||
|
||||
|
||||
def test_remove(tmp_dir):
|
||||
@@ -172,7 +171,7 @@ def test_remove(tmp_dir):
|
||||
assert not os.path.isfile(path)
|
||||
|
||||
remove(path_info)
|
||||
assert not os.path.isfile(path_info.fspath)
|
||||
assert not os.path.isfile(path_info)
|
||||
|
||||
|
||||
def test_path_isin_positive():
|
||||
@@ -217,14 +216,14 @@ def test_path_isin_with_absolute_path():
|
||||
|
||||
|
||||
def test_makedirs(tmp_dir):
|
||||
path = os.path.join(fspath(tmp_dir), "directory")
|
||||
path_info = PathInfo(os.path.join(fspath(tmp_dir), "another", "directory"))
|
||||
path = os.path.join(tmp_dir, "directory")
|
||||
path_info = PathInfo(os.path.join(tmp_dir, "another", "directory"))
|
||||
|
||||
makedirs(path)
|
||||
assert os.path.isdir(path)
|
||||
|
||||
makedirs(path_info)
|
||||
assert os.path.isdir(path_info.fspath)
|
||||
assert os.path.isdir(path_info)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["file", "dir"])
|
||||
@@ -251,14 +250,14 @@ def test_copyfile(path, tmp_dir):
|
||||
assert filecmp.cmp(src, dest, shallow=False)
|
||||
|
||||
copyfile(src_info, dest_info)
|
||||
if os.path.isdir(dest_info.fspath):
|
||||
if os.path.isdir(dest_info):
|
||||
assert filecmp.cmp(
|
||||
src_info.fspath,
|
||||
os.path.join(dest_info.fspath, os.path.basename(src_info.fspath)),
|
||||
src_info,
|
||||
os.path.join(dest_info, os.path.basename(src_info)),
|
||||
shallow=False,
|
||||
)
|
||||
else:
|
||||
assert filecmp.cmp(src_info.fspath, dest_info.fspath, shallow=False)
|
||||
assert filecmp.cmp(src_info, dest_info, shallow=False)
|
||||
|
||||
|
||||
def test_walk_files(tmp_dir):
|
||||
|
||||
Reference in New Issue
Block a user