mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Config to enable/disable updater (#4334)
* Updater: Add method to check dvc core config check_update * Updater: check config before calling update._check Fixes #1894
This commit is contained in:
@@ -138,6 +138,7 @@ SCHEMA = {
|
||||
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,
|
||||
|
||||
+16
-1
@@ -7,6 +7,7 @@ import colorama
|
||||
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 @@ class Updater: # pragma: no cover
|
||||
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 @@ class Updater: # pragma: no cover
|
||||
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
|
||||
|
||||
@@ -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",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user