mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
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:
+3
-3
@@ -2,7 +2,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .env import DVC_ANALYTICS
|
from .env import DVC_NO_ANALYTICS
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ def is_enabled():
|
|||||||
if env2bool("DVC_TEST"):
|
if env2bool("DVC_TEST"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
enabled = env2bool(DVC_ANALYTICS, None)
|
enabled = not os.getenv(DVC_NO_ANALYTICS)
|
||||||
if enabled is None:
|
if enabled:
|
||||||
enabled = to_bool(
|
enabled = to_bool(
|
||||||
Config(validate=False).get("core", {}).get("analytics", "true")
|
Config(validate=False).get("core", {}).get("analytics", "true")
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -9,4 +9,4 @@ DVCLIVE_RESUME = "DVCLIVE_RESUME"
|
|||||||
DVC_IGNORE_ISATTY = "DVC_IGNORE_ISATTY"
|
DVC_IGNORE_ISATTY = "DVC_IGNORE_ISATTY"
|
||||||
DVC_EXP_GIT_REMOTE = "DVC_EXP_GIT_REMOTE"
|
DVC_EXP_GIT_REMOTE = "DVC_EXP_GIT_REMOTE"
|
||||||
DVC_EXP_AUTO_PUSH = "DVC_EXP_AUTO_PUSH"
|
DVC_EXP_AUTO_PUSH = "DVC_EXP_AUTO_PUSH"
|
||||||
DVC_ANALYTICS = "DVC_ANALYTICS"
|
DVC_NO_ANALYTICS = "DVC_NO_ANALYTICS"
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ def test_is_enabled(dvc, config, result, monkeypatch, tmp_global_dir):
|
|||||||
|
|
||||||
# reset DVC_TEST env var, which affects `is_enabled()`
|
# reset DVC_TEST env var, which affects `is_enabled()`
|
||||||
monkeypatch.delenv("DVC_TEST")
|
monkeypatch.delenv("DVC_TEST")
|
||||||
monkeypatch.delenv("DVC_ANALYTICS", raising=False)
|
monkeypatch.delenv("DVC_NO_ANALYTICS", raising=False)
|
||||||
|
|
||||||
assert result == analytics.is_enabled()
|
assert result == analytics.is_enabled()
|
||||||
|
|
||||||
@@ -96,20 +96,23 @@ def test_is_enabled(dvc, config, result, monkeypatch, tmp_global_dir):
|
|||||||
"config, env, result",
|
"config, env, result",
|
||||||
[
|
[
|
||||||
(None, None, True),
|
(None, None, True),
|
||||||
(None, "true", True),
|
(None, "true", False),
|
||||||
(None, "false", False),
|
(None, "false", False), # only checking if env is set
|
||||||
("false", None, False),
|
("false", None, False),
|
||||||
("false", "true", True),
|
("false", "true", False),
|
||||||
("false", "false", False),
|
("false", "false", False),
|
||||||
("true", None, True),
|
("true", None, True),
|
||||||
("true", "true", True),
|
("true", "true", False),
|
||||||
("true", "false", 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()`
|
# reset DVC_TEST env var, which affects `is_enabled()`
|
||||||
monkeypatch.delenv("DVC_TEST")
|
monkeypatch.delenv("DVC_TEST")
|
||||||
monkeypatch.delenv("DVC_ANALYTICS", raising=False)
|
monkeypatch.delenv("DVC_NO_ANALYTICS", raising=False)
|
||||||
|
|
||||||
with dvc.config.edit() as conf:
|
with dvc.config.edit() as conf:
|
||||||
conf["core"] = {}
|
conf["core"] = {}
|
||||||
|
|
||||||
@@ -120,7 +123,7 @@ def test_is_enabled_env(dvc, config, env, result, monkeypatch, tmp_global_dir):
|
|||||||
conf["core"] = {"analytics": config}
|
conf["core"] = {"analytics": config}
|
||||||
|
|
||||||
if env is not None:
|
if env is not None:
|
||||||
monkeypatch.setenv("DVC_ANALYTICS", env)
|
monkeypatch.setenv("DVC_NO_ANALYTICS", env)
|
||||||
|
|
||||||
assert result == analytics.is_enabled()
|
assert result == analytics.is_enabled()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user