Skip to content

Commit

Permalink
local changes
Browse files Browse the repository at this point in the history
  • Loading branch information
eacharles committed Dec 15, 2021
1 parent 5703ed1 commit 1a80321
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 281 deletions.
19 changes: 18 additions & 1 deletion ceci/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,20 @@ def __init__(self):
self._tag_to_type = {}
self._tag_to_path = {}
self._path_to_tag = {}


def __getitem__(self, key):
return self._tag_to_path[key]

def __setitem__(self, key, value):
self._tag_to_path[key] = value
self._path_to_tag[value] = key

def __contains__(self, key):
return key in self._tag_to_path

def todict(self):
return self._tag_to_path

def insert(self, tag, path=None, ftype=None):
if path is not None:
self._tag_to_path[tag] = path
Expand Down Expand Up @@ -313,6 +326,10 @@ def add_stage(self, stage_info):
if sec.stage_obj:
return sec.stage_obj.find_outputs('.')
return {}

def build_stage(self, stage_class, args):
stage = stage_class(**args, **self.pipeline_files.todict())
return self.add_stage(stage)

def remove_stage(self, name):
"""Delete a stage from the pipeline
Expand Down
37 changes: 26 additions & 11 deletions ceci/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ def clone(cls, orig, cloneName, **kwargs):
def run(self):
raise NotImplementedError('run')

def get_aliased_tag(self, tag):
aliases = self.config.get('aliases', None)
if aliases is None:
return tag
return aliases.get(tag, tag)

def load_configs(self, args):
"""
Load the configuraiton
Expand Down Expand Up @@ -141,7 +147,7 @@ def load_configs(self, args):
Input names: {missing_inputs}"""
)

self._inputs = {x: args[x] for x in self.input_tags()}
self._inputs = {self.get_aliased_tag(x): args[x] for x in self.input_tags()}
# We alwys assume the config arg exists, whether it is in input_tags or not
if 'config' not in args:
raise ValueError("The argument --config was missing on the command line.")
Expand All @@ -155,9 +161,9 @@ def load_configs(self, args):
for i, x in enumerate(self.output_tags()):
if args.get(x) is None:
ftype = self.outputs[i][1]
self._outputs[x] = ftype.make_name(x)
self._outputs[self.get_aliased_tag(x)] = ftype.make_name(x)
else:
self._outputs[x] = args[x]
self._outputs[self.get_aliased_tag(x)] = args[x]

# Finally, we extract configuration information from a combination of
# command line arguments and optional 'config' file
Expand Down Expand Up @@ -945,20 +951,29 @@ def read_config(self, args):

#return my_config

def find_inputs(self, pipeline_files):
return {tag: pipeline_files[tag] for tag, _ in self.inputs}

def find_outputs(self, outdir):
return {tag: f"{outdir}/{ftype.make_name(tag)}" for tag, ftype in self.outputs}
def find_inputs(self, pipeline_files): # FIXME, pipeline_files
d = {}
for tag, _ in self.inputs:
aliased_tag = self.get_aliased_tag(tag)
d[aliased_tag] = pipeline_files[aliased_tag]
return d

def find_outputs(self, outdir): # FIXME, pipeline_files
d = {}
for tag, ftype in self.outputs:
aliased_tag = self.get_aliased_tag(tag)
d[aliased_tag] = f"{outdir}/{ftype.make_name(aliased_tag)}"
return d

def print_io(self, stream=sys.stdout):
stream.write("Inputs--------\n")
for tag, ftype in self.inputs:
stream.write(f"{tag:20} : {str(ftype):20} : {self._inputs[tag]}\n")
aliased_tag = self.get_aliased_tag(tag)
stream.write(f"{tag:20} : {aliased_tag:20} : {str(ftype):20} : {self._inputs[tag]}\n")
stream.write("Outputs--------\n")
for tag, ftype in self.outputs:
stream.write(f"{tag:20} : {str(ftype):20} : {self._outputs[tag]}\n")
aliased_tag = self.get_aliased_tag(tag)
stream.write(f"{tag:20} : {aliased_tag:20} : {str(ftype):20} : {self._outputs[tag]}\n")

def should_skip(self, run_config):
outputs = self.find_outputs(run_config["output_dir"]).values()
Expand Down Expand Up @@ -1066,7 +1081,7 @@ def iterate_hdf(
################################

@classmethod
def generate_command(cls, inputs, config, outputs):
def generate_command(cls, inputs, config, outputs): # FIXME PipelineFile
"""
Generate a command line that will run the stage
"""
Expand Down
Loading

0 comments on commit 1a80321

Please sign in to comment.