From a9ccf70439d5f11b0c27b50e37f2c59dc3337fa5 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Thu, 7 Jan 2021 11:45:58 +0545 Subject: [PATCH] cmd: imports lazy (#5226) They are not a major pain point though --- dvc/command/check_ignore.py | 3 ++- dvc/command/checkout.py | 3 ++- dvc/command/commit.py | 3 ++- dvc/command/data_sync.py | 13 ++++++++++--- dvc/command/destroy.py | 3 ++- dvc/command/diff.py | 3 ++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dvc/command/check_ignore.py b/dvc/command/check_ignore.py index 61c55859b..e1a1bf5ac 100644 --- a/dvc/command/check_ignore.py +++ b/dvc/command/check_ignore.py @@ -3,7 +3,6 @@ import logging from dvc.command import completion from dvc.command.base import CmdBase, append_doc_link -from dvc.exceptions import DvcException logger = logging.getLogger(__name__) @@ -55,6 +54,8 @@ class CmdCheckIgnore(CmdBase): return ret def _check_args(self): + from dvc.exceptions import DvcException + if not self.args.stdin and not self.args.targets: raise DvcException("`targets` or `--stdin` needed") diff --git a/dvc/command/checkout.py b/dvc/command/checkout.py index 3752342e1..858358df8 100644 --- a/dvc/command/checkout.py +++ b/dvc/command/checkout.py @@ -7,7 +7,6 @@ import colorama from dvc.command import completion from dvc.command.base import CmdBase, append_doc_link from dvc.exceptions import CheckoutError -from dvc.utils.humanize import get_summary logger = logging.getLogger(__name__) @@ -39,6 +38,8 @@ def log_changes(stats): class CmdCheckout(CmdBase): def run(self): + from dvc.utils.humanize import get_summary + stats, exc = None, None try: stats = self.repo.checkout( diff --git a/dvc/command/commit.py b/dvc/command/commit.py index 32012e10e..c665aa4a9 100644 --- a/dvc/command/commit.py +++ b/dvc/command/commit.py @@ -3,13 +3,14 @@ import logging from dvc.command import completion from dvc.command.base import CmdBase, append_doc_link -from dvc.exceptions import DvcException logger = logging.getLogger(__name__) class CmdCommit(CmdBase): def run(self): + from dvc.exceptions import DvcException + if not self.args.targets: self.args.targets = [None] diff --git a/dvc/command/data_sync.py b/dvc/command/data_sync.py index 8ce2e65cd..5bbfdf4dc 100644 --- a/dvc/command/data_sync.py +++ b/dvc/command/data_sync.py @@ -3,25 +3,28 @@ import logging from dvc.command import completion from dvc.command.base import CmdBase, append_doc_link -from dvc.command.checkout import log_changes -from dvc.exceptions import CheckoutError, DvcException -from dvc.utils.humanize import get_summary logger = logging.getLogger(__name__) class CmdDataBase(CmdBase): def log_summary(self, stats): + from dvc.utils.humanize import get_summary + default_msg = "Everything is up to date." logger.info(get_summary(stats.items()) or default_msg) class CmdDataPull(CmdDataBase): def log_summary(self, stats): + from dvc.command.checkout import log_changes + log_changes(stats) super().log_summary(stats) def run(self): + from dvc.exceptions import CheckoutError, DvcException + try: stats = self.repo.pull( targets=self.args.targets, @@ -46,6 +49,8 @@ class CmdDataPull(CmdDataBase): class CmdDataPush(CmdDataBase): def run(self): + from dvc.exceptions import DvcException + try: processed_files_count = self.repo.push( targets=self.args.targets, @@ -68,6 +73,8 @@ class CmdDataPush(CmdDataBase): class CmdDataFetch(CmdDataBase): def run(self): + from dvc.exceptions import DvcException + try: processed_files_count = self.repo.fetch( targets=self.args.targets, diff --git a/dvc/command/destroy.py b/dvc/command/destroy.py index 5f9dee6bd..06f82bb5d 100644 --- a/dvc/command/destroy.py +++ b/dvc/command/destroy.py @@ -3,13 +3,14 @@ import logging import dvc.prompt as prompt from dvc.command.base import CmdBase, append_doc_link -from dvc.exceptions import DvcException logger = logging.getLogger(__name__) class CmdDestroy(CmdBase): def run(self): + from dvc.exceptions import DvcException + try: statement = ( "This will destroy all information about your pipelines," diff --git a/dvc/command/diff.py b/dvc/command/diff.py index 68e2c8c8d..608db8182 100644 --- a/dvc/command/diff.py +++ b/dvc/command/diff.py @@ -7,7 +7,6 @@ import colorama from dvc.command import completion from dvc.command.base import CmdBase, append_doc_link -from dvc.exceptions import DvcException logger = logging.getLogger(__name__) @@ -127,6 +126,8 @@ class CmdDiff(CmdBase): return "\n\n".join(groups) def run(self): + from dvc.exceptions import DvcException + try: diff = self.repo.diff( self.args.a_rev, self.args.b_rev, self.args.targets