From 9c09075756279dbe43fa9969a6fd1a915c28423a Mon Sep 17 00:00:00 2001 From: Puneetha Pai Date: Tue, 4 Aug 2020 19:10:02 +0530 Subject: [PATCH 1/2] Updater: Add method to check dvc core config check_update --- dvc/config.py | 1 + dvc/updater.py | 10 ++++++++++ tests/unit/test_updater.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/dvc/config.py b/dvc/config.py index 26181e4d67..c88e6b2f2c 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -138,6 +138,7 @@ class RelPath(str): Optional("hardlink_lock", default=False): Bool, Optional("no_scm", default=False): Bool, Optional("experiments", default=False): Bool, + Optional("check_update", default=True): Bool, }, "cache": { "local": str, diff --git a/dvc/updater.py b/dvc/updater.py index b2fb79b6a2..667ec90ff9 100644 --- a/dvc/updater.py +++ b/dvc/updater.py @@ -7,6 +7,7 @@ from packaging import version from dvc import __version__ +from dvc.config import Config, to_bool from dvc.lock import LockError, make_lock from dvc.utils import boxify, env2bool from dvc.utils.pkg import PKG @@ -144,3 +145,12 @@ def _get_update_instructions(self): package_manager = "binary" return instructions[package_manager] + + def is_enabled(self): + enabled = to_bool( + Config(validate=False).get("core", {}).get("check_update", "true") + ) + logger.debug( + "Check for update is {}abled.".format("en" if enabled else "dis") + ) + return enabled diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index 76257af668..2b27e3e733 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -44,6 +44,20 @@ def test_fetch(mock_get, updater): assert info["version"] == __version__ +@pytest.mark.parametrize( + "core, result", + [ + ({}, True), + ({"check_update": "true"}, True), + ({"check_update": "false"}, False), + ], +) +def test_is_enabled(dvc, updater, core, result): + with dvc.config.edit("local") as conf: + conf["core"] = core + assert result == updater.is_enabled() + + @pytest.mark.parametrize( "current,latest,notify", [ From 755e757887106e6509859ea450beb2838a3e1680 Mon Sep 17 00:00:00 2001 From: Puneetha Pai Date: Tue, 4 Aug 2020 20:14:16 +0530 Subject: [PATCH 2/2] Updater: check config before calling update._check Fixes #1894 --- dvc/updater.py | 7 ++++++- tests/unit/test_updater.py | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dvc/updater.py b/dvc/updater.py index 667ec90ff9..92ef1bb889 100644 --- a/dvc/updater.py +++ b/dvc/updater.py @@ -47,7 +47,12 @@ def _with_lock(self, func, action): logger.debug(msg.format(self.lock.lockfile, action)) def check(self): - if os.getenv("CI") or env2bool("DVC_TEST") or PKG == "snap": + if ( + os.getenv("CI") + or env2bool("DVC_TEST") + or PKG == "snap" + or not self.is_enabled() + ): return self._with_lock(self._check, "checking") diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index 2b27e3e733..076229e29d 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -58,6 +58,14 @@ def test_is_enabled(dvc, updater, core, result): assert result == updater.is_enabled() +@pytest.mark.parametrize("result", [True, False]) +@mock.patch("dvc.updater.Updater._check") +def test_check_update_respect_config(mock_check, result, updater, mocker): + mocker.patch.object(updater, "is_enabled", return_value=result) + updater.check() + assert result == mock_check.called + + @pytest.mark.parametrize( "current,latest,notify", [