From d09e46921099e8fb5b31bb8491fc51a7ad1da018 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Wed, 2 Jan 2019 15:05:38 +0200 Subject: [PATCH] deps: use self.url instead of self.path Signed-off-by: Ruslan Kuprieiev --- dvc/dependency/base.py | 26 +++++++++++++++----------- dvc/dependency/local.py | 18 ++++++++++-------- dvc/dependency/ssh.py | 2 +- dvc/output/local.py | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dvc/dependency/base.py b/dvc/dependency/base.py index 7a519f9cf..6151790b6 100644 --- a/dvc/dependency/base.py +++ b/dvc/dependency/base.py @@ -23,23 +23,23 @@ class DependencyBase(object): def __init__(self, stage, path): self.stage = stage self.project = stage.project - self.path = path + self.url = path def __repr__(self): - return "{class_name}: '{path}'".format( + return "{class_name}: '{url}'".format( class_name=type(self).__name__, - path=(self.path or 'No path') + url=(self.url or 'No url') ) def __str__(self): - return self.path + return self.url @classmethod def match(cls, url): return re.match(cls.REGEX, url) def group(self, name): - match = self.match(self.path) + match = self.match(self.url) if not match: return None return match.group(name) @@ -48,6 +48,14 @@ class DependencyBase(object): def supported(cls, url): return cls.match(url) is not None + @property + def scheme(self): + return self.path_info['scheme'] + + @property + def path(self): + return self.path_info['path'] + @property def sep(self): return '/' @@ -62,18 +70,14 @@ class DependencyBase(object): def status(self): if self.changed(): # FIXME better msgs - if self.path_info['scheme'] == 'local': - p = self.rel_path - else: - p = self.path - return {p: 'changed'} + return {str(self): 'changed'} return {} def save(self): raise NotImplementedError def dumpd(self): - return {self.PARAM_PATH: self.path} + return {self.PARAM_PATH: self.url} def download(self, to_info): self.remote.download([self.path_info], [to_info]) diff --git a/dvc/dependency/local.py b/dvc/dependency/local.py index f944e5e6a..554a1b23d 100644 --- a/dvc/dependency/local.py +++ b/dvc/dependency/local.py @@ -19,8 +19,7 @@ class DependencyLOCAL(DependencyBase): IsNotFileOrDirError = DependencyIsNotFileOrDirError def __init__(self, stage, path, info=None, remote=None): - self.stage = stage - self.project = stage.project + super(DependencyLOCAL, self).__init__(stage, path) self.info = info if remote is not None: self.remote = remote @@ -28,15 +27,18 @@ class DependencyLOCAL(DependencyBase): self.remote = RemoteLOCAL(stage.project, {}) if remote: - path = os.path.join(remote.prefix, urlparse(path).path.lstrip('/')) + p = os.path.join(remote.prefix, + urlparse(self.url).path.lstrip('/')) + else: + p = path - if not os.path.isabs(path): - path = self.remote.to_ospath(path) - path = os.path.join(stage.cwd, path) - self.path = os.path.abspath(os.path.normpath(path)) + if not os.path.isabs(p): + p = self.remote.to_ospath(p) + p = os.path.join(stage.cwd, p) + p = os.path.abspath(os.path.normpath(p)) self.path_info = {'scheme': 'local', - 'path': self.path} + 'path': p} def __str__(self): return self.rel_path diff --git a/dvc/dependency/ssh.py b/dvc/dependency/ssh.py index f4463213f..66a644d01 100644 --- a/dvc/dependency/ssh.py +++ b/dvc/dependency/ssh.py @@ -24,7 +24,7 @@ class DependencySSH(DependencyBase): path = posixpath.join(remote.prefix, urlparse(path).path.lstrip('/')) else: - path = self.match(self.path).group('path') + path = self.match(self.url).group('path') self.path_info = {'scheme': 'ssh', 'host': host, diff --git a/dvc/output/local.py b/dvc/output/local.py index eda2aa6b0..bd9ff504d 100644 --- a/dvc/output/local.py +++ b/dvc/output/local.py @@ -127,7 +127,7 @@ class OutputLOCAL(DependencyLOCAL): self.project.scm.ignore_remove(self.path) self.remote.move(self.path_info, out.path_info) - self.path = out.path + self.url = out.url self.path_info = out.path_info self.save()