Skip to content

Commit

Permalink
Merge pull request iterative#1201 from efiop/master
Browse files Browse the repository at this point in the history
repro: show which dependencies have changed
  • Loading branch information
efiop authored Oct 10, 2018
2 parents 82b10a8 + 1de87bc commit 13a2e46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
20 changes: 14 additions & 6 deletions dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ class Logger(object):
}

COLOR_MAP = {
'debug': colorama.Fore.BLUE,
'warn': colorama.Fore.YELLOW,
'error': colorama.Fore.RED
'green': colorama.Fore.GREEN,
'yellow': colorama.Fore.YELLOW,
'blue': colorama.Fore.BLUE,
'red': colorama.Fore.RED,
}

LEVEL_COLOR_MAP = {
'debug': 'blue',
'warn': 'yellow',
'error': 'red',
}

def __init__(self, loglevel=None):
Expand Down Expand Up @@ -58,12 +65,12 @@ def be_verbose():
Logger.logger().setLevel(logging.DEBUG)

@staticmethod
def colorize(msg, typ):
def colorize(msg, color):
header = ''
footer = ''

if sys.stdout.isatty(): # pragma: no cover
header = Logger.COLOR_MAP.get(typ.lower(), '')
header = Logger.COLOR_MAP.get(color.lower(), '')
footer = colorama.Style.RESET_ALL

return u'{}{}{}'.format(header, msg, footer)
Expand All @@ -84,7 +91,8 @@ def parse_exc(exc, tb=None):

@staticmethod
def _prefix(msg, typ):
return Logger.colorize('{}: '.format(msg), typ)
color = Logger.LEVEL_COLOR_MAP.get(typ.lower(), '')
return Logger.colorize('{}: '.format(msg), color)

@staticmethod
def error_prefix():
Expand Down
48 changes: 33 additions & 15 deletions dvc/stage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import yaml
import itertools
import posixpath
import subprocess
from schema import Schema, SchemaError, Optional, Or, And
Expand Down Expand Up @@ -135,8 +134,6 @@ def changed_md5(self):
if self.md5 and md5 and self.md5 == md5:
return False

msg = "Dvc file '{}' md5 changed(expected '{}', actual '{}')"
self.project.logger.debug(msg.format(self.relpath, self.md5, md5))
return True

@property
Expand All @@ -149,30 +146,51 @@ def is_import(self):
len(self.deps) == 1 and \
len(self.outs) == 1

def changed(self):
def changed(self, print_info=False):
ret = False

if print_info:
log = self.project.logger.info
else:
log = self.project.logger.debug

if self.is_callback:
msg = "Dvc file '{}' is a 'callback' stage (has a command and " \
"no dependencies) and thus always considered as changed."
self.project.logger.warn(msg.format(self.relpath))
ret = True

if self.locked:
entries = self.outs
else:
entries = itertools.chain(self.outs, self.deps)

for entry in entries:
if entry.changed():
if not self.locked:
for dep in self.deps:
if not dep.changed():
continue
if print_info:
msg = "Dependency '{}' of '{}' changed."
log(msg.format(dep, self.relpath))
ret = True

for out in self.outs:
if not out.changed():
continue
if print_info:
msg = "Output '{}' of '{}' changed."
log(msg.format(out, self.relpath))
ret = True

if self.changed_md5():
if print_info:
msg = "Dvc file '{}' changed."
log(msg.format(self.relpath))
ret = True

if ret:
msg = u'Dvc file \'{}\' changed'.format(self.relpath)
msg = "Stage '{}' changed.".format(self.relpath)
color = 'yellow'
else:
msg = u'Dvc file \'{}\' didn\'t change'.format(self.relpath)
msg = "Stage '{}' didn't change.".format(self.relpath)
color = 'green'

self.project.logger.debug(msg)
log(Logger.colorize(msg, color))

return ret

Expand All @@ -185,7 +203,7 @@ def remove(self):
os.unlink(self.path)

def reproduce(self, force=False, dry=False, interactive=False):
if not self.changed() and not force:
if not self.changed(print_info=True) and not force:
return None

if (self.cmd or self.is_import) and not self.locked and not dry:
Expand Down

0 comments on commit 13a2e46

Please sign in to comment.