Repository: iterative/dvc

Issue:
`dvc init` prints analytics warning even if has been disabled
**When** a new repository is initialized and the `core.analytics` has been set to `False` either globally or system-wide
**Then** a the analytics warning message is still printed
**Causing** a bit of irritation and actually checking the code what's really going on 

Seems like the `_welcome_message` function in `dvc/repo/init.py` has no check if analytics is still enabled.

---
**DVC version**: 0.51.2
**Method of installation**: `pip`




Discussion:

Resolving patch:
diff --git a/dvc/analytics.py b/dvc/analytics.py
--- a/dvc/analytics.py
+++ b/dvc/analytics.py
@@ -213,10 +213,20 @@ def _is_enabled_config(config):
         return core.get(Config.SECTION_CORE_ANALYTICS, True)
 
     @staticmethod
-    def _is_enabled(cmd=None):
+    def _get_current_config():
         from dvc.config import Config
         from dvc.repo import Repo
         from dvc.exceptions import NotDvcRepoError
+
+        try:
+            dvc_dir = Repo.find_dvc_dir()
+            config = Config(dvc_dir)
+        except NotDvcRepoError:
+            config = Config(validate=False)
+        return config
+
+    @staticmethod
+    def is_enabled(cmd=None):
         from dvc.command.daemon import CmdDaemonBase
 
         if os.getenv("DVC_TEST"):
@@ -225,17 +235,13 @@ def _is_enabled(cmd=None):
         if isinstance(cmd, CmdDaemonBase):
             return False
 
-        if cmd is None or not hasattr(cmd, "config"):
-            try:
-                dvc_dir = Repo.find_dvc_dir()
-                config = Config(dvc_dir)
-                assert config is not None
-            except NotDvcRepoError:
-                config = Config(validate=False)
-                assert config is not None
-        else:
-            config = cmd.config
-            assert config is not None
+        config = (
+            Analytics._get_current_config()
+            if cmd is None or not hasattr(cmd, "config")
+            else cmd.config
+        )
+
+        assert config is not None
 
         enabled = Analytics._is_enabled_config(config)
         logger.debug(
@@ -253,7 +259,7 @@ def send_cmd(cmd, args, ret):
         """
         from dvc.daemon import daemon
 
-        if not Analytics._is_enabled(cmd):
+        if not Analytics.is_enabled(cmd):
             return
 
         analytics = Analytics()
@@ -264,7 +270,7 @@ def send(self):
         """Collect and send analytics."""
         import requests
 
-        if not self._is_enabled():
+        if not self.is_enabled():
             return
 
         self.collect()
diff --git a/dvc/repo/init.py b/dvc/repo/init.py
--- a/dvc/repo/init.py
+++ b/dvc/repo/init.py
@@ -7,21 +7,23 @@
 from dvc.config import Config
 from dvc.exceptions import InitError
 from dvc.utils import boxify, relpath, remove
+from dvc.analytics import Analytics
 
 logger = logging.getLogger(__name__)
 
 
 def _welcome_message():
-    logger.info(
-        boxify(
-            "DVC has enabled anonymous aggregate usage analytics.\n"
-            "Read the analytics documentation (and how to opt-out) here:\n"
-            "{blue}https://dvc.org/doc/user-guide/analytics{nc}".format(
-                blue=colorama.Fore.BLUE, nc=colorama.Fore.RESET
-            ),
-            border_color="red",
+    if Analytics.is_enabled():
+        logger.info(
+            boxify(
+                "DVC has enabled anonymous aggregate usage analytics.\n"
+                "Read the analytics documentation (and how to opt-out) here:\n"
+                "{blue}https://dvc.org/doc/user-guide/analytics{nc}".format(
+                    blue=colorama.Fore.BLUE, nc=colorama.Fore.RESET
+                ),
+                border_color="red",
+            )
         )
-    )
 
     msg = (
         "{yellow}What's next?{nc}\n"


Test patch: