outs/deps: use 'stage' instead of 'project'

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-05-23 00:51:08 +03:00
parent 21bf52ee9d
commit 56e76d0d8b
3 changed files with 46 additions and 43 deletions
+14 -13
View File
@@ -42,8 +42,9 @@ class Dependency(object):
schema.Optional(PARAM_MD5): schema.Or(str, None),
}
def __init__(self, project, path, md5=None):
self.project = project
def __init__(self, stage, path, md5=None):
self.stage = stage
self.project = stage.project
self.path = os.path.abspath(os.path.normpath(path))
if not self.path.startswith(self.project.root_dir):
@@ -100,27 +101,27 @@ class Dependency(object):
assert not posixpath.isabs(path)
return path.replace('\\', '/')
def dumpd(self, cwd):
def dumpd(self):
return {
self.PARAM_PATH: self.unixpath(os.path.relpath(self.path, cwd)),
self.PARAM_PATH: self.unixpath(os.path.relpath(self.path, self.stage.cwd)),
self.PARAM_MD5: self.md5,
}
@classmethod
def loadd(cls, project, d, cwd=os.curdir):
def loadd(cls, stage, d):
relpath = os.path.normpath(Dependency.unixpath(d[Dependency.PARAM_PATH]))
path = os.path.join(cwd, relpath)
path = os.path.join(stage.cwd, relpath)
md5 = d.get(Dependency.PARAM_MD5, None)
return cls(project, path, md5=md5)
return cls(stage, path, md5=md5)
@classmethod
def loadd_from(cls, project, d_list, cwd=os.curdir):
return [cls.loadd(project, x, cwd=cwd) for x in d_list]
def loadd_from(cls, stage, d_list):
return [cls.loadd(stage, x) for x in d_list]
@classmethod
def loads(cls, project, s, cwd=os.curdir):
return cls(project, os.path.join(cwd, s), md5=None)
def loads(cls, stage, s):
return cls(stage, os.path.join(stage.cwd, s), md5=None)
@classmethod
def loads_from(cls, project, s_list, cwd=os.curdir):
return [cls.loads(project, x, cwd=cwd) for x in s_list]
def loads_from(cls, stage, s_list):
return [cls.loads(stage, x) for x in s_list]
+10 -10
View File
@@ -44,8 +44,8 @@ class Output(Dependency):
SCHEMA = Dependency.SCHEMA
SCHEMA[schema.Optional(PARAM_CACHE)] = bool
def __init__(self, project, path, md5=None, use_cache=True):
super(Output, self).__init__(project, path, md5=md5)
def __init__(self, stage, path, md5=None, use_cache=True):
super(Output, self).__init__(stage, path, md5=md5)
self.use_cache = use_cache
@property
@@ -55,26 +55,26 @@ class Output(Dependency):
return self.project.cache.get(self.md5)
def dumpd(self, cwd):
ret = super(Output, self).dumpd(cwd)
def dumpd(self):
ret = super(Output, self).dumpd()
ret[Output.PARAM_CACHE] = self.use_cache
return ret
@classmethod
def loadd(cls, project, d, cwd=os.curdir):
ret = super(Output, cls).loadd(project, d, cwd=cwd)
def loadd(cls, stage, d):
ret = super(Output, cls).loadd(stage, d)
ret.use_cache = d.get(Output.PARAM_CACHE, True)
return ret
@classmethod
def loads(cls, project, s, use_cache=True, cwd=os.curdir):
ret = super(Output, cls).loads(project, s, cwd=cwd)
def loads(cls, stage, s, use_cache=True):
ret = super(Output, cls).loads(stage, s)
ret.use_cache = use_cache
return ret
@classmethod
def loads_from(cls, project, s_list, use_cache=False, cwd=os.curdir):
return [cls.loads(project, x, use_cache=use_cache, cwd=cwd) for x in s_list]
def loads_from(cls, stage, s_list, use_cache=False):
return [cls.loads(stage, x, use_cache=use_cache) for x in s_list]
def changed(self):
if super(Output, self).changed():
+22 -20
View File
@@ -148,17 +148,18 @@ class Stage(object):
path = os.path.abspath(path)
cwd = os.path.dirname(path)
cmd = d.get(Stage.PARAM_CMD, None)
deps = Dependency.loadd_from(project, d.get(Stage.PARAM_DEPS, []), cwd=cwd)
outs = Output.loadd_from(project, d.get(Stage.PARAM_OUTS, []), cwd=cwd)
md5 = d.get(Stage.PARAM_MD5, None)
return Stage(project=project,
path=path,
cmd=cmd,
cwd=cwd,
deps=deps,
outs=outs,
md5=md5)
stage = Stage(project=project,
path=path,
cmd=cmd,
cwd=cwd,
md5=md5)
stage.deps = Dependency.loadd_from(stage, d.get(Stage.PARAM_DEPS, []))
stage.outs = Output.loadd_from(stage, d.get(Stage.PARAM_OUTS, []))
return stage
@staticmethod
def loads(project=None,
@@ -170,16 +171,17 @@ class Stage(object):
cwd=os.curdir):
cwd = os.path.abspath(cwd)
path = os.path.join(cwd, fname)
outputs = Output.loads_from(project, outs, use_cache=True, cwd=cwd)
outputs += Output.loads_from(project, outs_no_cache, use_cache=False, cwd=cwd)
dependencies = Dependency.loads_from(project, deps, cwd=cwd)
return Stage(project=project,
path=path,
cmd=cmd,
cwd=cwd,
outs=outputs,
deps=dependencies)
stage = Stage(project=project,
path=path,
cmd=cmd,
cwd=cwd)
stage.outs = Output.loads_from(stage, outs, use_cache=True)
stage.outs += Output.loads_from(stage, outs_no_cache, use_cache=False)
stage.deps = Dependency.loads_from(stage, deps)
return stage
@staticmethod
def load(project, fname):
@@ -187,8 +189,8 @@ class Stage(object):
return Stage.loadd(project, yaml.safe_load(fd), fname)
def dumpd(self):
deps = [x.dumpd(self.cwd) for x in self.deps]
outs = [x.dumpd(self.cwd) for x in self.outs]
deps = [x.dumpd() for x in self.deps]
outs = [x.dumpd() for x in self.outs]
ret = {}
if self.cmd != None: