Repository: iterative/dvc
Pull request: disable analytics warning message on init if disabled globally/system…
…-wide

Fixes #2267 by only printing an analytics warning message on `dvc init` if
`dvc.analytics.Analytics._is_enabled()` returns `True`.
Maybe a message that analytics is disabled should be printed too.


Problem statement:
`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`

Hints from issue discussion:

Commit message: disable analytics warning message on init if disabled globally/system-wide

Patch to review:
diff --git a/dvc/repo/init.py b/dvc/repo/init.py
index 6fefbad8f3..1233cba68f 100644
--- 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"


Code review comments:
diff_hunk: @@ -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():
path: dvc/repo/init.py
text: @user1:
Let's rename `_is_enabled` into `is_enabled`, so we don't use a protected method here.

@author:
changed as requested