Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config to enable/disable updater #4334

Merged
merged 2 commits into from Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dvc/config.py
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
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
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