Skip to content
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
4 changes: 4 additions & 0 deletions dvc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

from dvc.version import __version__ # noqa: F401
import warnings
import dvc.logger


dvc.logger.setup()

# Ignore numpy's runtime warnings: https://github.com/numpy/numpy/pull/432.
# We don't directly import numpy, but our dependency networkx does, causing
Expand Down
5 changes: 4 additions & 1 deletion dvc/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import os
import json
import errno
import logging

import dvc.logger as logger
from dvc import __version__


logger = logging.getLogger(__name__)


class Analytics(object):
"""Class for collecting and sending usage analytics.

Expand Down
4 changes: 3 additions & 1 deletion dvc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import sys
import argparse
import logging

import dvc.logger as logger
from dvc.command.base import fix_subparsers
import dvc.command.init as init
import dvc.command.pkg as pkg
Expand Down Expand Up @@ -36,6 +36,8 @@
from dvc.exceptions import DvcParserError


logger = logging.getLogger(__name__)

COMMANDS = [
init,
pkg,
Expand Down
7 changes: 5 additions & 2 deletions dvc/command/add.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import unicode_literals

import argparse
import logging

import dvc.logger as logger
from dvc.exceptions import DvcException
from dvc.command.base import CmdBase, append_doc_link


logger = logging.getLogger(__name__)


class CmdAdd(CmdBase):
def run(self):
try:
Expand All @@ -22,7 +25,7 @@ def run(self):
)

except DvcException:
logger.error("failed to add file")
logger.exception("failed to add file")
return 1
return 0

Expand Down
16 changes: 4 additions & 12 deletions dvc/command/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import unicode_literals

import colorama
import logging

import dvc.logger as logger

logger = logging.getLogger(__name__)


def fix_subparsers(subparsers):
Expand Down Expand Up @@ -40,7 +42,6 @@ def __init__(self, args):
self.repo = Repo()
self.config = self.repo.config
self.args = args
self.set_loglevel(args)

@property
def default_targets(self):
Expand All @@ -51,23 +52,14 @@ def default_targets(self):
logger.warning(msg)
return [Stage.STAGE_FILE]

@staticmethod
def set_loglevel(args):
"""Sets log level from CLI arguments."""
if args.quiet:
logger.be_quiet()

elif args.verbose:
logger.be_verbose()

def run_cmd(self):
from dvc.lock import LockError

try:
with self.repo.lock:
return self.run()
except LockError:
logger.error("failed to lock before running a command")
logger.exception("failed to lock before running a command")
return 1

# Abstract methods that have to be implemented by any inheritance class
Expand Down
7 changes: 5 additions & 2 deletions dvc/command/commit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import unicode_literals

import argparse
import logging

import dvc.logger as logger
from dvc.exceptions import DvcException
from dvc.command.base import CmdBase, append_doc_link


logger = logging.getLogger(__name__)


class CmdCommit(CmdBase):
def run(self):
if not self.args.targets:
Expand All @@ -21,7 +24,7 @@ def run(self):
force=self.args.force,
)
except DvcException:
logger.error(
logger.exception(
"failed to commit{}".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string formatting routines shouldn't be used in the logger method invocations. This should be rewritten with:

"failed to commit%s", (" " + target) if target else ""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally, @ei-grad ; I delayed this change because the whole code base is currently using the brace style: "hello {}".format("world"), sadly, on 2.7 the logger doesn't support braces, but it does on 3.x maybe we should wait a little bit to embrace this change.

(" " + target) if target else ""
)
Expand Down
11 changes: 7 additions & 4 deletions dvc/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import os
import argparse
import logging

import dvc.logger as logger
from dvc.command.base import CmdBase, append_doc_link
from dvc.config import Config
from dvc.exceptions import DvcException


logger = logging.getLogger(__name__)


class CmdConfig(CmdBase):
def __init__(self, args):
from dvc.repo import Repo, NotDvcRepoError
Expand Down Expand Up @@ -47,15 +50,15 @@ def _unset(self, section, opt=None, configobj=None):
self.config.unset(configobj, section, opt)
self.config.save(configobj)
except DvcException:
logger.error("failed to unset '{}'".format(self.args.name))
logger.exception("failed to unset '{}'".format(self.args.name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.exception("failed to unset '{}'".format(self.args.name))
logger.exception("failed to unset %r", self.args.name)

return 1
return 0

def _show(self, section, opt):
try:
self.config.show(self.configobj, section, opt)
except DvcException:
logger.error("failed to show '{}'".format(self.args.name))
logger.exception("failed to show '{}'".format(self.args.name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.exception("failed to show '{}'".format(self.args.name))
logger.exception("failed to show %r", self.args.name)

return 1
return 0

Expand All @@ -64,7 +67,7 @@ def _set(self, section, opt, value):
self.config.set(self.configobj, section, opt, value)
self.config.save(self.configobj)
except DvcException:
logger.error(
logger.exception(
"failed to set '{}.{}' to '{}'".format(section, opt, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"failed to set '{}.{}' to '{}'".format(section, opt, value)
"failed to set '%s.%s' to %r", section, opt, value,

)
return 1
Expand Down
1 change: 0 additions & 1 deletion dvc/command/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class CmdDaemonBase(CmdBase):
def __init__(self, args):
self.args = args
self.config = None
self.set_loglevel(args)

def run_cmd(self):
return self.run()
Expand Down
11 changes: 7 additions & 4 deletions dvc/command/data_sync.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import unicode_literals

import argparse
import logging

import dvc.logger as logger
from dvc.command.base import CmdBase, append_doc_link


logger = logging.getLogger(__name__)


class CmdDataBase(CmdBase):
UP_TO_DATE_MSG = "Everything is up to date."

Expand Down Expand Up @@ -43,7 +46,7 @@ def do_run(self, target=None):
recursive=self.args.recursive,
)
except Exception:
logger.error("failed to pull data from the cloud")
logger.exception("failed to pull data from the cloud")
return 1
self.check_up_to_date(processed_files_count)
return 0
Expand All @@ -63,7 +66,7 @@ def do_run(self, target=None):
recursive=self.args.recursive,
)
except Exception:
logger.error("failed to push data to the cloud")
logger.exception("failed to push data to the cloud")
return 1
self.check_up_to_date(processed_files_count)
return 0
Expand All @@ -83,7 +86,7 @@ def do_run(self, target=None):
recursive=self.args.recursive,
)
except Exception:
logger.error("failed to fetch data from the cloud")
logger.exception("failed to fetch data from the cloud")
return 1
self.check_up_to_date(processed_files_count)
return 0
Expand Down
7 changes: 5 additions & 2 deletions dvc/command/destroy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import unicode_literals

import argparse
import logging

import dvc.prompt as prompt
import dvc.logger as logger
from dvc.command.base import CmdBase, append_doc_link
from dvc.exceptions import DvcException


logger = logging.getLogger(__name__)


class CmdDestroy(CmdBase):
def run_cmd(self):
try:
Expand All @@ -26,7 +29,7 @@ def run_cmd(self):

self.repo.destroy()
except Exception:
logger.error("failed to destroy DVC")
logger.exception("failed to destroy DVC")
return 1
return 0

Expand Down
8 changes: 5 additions & 3 deletions dvc/command/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import humanize
import inflect
import logging


import dvc.logger as logger
from dvc.exceptions import DvcException
from dvc.command.base import CmdBase
from dvc.utils.collections import compact
import dvc.repo.diff as diff


logger = logging.getLogger(__name__)


class CmdDiff(CmdBase):
def _print_size(self, size):
if size < 0:
Expand Down Expand Up @@ -113,7 +115,7 @@ def run(self):
compact([self.args.target, self.args.a_ref, self.args.b_ref])
)
msg = msg.format(args)
logger.error(msg)
logger.exception(msg)
return 1
return 0

Expand Down
5 changes: 4 additions & 1 deletion dvc/command/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import argparse
import os
import dvc.prompt as prompt
import dvc.logger as logger
import logging

from dvc.command.base import CmdBase, append_doc_link


logger = logging.getLogger(__name__)


class CmdGC(CmdBase):
def run(self):
msg = "this will remove all cache except the cache that is used in "
Expand Down
7 changes: 5 additions & 2 deletions dvc/command/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import argparse
import os
import logging

import dvc.logger as logger
from dvc.utils.compat import urlparse
from dvc.exceptions import DvcException
from dvc.command.base import CmdBase, append_doc_link


logger = logging.getLogger(__name__)


class CmdImport(CmdBase):
def run(self):
try:
Expand All @@ -18,7 +21,7 @@ def run(self):

self.repo.imp(self.args.url, out, self.args.resume)
except DvcException:
logger.error(
logger.exception(
"failed to import {}. You could also try downloading "
"it manually and adding it with `dvc add` command.".format(
self.args.url
Expand Down
7 changes: 5 additions & 2 deletions dvc/command/init.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import unicode_literals

import argparse
import logging

import dvc.logger as logger
from dvc.command.base import append_doc_link


logger = logging.getLogger(__name__)


class CmdInit(object):
def __init__(self, args):
self.args = args
Expand All @@ -20,7 +23,7 @@ def run_cmd(self):
)
self.config = self.repo.config
except InitError:
logger.error("failed to initiate dvc")
logger.exception("failed to initiate dvc")
return 1
return 0

Expand Down
7 changes: 5 additions & 2 deletions dvc/command/install.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from __future__ import unicode_literals

import argparse
import logging

import dvc.logger as logger
from dvc.command.base import CmdBase, append_doc_link


logger = logging.getLogger(__name__)


class CmdInstall(CmdBase):
def run_cmd(self):
try:
self.repo.install()
except Exception:
logger.error("failed to install dvc hooks")
logger.exception("failed to install dvc hooks")
return 1
return 0

Expand Down
Loading