mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 23:09:35 +01:00
Merge branch 'master' into summon
This commit is contained in:
+3
-1
@@ -164,4 +164,6 @@ def _find_or_create_user_id():
|
||||
return user_id
|
||||
|
||||
except LockError:
|
||||
logger.debug("Failed to acquire {lockfile}".format(lockfile=lockfile))
|
||||
logger.debug(
|
||||
"Failed to acquire '{lockfile}'".format(lockfile=lockfile)
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ class CmdRemove(CmdBase):
|
||||
if self.args.force:
|
||||
return False
|
||||
|
||||
msg = "Are you sure you want to remove {} with its outputs?".format(
|
||||
msg = "Are you sure you want to remove '{}' with its outputs?".format(
|
||||
target
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ class CmdRemove(CmdBase):
|
||||
outs_only = self._is_outs_only(target)
|
||||
self.repo.remove(target, outs_only=outs_only)
|
||||
except DvcException:
|
||||
logger.exception("failed to remove {}".format(target))
|
||||
logger.exception("failed to remove '{}'".format(target))
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ def Choices(*choices):
|
||||
*choices: pass allowed values as arguments, or pass a list or
|
||||
tuple as a single argument
|
||||
"""
|
||||
return Any(*choices, msg="expected one of {}".format(",".join(choices)))
|
||||
return Any(*choices, msg="expected one of {}".format(", ".join(choices)))
|
||||
|
||||
|
||||
class Config(object): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ class RemoteCmdError(DvcException):
|
||||
|
||||
class RemoteActionNotImplemented(DvcException):
|
||||
def __init__(self, action, scheme):
|
||||
m = "{} is not supported by {} remote".format(action, scheme)
|
||||
m = "{} is not supported for {} remotes".format(action, scheme)
|
||||
super(RemoteActionNotImplemented, self).__init__(m)
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -69,9 +69,9 @@ class RemoteOSS(RemoteBASE):
|
||||
def oss_service(self):
|
||||
import oss2
|
||||
|
||||
logger.debug("URL {}".format(self.path_info))
|
||||
logger.debug("key id {}".format(self.key_id))
|
||||
logger.debug("key secret {}".format(self.key_secret))
|
||||
logger.debug("URL: {}".format(self.path_info))
|
||||
logger.debug("key id: {}".format(self.key_id))
|
||||
logger.debug("key secret: {}".format(self.key_secret))
|
||||
|
||||
auth = oss2.Auth(self.key_id, self.key_secret)
|
||||
bucket = oss2.Bucket(auth, self.endpoint, self.path_info.bucket)
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ def add(repo, targets, recursive=False, no_commit=False, fname=None):
|
||||
"You are adding a large directory '{target}' recursively,"
|
||||
" consider tracking it as a whole instead.\n"
|
||||
"{purple}HINT:{nc} Remove the generated DVC-file and then"
|
||||
" run {cyan}dvc add {target}{nc}".format(
|
||||
" run `{cyan}dvc add {target}{nc}`".format(
|
||||
purple=colorama.Fore.MAGENTA,
|
||||
cyan=colorama.Fore.CYAN,
|
||||
nc=colorama.Style.RESET_ALL,
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
|
||||
def _do_gc(typ, func, clist):
|
||||
removed = func(clist)
|
||||
if not removed:
|
||||
logger.info("No unused {} cache to remove.".format(typ))
|
||||
logger.info("No unused '{}' cache to remove.".format(typ))
|
||||
|
||||
|
||||
@locked
|
||||
|
||||
+2
-2
@@ -116,7 +116,7 @@ class MissingDep(DvcException):
|
||||
else:
|
||||
dep = "dependency"
|
||||
|
||||
msg = "missing {}: {}".format(dep, ", ".join(map(str, deps)))
|
||||
msg = "missing '{}': {}".format(dep, ", ".join(map(str, deps)))
|
||||
super(MissingDep, self).__init__(msg)
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class MissingDataSource(DvcException):
|
||||
if len(missing_files) > 1:
|
||||
source += "s"
|
||||
|
||||
msg = "missing data {}: {}".format(source, ", ".join(missing_files))
|
||||
msg = "missing data '{}': {}".format(source, ", ".join(missing_files))
|
||||
super(MissingDataSource, self).__init__(msg)
|
||||
|
||||
|
||||
|
||||
+10
-10
@@ -124,12 +124,13 @@ class Updater(object): # pragma: no cover
|
||||
|
||||
def _get_update_instructions(self):
|
||||
instructions = {
|
||||
"pip": "Run {yellow}pip{reset} install dvc {blue}--upgrade{reset}",
|
||||
"rpm": "Run {yellow}yum{reset} update dvc",
|
||||
"brew": "Run {yellow}brew{reset} upgrade dvc",
|
||||
"pip": "Run `{yellow}pip{reset} install dvc "
|
||||
"{blue}--upgrade{reset}`",
|
||||
"rpm": "Run `{yellow}yum{reset} update dvc`",
|
||||
"brew": "Run `{yellow}brew{reset} upgrade dvc`",
|
||||
"deb": (
|
||||
"Run {yellow}apt-get{reset} install"
|
||||
" {blue}--only-upgrade{reset} dvc"
|
||||
"Run `{yellow}apt-get{reset} install"
|
||||
" {blue}--only-upgrade{reset} dvc`"
|
||||
),
|
||||
"binary": (
|
||||
"To upgrade follow these steps:\n"
|
||||
@@ -137,12 +138,11 @@ class Updater(object): # pragma: no cover
|
||||
"2. Go to {blue}https://dvc.org{reset}\n"
|
||||
"3. Download and install new binary"
|
||||
),
|
||||
"conda": "Run {yellow}conda{reset} update dvc",
|
||||
"choco": "Run {yellow}choco{reset} upgrade dvc",
|
||||
"conda": "Run `{yellow}conda{reset} update dvc`",
|
||||
"choco": "Run `{yellow}choco{reset} upgrade dvc`",
|
||||
None: (
|
||||
"Find the latest release at\n{blue}"
|
||||
"https://github.com/iterative/dvc/releases/latest"
|
||||
"{reset}"
|
||||
"Find the latest release at\n"
|
||||
"{blue}https://github.com/iterative/dvc/releases/latest{reset}"
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ def file_md5(fname):
|
||||
no_progress_bar = True
|
||||
if size >= LARGE_FILE_SIZE:
|
||||
no_progress_bar = False
|
||||
msg = "Computing md5 for a large file {}. This is only done once."
|
||||
msg = (
|
||||
"Computing md5 for a large file '{}'. This is only done once."
|
||||
)
|
||||
logger.info(msg.format(relpath(fname)))
|
||||
name = relpath(fname)
|
||||
|
||||
|
||||
@@ -87,6 +87,9 @@ install_dependencies()
|
||||
fi
|
||||
|
||||
gem install --no-document fpm
|
||||
|
||||
# https://github.com/iterative/dvc/issues/2970
|
||||
gem uninstall -i /Users/travis/.rvm/gems/ruby-2.4.3@global rubygems-bundler
|
||||
|
||||
print_info "Upgrading pip..."
|
||||
pip install --upgrade pip
|
||||
|
||||
@@ -45,10 +45,10 @@ fi
|
||||
|
||||
if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
|
||||
if [[ -n "$PY2" ]]; then
|
||||
choco install python2
|
||||
$scriptdir/retry.sh choco install python2
|
||||
echo 'PATH="/c/Python27:/c/Python27/Scripts:$PATH"' >> env.sh
|
||||
else
|
||||
choco install python --version 3.7.5
|
||||
$scriptdir/retry.sh choco install python --version 3.7.5
|
||||
echo 'PATH="/c/Python37:/c/Python37/Scripts:$PATH"' >> env.sh
|
||||
fi
|
||||
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
||||
|
||||
@@ -92,7 +92,7 @@ class TestAddCmdDirectoryRecursive(TestDvc):
|
||||
"You are adding a large directory 'large-dir' recursively,"
|
||||
" consider tracking it as a whole instead.\n"
|
||||
"{purple}HINT:{nc} Remove the generated DVC-file and then"
|
||||
" run {cyan}dvc add large-dir{nc}".format(
|
||||
" run `{cyan}dvc add large-dir{nc}`".format(
|
||||
purple=colorama.Fore.MAGENTA,
|
||||
cyan=colorama.Fore.CYAN,
|
||||
nc=colorama.Style.RESET_ALL,
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import os
|
||||
|
||||
from dvc.system import System
|
||||
|
||||
|
||||
def test_destroy(repo_dir, dvc_repo):
|
||||
# NOTE: using symlink to ensure that data was unprotected after `destroy`
|
||||
dvc_repo.config.set("cache", "type", "symlink")
|
||||
|
||||
foo_stage, = dvc_repo.add(repo_dir.FOO)
|
||||
data_dir_stage, = dvc_repo.add(repo_dir.DATA_DIR)
|
||||
|
||||
dvc_repo.destroy()
|
||||
|
||||
assert not os.path.exists(dvc_repo.dvc_dir)
|
||||
assert not os.path.exists(foo_stage.path)
|
||||
assert not os.path.exists(data_dir_stage.path)
|
||||
|
||||
assert os.path.isfile(repo_dir.FOO)
|
||||
assert os.path.isdir(repo_dir.DATA_DIR)
|
||||
assert os.path.isfile(repo_dir.DATA)
|
||||
assert os.path.isdir(repo_dir.DATA_SUB_DIR)
|
||||
assert os.path.isfile(repo_dir.DATA_SUB)
|
||||
|
||||
assert not System.is_symlink(repo_dir.FOO)
|
||||
assert not System.is_symlink(repo_dir.DATA_DIR)
|
||||
assert not System.is_symlink(repo_dir.DATA)
|
||||
assert not System.is_symlink(repo_dir.DATA_SUB)
|
||||
+61
-59
@@ -1,71 +1,73 @@
|
||||
from dvc.ignore import DvcIgnore
|
||||
from dvc.main import main
|
||||
import os
|
||||
|
||||
from dvc.scm.git.tree import GitTree
|
||||
from dvc.cache import Cache
|
||||
from dvc.repo import Repo
|
||||
from dvc.scm.git import GitTree
|
||||
from dvc.scm.tree import WorkingTree
|
||||
from dvc.stage import Stage
|
||||
from tests.basic_env import TestDvcGit
|
||||
from dvc.system import System
|
||||
from dvc.utils.compat import fspath
|
||||
|
||||
|
||||
class TestCollect(TestDvcGit):
|
||||
def setUp(self):
|
||||
super(TestCollect, self).setUp()
|
||||
self.dvc.add(self.FOO)
|
||||
self.dvc.run(
|
||||
deps=[self.FOO],
|
||||
outs=[self.BAR],
|
||||
cmd="python code.py {} {}".format(self.FOO, self.BAR),
|
||||
def test_destroy(tmp_dir, dvc):
|
||||
dvc.config.set("cache", "type", "symlink")
|
||||
dvc.cache = Cache(dvc)
|
||||
|
||||
tmp_dir.dvc_gen("file", "text")
|
||||
tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}})
|
||||
|
||||
dvc.destroy()
|
||||
|
||||
# Remove all the files related to DVC
|
||||
for path in [".dvc", "file.dvc", "dir.dvc"]:
|
||||
assert not (tmp_dir / path).exists()
|
||||
|
||||
# Leave the rest of the files
|
||||
for path in ["file", "dir/file", "dir/subdir/file"]:
|
||||
assert (tmp_dir / path).is_file()
|
||||
|
||||
# Make sure that data was unprotected after `destroy`
|
||||
for path in ["file", "dir", "dir/file", "dir/subdir", "dir/subdir/file"]:
|
||||
assert not System.is_symlink(fspath(tmp_dir / path))
|
||||
|
||||
|
||||
def test_collect(tmp_dir, scm, dvc, run_copy):
|
||||
def collect_outs(*args, **kwargs):
|
||||
return set(
|
||||
str(out.path_info)
|
||||
for stage in dvc.collect(*args, **kwargs)
|
||||
for out in stage.outs
|
||||
)
|
||||
self.dvc.scm.add([".gitignore", self.FOO + ".dvc", self.BAR + ".dvc"])
|
||||
self.dvc.scm.commit("foo.dvc and bar.dvc")
|
||||
self.dvc.scm.checkout("new_branch", True)
|
||||
self.dvc.run(
|
||||
deps=[self.BAR],
|
||||
outs=["buzz"],
|
||||
cmd="python code.py {} {}".format(self.BAR, "buzz"),
|
||||
)
|
||||
self.dvc.scm.add([".gitignore", "buzz.dvc"])
|
||||
self.dvc.scm.commit("add buzz")
|
||||
self.dvc.scm.checkout("master")
|
||||
|
||||
def _check(self, branch, target, with_deps, expected):
|
||||
if branch:
|
||||
self.dvc.tree = GitTree(self.dvc.scm.repo, branch)
|
||||
else:
|
||||
self.dvc.tree = WorkingTree()
|
||||
result = self.dvc.collect(target + ".dvc", with_deps=with_deps)
|
||||
self.assertEqual([[str(j) for j in i.outs] for i in result], expected)
|
||||
return result
|
||||
tmp_dir.dvc_gen("foo", "foo")
|
||||
run_copy("foo", "bar")
|
||||
scm.add([".gitignore", "foo.dvc", "bar.dvc"])
|
||||
scm.commit("Add foo and bar")
|
||||
|
||||
def test(self):
|
||||
self._check("", self.BAR, True, [[self.FOO], [self.BAR]])
|
||||
self._check("master", self.BAR, True, [[self.FOO], [self.BAR]])
|
||||
self._check(
|
||||
"new_branch", "buzz", True, [[self.FOO], [self.BAR], ["buzz"]]
|
||||
)
|
||||
result = self._check("new_branch", "buzz", False, [["buzz"]])
|
||||
self.assertEqual([str(i) for i in result[0].deps], ["bar"])
|
||||
scm.checkout("new-branch", create_new=True)
|
||||
|
||||
run_copy("bar", "buzz")
|
||||
scm.add([".gitignore", "buzz.dvc"])
|
||||
scm.commit("Add buzz")
|
||||
|
||||
assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"}
|
||||
|
||||
dvc.tree = GitTree(scm.repo, "new-branch")
|
||||
|
||||
assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"}
|
||||
assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"}
|
||||
|
||||
|
||||
class TestIgnore(TestDvcGit):
|
||||
def _stage_name(self, file):
|
||||
return file + Stage.STAGE_FILE_SUFFIX
|
||||
def test_stages(tmp_dir, dvc):
|
||||
def stages():
|
||||
return set(stage.relpath for stage in Repo(fspath(tmp_dir)).stages)
|
||||
|
||||
def test_should_not_gather_stage_files_from_ignored_dir(self):
|
||||
ret = main(["add", self.FOO, self.BAR, self.DATA, self.DATA_SUB])
|
||||
self.assertEqual(0, ret)
|
||||
tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"})
|
||||
|
||||
stages = self.dvc.stages
|
||||
self.assertEqual(4, len(stages))
|
||||
assert stages() == {
|
||||
"file.dvc",
|
||||
os.path.join("dir", "file.dvc"),
|
||||
os.path.join("dir", "subdir", "file.dvc"),
|
||||
}
|
||||
|
||||
self.create(DvcIgnore.DVCIGNORE_FILE, self.DATA_DIR)
|
||||
tmp_dir.gen(".dvcignore", "dir")
|
||||
|
||||
self.dvc = Repo(self.dvc.root_dir)
|
||||
stages = self.dvc.stages
|
||||
self.assertEqual(2, len(stages))
|
||||
|
||||
stagenames = [s.relpath for s in stages]
|
||||
self.assertIn(self._stage_name(self.FOO), stagenames)
|
||||
self.assertIn(self._stage_name(self.BAR), stagenames)
|
||||
self.assertNotIn(self._stage_name(self.DATA), stagenames)
|
||||
self.assertNotIn(self._stage_name(self.DATA_SUB), stagenames)
|
||||
assert stages() == {"file.dvc"}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import os
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from dvc.updater import Updater
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def updater(dvc_repo):
|
||||
return Updater(dvc_repo.dvc_dir)
|
||||
|
||||
|
||||
def test_updater(updater):
|
||||
# NOTE: only test on travis CRON to avoid generating too much logs
|
||||
travis = os.getenv("TRAVIS") == "true"
|
||||
if not travis:
|
||||
return
|
||||
|
||||
cron = os.getenv("TRAVIS_EVENT_TYPE") == "cron"
|
||||
if not cron:
|
||||
return
|
||||
|
||||
env = os.environ.copy()
|
||||
if env.get("CI"):
|
||||
del env["CI"]
|
||||
|
||||
with mock.patch.dict(os.environ, env):
|
||||
updater.check()
|
||||
updater.check()
|
||||
updater.check()
|
||||
|
||||
|
||||
def test_check_version_newer(updater):
|
||||
updater.latest = "0.20.8"
|
||||
updater.current = "0.21.0"
|
||||
|
||||
assert not updater._is_outdated()
|
||||
|
||||
|
||||
def test_check_version_equal(updater):
|
||||
updater.latest = "0.20.8"
|
||||
updater.current = "0.20.8"
|
||||
|
||||
assert not updater._is_outdated()
|
||||
|
||||
|
||||
def test_check_version_outdated(updater):
|
||||
updater.latest = "0.21.0"
|
||||
updater.current = "0.20.8"
|
||||
|
||||
assert updater._is_outdated()
|
||||
+3
-10
@@ -1,13 +1,6 @@
|
||||
import os
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
class TestIsDvcInternal(TestDvc):
|
||||
def test_return_false_on_non_dvc_file(self):
|
||||
path = os.path.join("path", "to-non-.dvc", "file")
|
||||
self.assertFalse(self.dvc.is_dvc_internal(path))
|
||||
|
||||
def test_return_true_on_dvc_internal_file(self):
|
||||
path = os.path.join("path", "to", ".dvc", "file")
|
||||
self.assertTrue(path)
|
||||
def test_is_dvc_internal(dvc):
|
||||
assert dvc.is_dvc_internal(os.path.join("path", "to", ".dvc", "file"))
|
||||
assert not dvc.is_dvc_internal(os.path.join("path", "to-non-.dvc", "file"))
|
||||
|
||||
+43
-22
@@ -1,40 +1,61 @@
|
||||
import json
|
||||
import os
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from dvc import __version__
|
||||
from dvc.updater import Updater
|
||||
|
||||
|
||||
class MockResponse(object):
|
||||
def __init__(self, json_data, status_code):
|
||||
self.json_data = json_data
|
||||
self.status_code = status_code
|
||||
|
||||
def json(self):
|
||||
return self.json_data
|
||||
@pytest.fixture
|
||||
def updater(dvc):
|
||||
return Updater(dvc.dvc_dir)
|
||||
|
||||
|
||||
def mocked_requests_get(*args, **kwargs):
|
||||
class MockResponse:
|
||||
def __init__(self, json_data, status_code):
|
||||
self.json_data = json_data
|
||||
self.status_code = status_code
|
||||
@mock.patch("requests.get")
|
||||
def test_fetch(mock_get, updater):
|
||||
mock_get.return_value.status_code = 200
|
||||
mock_get.return_value.json.return_value = {"version": __version__}
|
||||
|
||||
def json(self):
|
||||
return self.json_data
|
||||
|
||||
return MockResponse({"version": __version__}, 200)
|
||||
|
||||
|
||||
def test_fetch(dvc_repo, mocker):
|
||||
updater = Updater(dvc_repo.dvc_dir)
|
||||
assert not os.path.exists(updater.updater_file)
|
||||
|
||||
mock_get = mocker.patch("requests.get", side_effect=mocked_requests_get)
|
||||
updater.fetch(detach=False)
|
||||
mock_get.assert_called_once_with(Updater.URL, timeout=Updater.TIMEOUT_GET)
|
||||
|
||||
mock_get.assert_called_once_with(Updater.URL, timeout=Updater.TIMEOUT_GET)
|
||||
assert os.path.isfile(updater.updater_file)
|
||||
|
||||
with open(updater.updater_file, "r") as fobj:
|
||||
info = json.load(fobj)
|
||||
|
||||
assert info["version"] == __version__
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"latest, current, result",
|
||||
[
|
||||
("0.20.8", "0.21.0", False),
|
||||
("0.20.8", "0.20.8", False),
|
||||
("0.20.8", "0.19.0", True),
|
||||
],
|
||||
)
|
||||
def test_is_outdated(latest, current, result, updater):
|
||||
updater.latest = latest
|
||||
updater.current = current
|
||||
|
||||
assert updater._is_outdated() == result
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.getenv("TRAVIS_EVENT_TYPE") != "cron",
|
||||
reason="Only run on travis CRON to avoid generating too much logs",
|
||||
)
|
||||
@mock.patch("dvc.updater.Updater._check")
|
||||
def test_check(mock_check, updater, monkeypatch):
|
||||
monkeypatch.delenv("CI", None)
|
||||
monkeypatch.setenv("DVC_TEST", False)
|
||||
|
||||
updater.check()
|
||||
updater.check()
|
||||
updater.check()
|
||||
|
||||
assert mock_check.call_count == 3
|
||||
|
||||
Reference in New Issue
Block a user