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

Implemented variable substitution for nested structures in cumulusci.yml #3665

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions cumulusci/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,26 @@ def _init_options(self, kwargs):
self.options.update(kwargs)

# Handle dynamic lookup of project_config values via $project_config.attr
for option, value in self.options.items():
if isinstance(value, str):
value = PROJECT_CONFIG_RE.sub(
def process_options(option):
if isinstance(option, str):
return PROJECT_CONFIG_RE.sub(
lambda match: str(self.project_config.lookup(match.group(1), None)),
value,
option,
)
self.options[option] = value
elif isinstance(option, dict):
processed_dict = {}
for key, value in option.items():
processed_dict[key] = process_options(value)
return processed_dict
elif isinstance(option, list):
processed_list = []
for item in option:
processed_list.append(process_options(item))
return processed_list
else:
return option

self.options = process_options(self.options)

if self.Options:
try:
Expand Down
16 changes: 16 additions & 0 deletions cumulusci/core/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def test_init_options__project_config_substitution(self):
task = BaseTask(self.project_config, self.task_config, self.org_config)
assert task.options["test_option"] == "baz"

# For variable substitution in nested structures
def test_init_options__project_config_substitution_nested(self):
self.project_config.config["foo"] = {"bar": "baz", "fighters": "pretender"}
self.project_config.config["vulf"] = {"peck": "DeanTown"}
self.task_config.config["options"] = {
"test_option": "$project_config.foo__bar",
"songs": [
{"foo_fighters": "$project_config.foo__fighters"},
{"vulfpeck": "$project_config.vulf__peck"},
],
}
task = BaseTask(self.project_config, self.task_config, self.org_config)
assert task.options["test_option"] == "baz"
assert task.options["songs"][0]["foo_fighters"] == "pretender"
assert task.options["songs"][1]["vulfpeck"] == "DeanTown"

def test_init_options__not_shared(self):
self.project_config.config["foo"] = {"bar": "baz"}
self.task_config.config["options"] = {}
Expand Down
Loading