Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-26144 Inherit configs when inheriting a Pipeline #141

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/lsst/pipe/base/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from typing import Mapping, Union, Generator, TYPE_CHECKING

import copy
import os

# -----------------------------
# Imports for other modules --
Expand Down Expand Up @@ -335,7 +336,7 @@ def toExpandedPipeline(self) -> Generator[TaskDef]:
if configIR.dataId is None:
if configIR.file:
for configFile in configIR.file:
overrides.addFileOverride(configFile)
overrides.addFileOverride(os.path.expandvars(configFile))
if configIR.python is not None:
overrides.addPythonOverride(configIR.python)
for key, value in configIR.rest.items():
Expand Down
13 changes: 12 additions & 1 deletion python/lsst/pipe/base/pipelineIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,18 @@ def process_args(argument: Union[str, dict]) -> dict:
"be unique")
accumulate_tasks.update(tmp_IR.tasks)
self.contracts.extend(tmp_IR.contracts)
accumulate_tasks.update(self.tasks)

# merge the dict of label:TaskIR objects, preserving any configs in the
# imported pipeline if the labels point to the same class
for label, task in self.tasks.items():
if label not in accumulate_tasks:
accumulate_tasks[label] = task
elif accumulate_tasks[label].klass == task.klass:
if task.config is not None:
for config in task.config:
accumulate_tasks[label].add_or_update_config(config)
else:
accumulate_tasks[label] = task
self.tasks = accumulate_tasks

def _read_tasks(self, loaded_yaml):
Expand Down
5 changes: 4 additions & 1 deletion tests/testPipeline2.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
description: Test Pipeline
tasks:
modA: "test.moduleA"
modA:
class: "test.moduleA"
config:
value1: 1
30 changes: 30 additions & 0 deletions tests/test_pipelineIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,36 @@ def testInheritParsing(self):
pipeline = PipelineIR.from_string(pipeline_str)
self.assertEqual(pipeline.contracts, [])

# Test that configs are inherited when defining the same task again with
# the same label
pipeline_str = textwrap.dedent("""
description: Test Pipeline
inherits:
- $PIPE_BASE_DIR/tests/testPipeline2.yaml
tasks:
modA:
class: "test.moduleA"
config:
value2: 2
""")
pipeline = PipelineIR.from_string(pipeline_str)
self.assertEqual(pipeline.tasks["modA"].config[0].rest, {"value1": 1, "value2": 2})

# Test that configs are not inherited when redefining the task
# associated with a label
pipeline_str = textwrap.dedent("""
description: Test Pipeline
inherits:
- $PIPE_BASE_DIR/tests/testPipeline2.yaml
tasks:
modA:
class: "test.moduleAReplace"
config:
value2: 2
""")
pipeline = PipelineIR.from_string(pipeline_str)
self.assertEqual(pipeline.tasks["modA"].config[0].rest, {"value2": 2})

def testReadContracts(self):
# Verify that contracts are read in from a pipeline
location = os.path.expandvars("$PIPE_BASE_DIR/tests/testPipeline1.yaml")
Expand Down