diff --git a/dvc/config.py b/dvc/config.py index 6aa5908e59..e370489d66 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..92ef1bb889 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 @@ -46,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") @@ -144,3 +150,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..076229e29d 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -44,6 +44,28 @@ 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("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", [