analytics: introduce DVC_NO_ANALYTICS (#6453)

Replacing DVC_ANALYTICS. This is following our other env conventions and
will not have effect if set to false/no/etc, and will only work if set
to true/yes/y/etc. Will disable analytics even if it is explicitly
enabled in our configs.

Kudos @skshetry
This commit is contained in:
Ruslan Kuprieiev
2021-08-17 15:16:40 +03:00
committed by GitHub
parent 14cc748139
commit 33c6a9b19b
3 changed files with 16 additions and 13 deletions
+3 -3
View File
@@ -2,7 +2,7 @@ import json
import logging
import os
from .env import DVC_ANALYTICS
from .env import DVC_NO_ANALYTICS
logger = logging.getLogger(__name__)
@@ -44,8 +44,8 @@ def is_enabled():
if env2bool("DVC_TEST"):
return False
enabled = env2bool(DVC_ANALYTICS, None)
if enabled is None:
enabled = not os.getenv(DVC_NO_ANALYTICS)
if enabled:
enabled = to_bool(
Config(validate=False).get("core", {}).get("analytics", "true")
)
+1 -1
View File
@@ -9,4 +9,4 @@ DVCLIVE_RESUME = "DVCLIVE_RESUME"
DVC_IGNORE_ISATTY = "DVC_IGNORE_ISATTY"
DVC_EXP_GIT_REMOTE = "DVC_EXP_GIT_REMOTE"
DVC_EXP_AUTO_PUSH = "DVC_EXP_AUTO_PUSH"
DVC_ANALYTICS = "DVC_ANALYTICS"
DVC_NO_ANALYTICS = "DVC_NO_ANALYTICS"
+12 -9
View File
@@ -87,7 +87,7 @@ def test_is_enabled(dvc, config, result, monkeypatch, tmp_global_dir):
# reset DVC_TEST env var, which affects `is_enabled()`
monkeypatch.delenv("DVC_TEST")
monkeypatch.delenv("DVC_ANALYTICS", raising=False)
monkeypatch.delenv("DVC_NO_ANALYTICS", raising=False)
assert result == analytics.is_enabled()
@@ -96,20 +96,23 @@ def test_is_enabled(dvc, config, result, monkeypatch, tmp_global_dir):
"config, env, result",
[
(None, None, True),
(None, "true", True),
(None, "false", False),
(None, "true", False),
(None, "false", False), # only checking if env is set
("false", None, False),
("false", "true", True),
("false", "true", False),
("false", "false", False),
("true", None, True),
("true", "true", True),
("true", "false", False),
("true", "true", False),
("true", "false", False), # we checking if env is set
],
)
def test_is_enabled_env(dvc, config, env, result, monkeypatch, tmp_global_dir):
def test_is_enabled_env_neg(
dvc, config, env, result, monkeypatch, tmp_global_dir
):
# reset DVC_TEST env var, which affects `is_enabled()`
monkeypatch.delenv("DVC_TEST")
monkeypatch.delenv("DVC_ANALYTICS", raising=False)
monkeypatch.delenv("DVC_NO_ANALYTICS", raising=False)
with dvc.config.edit() as conf:
conf["core"] = {}
@@ -120,7 +123,7 @@ def test_is_enabled_env(dvc, config, env, result, monkeypatch, tmp_global_dir):
conf["core"] = {"analytics": config}
if env is not None:
monkeypatch.setenv("DVC_ANALYTICS", env)
monkeypatch.setenv("DVC_NO_ANALYTICS", env)
assert result == analytics.is_enabled()