mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
analytics: add DVC_ANALYTICS env var (#6448)
This commit is contained in:
+8
-3
@@ -2,6 +2,8 @@ import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
from .env import DVC_ANALYTICS
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -42,9 +44,12 @@ def is_enabled():
|
||||
if env2bool("DVC_TEST"):
|
||||
return False
|
||||
|
||||
enabled = to_bool(
|
||||
Config(validate=False).get("core", {}).get("analytics", "true")
|
||||
)
|
||||
enabled = env2bool(DVC_ANALYTICS, None)
|
||||
if enabled is None:
|
||||
enabled = to_bool(
|
||||
Config(validate=False).get("core", {}).get("analytics", "true")
|
||||
)
|
||||
|
||||
logger.debug("Analytics is {}abled.".format("en" if enabled else "dis"))
|
||||
|
||||
return enabled
|
||||
|
||||
@@ -9,3 +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"
|
||||
|
||||
@@ -87,6 +87,40 @@ 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)
|
||||
|
||||
assert result == analytics.is_enabled()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config, env, result",
|
||||
[
|
||||
(None, None, True),
|
||||
(None, "true", True),
|
||||
(None, "false", False),
|
||||
("false", None, False),
|
||||
("false", "true", True),
|
||||
("false", "false", False),
|
||||
("true", None, True),
|
||||
("true", "true", True),
|
||||
("true", "false", False),
|
||||
],
|
||||
)
|
||||
def test_is_enabled_env(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)
|
||||
with dvc.config.edit() as conf:
|
||||
conf["core"] = {}
|
||||
|
||||
assert analytics.is_enabled()
|
||||
|
||||
if config is not None:
|
||||
with dvc.config.edit() as conf:
|
||||
conf["core"] = {"analytics": config}
|
||||
|
||||
if env is not None:
|
||||
monkeypatch.setenv("DVC_ANALYTICS", env)
|
||||
|
||||
assert result == analytics.is_enabled()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user