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

Fix configs to allow the use of configs as keys of other configs #2206

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

romain-intel
Copy link
Contributor

This allows things like this:

def git_info(args):
    info = {
        "commit": ["git", "rev-parse", "HEAD"],
        "branch": ["git", "rev-parse", "--abbrev-ref", "HEAD"],
        "message": ["git", "log", "-1", "--pretty=%B"],
    }
    cfg = {}
    for key, cmd in info.items():
        cfg[key] = check_output(cmd, text=True).strip()
    if cfg["branch"].startswith("feature/"):
        cfg["branch_type"] = "feature"
    elif cfg["branch"].startswith("main"):
        cfg["branch_type"] = "main"
    else:
        cfg["branch_type"] = "default"]
    print(f"cfg is {cfg}")
    return cfg

class MyExampleCICDFlow(FlowSpec):
    git_config = Config("git_config", default_value={}, parser=git_info)
    flow_config = Config("flow_config", default="my_config.json")

    @timeout(seconds=flow_config[git_config.branch_type].timeout)
    @step
    def start(self):
        # More code

This allows things like this:

```
def git_info(args):
    info = {
        "commit": ["git", "rev-parse", "HEAD"],
        "branch": ["git", "rev-parse", "--abbrev-ref", "HEAD"],
        "message": ["git", "log", "-1", "--pretty=%B"],
    }
    cfg = {}
    for key, cmd in info.items():
        cfg[key] = check_output(cmd, text=True).strip()
    if cfg["branch"].startswith("feature/"):
        cfg["branch_type"] = "feature"
    elif cfg["branch"].startswith("main"):
        cfg["branch_type"] = "main"
    else:
        cfg["branch_type"] = "default"]
    print(f"cfg is {cfg}")
    return cfg

class MyExampleCICDFlow(FlowSpec):
    git_config = Config("git_config", default_value={}, parser=git_info)
    flow_config = Config("flow_config", default="my_config.json")

    @timeout(seconds=flow_config[git_config.branch_type].timeout)
    @step
    def start(self):
        # More code
```
@romain-intel romain-intel merged commit 49a073e into master Jan 13, 2025
29 checks passed
@romain-intel romain-intel deleted the fix/allow-configs-in-configs branch January 13, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants