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

analytics: introduce DVC_NO_ANALYTICS #6453

Merged
merged 1 commit into from
Aug 17, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dvc/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os

from .env import DVC_ANALYTICS
from .env import DVC_NO_ANALYTICS

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -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")
)
Expand Down
2 changes: 1 addition & 1 deletion dvc/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
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"
21 changes: 12 additions & 9 deletions tests/unit/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"] = {}

Expand All @@ -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()

Expand Down