kraemer-lab / GRAPEVNE

Graphical Analytical Pipeline Development Evironment
MIT License
6 stars 3 forks source link

[BUG]: Parameters with metadata can break configuration loading #292

Open jsbrittain opened 6 days ago

jsbrittain commented 6 days ago

Configuration files with parameter extensions (#174, #203) can break workflow builds since key names are dumped to config.yaml as :Name rather than ":Name". This can cause issues when parsing the parameters back into GRAPEVNE. The issue could be resolved by forcing all keys to be dumped as quoted strings.

The config.yaml files are dumped by the builder (Python) component. A potential implementation to fix this issue would be to provide a custom key representer, e.g.

import yaml
from yaml.representer import SafeRepresenter

# Define a custom representer to always quote keys
class QuotedKey(str):
    pass

def quoted_key_representer(dumper, data):
    return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='"')

# Add the custom representer to the SafeRepresenter
yaml.add_representer(QuotedKey, quoted_key_representer, Dumper=yaml.SafeDumper)

# Example dictionary
data = {
    QuotedKey('key1'): 'value1',
    QuotedKey('key2'): 'value2'
}

# Dump the dictionary with quoted keys
yaml_str = yaml.dump(data, Dumper=yaml.SafeDumper)
print(yaml_str)

This will produce

"key1": value1
"key2": value2

as opposed to

key1: value1
key2: value2