Skip to content

Commit

Permalink
Config to enable/disable updater (#4334)
Browse files Browse the repository at this point in the history
* Updater: Add method to check dvc core config check_update

* Updater: check config before calling update._check

Fixes #1894
  • Loading branch information
PuneethaPai authored Aug 10, 2020
1 parent 4e5a814 commit 172032d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion dvc/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
22 changes: 22 additions & 0 deletions tests/unit/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit 172032d

Please sign in to comment.