From 8a5dc6a781b6eaa26c8598fcf4511b53a66cbb35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Rowlands=20=28=EB=B3=80=EA=B8=B0=ED=98=B8=29?= Date: Thu, 22 Oct 2020 12:49:48 +0900 Subject: [PATCH] init: move welcome message from `Repo.init` to `command.init` (#4759) * repo: add quiet flag for Repo.init * move welcome message to command/init --- dvc/command/init.py | 28 ++++++++++++++++++++++++++++ dvc/repo/init.py | 29 ----------------------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/dvc/command/init.py b/dvc/command/init.py index 8f5e881fc..6470554a1 100644 --- a/dvc/command/init.py +++ b/dvc/command/init.py @@ -1,11 +1,38 @@ import argparse import logging +import colorama + +from dvc import analytics from dvc.command.base import CmdBaseNoRepo, append_doc_link +from dvc.utils import boxify +from dvc.utils import format_link as fmt_link logger = logging.getLogger(__name__) +def _welcome_message(): + 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" + + fmt_link("https://dvc.org/doc/user-guide/analytics"), + border_color="red", + ) + ) + + msg = ( + "{yellow}What's next?{nc}\n" + "{yellow}------------{nc}\n" + f"- Check out the documentation: {fmt_link('https://dvc.org/doc')}\n" + f"- Get help and share ideas: {fmt_link('https://dvc.org/chat')}\n" + f"- Star us on GitHub: {fmt_link('https://github.com/iterative/dvc')}" + ).format(yellow=colorama.Fore.YELLOW, nc=colorama.Fore.RESET) + + logger.info(msg) + + class CmdInit(CmdBaseNoRepo): def run(self): from dvc.exceptions import InitError @@ -19,6 +46,7 @@ class CmdInit(CmdBaseNoRepo): subdir=self.args.subdir, ) self.config = self.repo.config + _welcome_message() except InitError: logger.exception("failed to initiate DVC") return 1 diff --git a/dvc/repo/init.py b/dvc/repo/init.py index ecce3e4a8..2712b2279 100644 --- a/dvc/repo/init.py +++ b/dvc/repo/init.py @@ -1,45 +1,18 @@ import logging import os -import colorama - -from dvc import analytics from dvc.config import Config from dvc.exceptions import InitError, InvalidArgumentError from dvc.ignore import init as init_dvcignore from dvc.repo import Repo from dvc.scm import SCM from dvc.scm.base import SCMError -from dvc.utils import boxify -from dvc.utils import format_link as fmt_link from dvc.utils import relpath from dvc.utils.fs import remove logger = logging.getLogger(__name__) -def _welcome_message(): - 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" - + fmt_link("https://dvc.org/doc/user-guide/analytics"), - border_color="red", - ) - ) - - msg = ( - "{yellow}What's next?{nc}\n" - "{yellow}------------{nc}\n" - f"- Check out the documentation: {fmt_link('https://dvc.org/doc')}\n" - f"- Get help and share ideas: {fmt_link('https://dvc.org/chat')}\n" - f"- Star us on GitHub: {fmt_link('https://github.com/iterative/dvc')}" - ).format(yellow=colorama.Fore.YELLOW, nc=colorama.Fore.RESET) - - logger.info(msg) - - def init(root_dir=os.curdir, no_scm=False, force=False, subdir=False): """ Creates an empty repo on the given directory -- basically a @@ -110,6 +83,4 @@ def init(root_dir=os.curdir, no_scm=False, force=False, subdir=False): scm.add([os.path.join(dvc_dir, scm.ignore_file)]) logger.info("\nYou can now commit the changes to git.\n") - _welcome_message() - return proj