From 2e09dbb592e3cae860448f7d172c852c551bfc98 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 28 Sep 2018 15:57:33 +0300 Subject: [PATCH 1/3] output: be more verbose Signed-off-by: Ruslan Kuprieiev --- dvc/output/local.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dvc/output/local.py b/dvc/output/local.py index 7955eb3ac..6e6018563 100644 --- a/dvc/output/local.py +++ b/dvc/output/local.py @@ -83,7 +83,7 @@ class OutputLOCAL(DependencyLOCAL): super(OutputLOCAL, self).save() self._verify_metric() msg = 'Output \'{}\' doesn\'t use cache. Skipping saving.' - self.project.logger.debug(msg.format(self.rel_path)) + self.project.logger.info(msg.format(self.rel_path)) return if not os.path.exists(self.path): @@ -99,7 +99,7 @@ class OutputLOCAL(DependencyLOCAL): if not self.changed(): msg = 'Output \'{}\' didn\'t change. Skipping saving.' - self.project.logger.debug(msg.format(self.rel_path)) + self.project.logger.info(msg.format(self.rel_path)) return if self.is_local: From 417ad8706efbb1719ee0425876f86f2fca14f230 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 28 Sep 2018 15:04:11 +0300 Subject: [PATCH 2/3] state: use state version Signed-off-by: Ruslan Kuprieiev --- dvc/state.py | 61 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/dvc/state.py b/dvc/state.py index 337645c3b..26e0cf3ff 100644 --- a/dvc/state.py +++ b/dvc/state.py @@ -15,6 +15,7 @@ class StateDuplicateError(DvcException): class State(object): + VERSION = 0 STATE_FILE = 'state' STATE_TABLE = 'state' STATE_TABLE_LAYOUT = "inode INTEGER PRIMARY KEY, " \ @@ -81,6 +82,51 @@ class State(object): return actual.split('.')[0] != md5.split('.')[0] + def _load(self): + from dvc import VERSION + + cmd = "PRAGMA user_version;" + self.c.execute(cmd) + ret = self.c.fetchall() + assert len(ret) == 1 + assert len(ret[0]) == 1 + assert isinstance(ret[0][0], int) + self.version = ret[0][0] + + if self.version > self.VERSION: + msg = "You are using an old version '{}' of dvc that is using " \ + "state file version '{}' which is not compatible with the " \ + "state file version '{}' that is used in this projet. " \ + "Please upgrade right now!" + raise DvcException(msg.format(VERSION, + self.VERSION, + self.version)) + elif self.version < self.VERSION: + msg = "State file version '{}' is too old. " \ + "Reformatting to the current version '{}'." + self.project.logger.warn(msg.format(self.version, self.VERSION)) + cmd = "DROP TABLE IF EXISTS {};" + self.c.execute(cmd.format(self.STATE_TABLE)) + self.c.execute(cmd.format(self.STATE_INFO_TABLE)) + self.c.execute(cmd.format(self.LINK_STATE_TABLE)) + + # Check that the state file is indeed a database + cmd = "CREATE TABLE IF NOT EXISTS {} ({})" + self.c.execute(cmd.format(self.STATE_TABLE, + self.STATE_TABLE_LAYOUT)) + self.c.execute(cmd.format(self.STATE_INFO_TABLE, + self.STATE_INFO_TABLE_LAYOUT)) + self.c.execute(cmd.format(self.LINK_STATE_TABLE, + self.LINK_STATE_TABLE_LAYOUT)) + + cmd = "INSERT OR IGNORE INTO {} (count) SELECT 0 " \ + "WHERE NOT EXISTS (SELECT * FROM {})" + self.c.execute(cmd.format(self.STATE_INFO_TABLE, + self.STATE_INFO_TABLE)) + + cmd = "PRAGMA user_version = {};" + self.c.execute(cmd.format(self.VERSION)) + def load(self): retries = 1 while True: @@ -93,20 +139,7 @@ class State(object): # Try loading once to check that the file is indeed a database # and reformat it if it is not. try: - # Check that the state file is indeed a database - cmd = "CREATE TABLE IF NOT EXISTS {} ({})" - self.c.execute(cmd.format(self.STATE_TABLE, - self.STATE_TABLE_LAYOUT)) - self.c.execute(cmd.format(self.STATE_INFO_TABLE, - self.STATE_INFO_TABLE_LAYOUT)) - self.c.execute(cmd.format(self.LINK_STATE_TABLE, - self.LINK_STATE_TABLE_LAYOUT)) - - cmd = "INSERT OR IGNORE INTO {} (count) SELECT 0 " \ - "WHERE NOT EXISTS (SELECT * FROM {})" - self.c.execute(cmd.format(self.STATE_INFO_TABLE, - self.STATE_INFO_TABLE)) - + self._load() return except sqlite3.DatabaseError: self.c.close() From f4fc3f47e4bda6a29f1d84699962f5761afa7cc5 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 28 Sep 2018 21:41:09 +0300 Subject: [PATCH 3/3] show: don't use asciicanvas package Signed-off-by: Ruslan Kuprieiev --- dvc/dagascii.py | 103 ++++++++++++++++++++++++++++++++++++++++------- requirements.txt | 1 - setup.py | 1 - 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/dvc/dagascii.py b/dvc/dagascii.py index 728778ba2..ec6689fa8 100644 --- a/dvc/dagascii.py +++ b/dvc/dagascii.py @@ -1,13 +1,88 @@ import math -from asciicanvas.asciicanvas import AsciiCanvas -from asciicanvas.style import Style - from grandalf.graphs import Vertex, Edge, Graph from grandalf.layouts import SugiyamaLayout from grandalf.routing import route_with_lines, EdgeViewer +class AsciiCanvas(object): + def __init__(self, cols, lines): + assert cols > 1 + assert lines > 1 + + self.cols = cols + self.lines = lines + self.canvas = [[' '] * cols for l in range(lines)] + + def draw(self): + for line in self.canvas: + print(''.join(line)) + + def point(self, x, y, char): + assert x >= 0 + assert x < self.cols + assert y >= 0 + assert y < self.lines + + self.canvas[y][x] = char + + def line(self, x0, y0, x1, y1, char): + if x0 > x1: + x1, x0 = x0, x1 + y1, y0 = y0, y1 + + dx = x1 - x0 + dy = y1 - y0 + + if dx == 0 and dy == 0: + self.point(x0, y0, char) + elif abs(dx) >= abs(dy): + for x in range(x0, x1 + 1): + if dx == 0: + y = y0 + else: + y = y0 + int(round((x - x0) * dy / float((dx)))) + self.point(x, y, char) + elif y0 < y1: + for y in range(y0, y1 + 1): + if dy == 0: + x = x0 + else: + x = x0 + int(round((y - y0) * dx / float((dy)))) + self.point(x, y, char) + else: + for y in range(y1, y0 + 1): + if dy == 0: + x = x0 + else: + x = x1 + int(round((y - y1) * dx / float((dy)))) + self.point(x, y, char) + + def text(self, x, y, text): + for i, c in enumerate(text): + self.point(x + i, y, c) + + def box(self, x0, y0, w, h): + assert w > 1 + assert h > 1 + + w -= 1 + h -= 1 + + for x in range(x0, x0 + w): + self.point(x, y0, '-') + self.point(x, y0 + h, '-') + + for y in range(y0, y0 + h): + self.point(x0, y, '|') + self.point(x0 + w, y, '|') + + self.point(x0, y0, '+') + self.point(x0 + w, y0, '+') + self.point(x0, y0 + h, '+') + self.point(x0 + w, y0 + h, '+') + + class Dagascii(object): def __init__(self, vertexes, edges): # @@ -100,22 +175,22 @@ class Dagascii(object): assert end_x >= 0 assert end_y >= 0 - canvas.add_line(start_x, start_y, - end_x, end_y, - style=Style('*')) + canvas.line(start_x, start_y, + end_x, end_y, + '*') for v in self.sug.g.sV: # NOTE: moving boxes w/2 to the left x = v.view.xy[0] - v.view.w/2.0 y = v.view.xy[1] - canvas.add_nine_patch_rect(int(round(x - minx)), - int(round(y - miny)), - v.view.w, - v.view.h) + canvas.box(int(round(x - minx)), + int(round(y - miny)), + v.view.w, + v.view.h) - canvas.add_text(int(round(x - minx)) + 1, - int(round(y - miny)) + 1, - v.data) + canvas.text(int(round(x - minx)) + 1, + int(round(y - miny)) + 1, + v.data) - canvas.print_out() + canvas.draw() diff --git a/requirements.txt b/requirements.txt index 59a8f335a..ab85126e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,5 +22,4 @@ requests>=2.18.4 wheel>=0.31.1 futures>=3.2.0; python_version == "2.7" grandalf==0.6 -asciicanvas==0.0.3 pydot>=1.2.4 diff --git a/setup.py b/setup.py index c5807d915..7452bba39 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,6 @@ install_requires = [ "jsonpath-rw==1.4.0", "requests>=2.18.4", "grandalf==0.6", - "asciicanvas==0.0.3", ] # Extra dependencies for remote integrations