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

Create a wrapper around YAML metadata #4084

Open
Marigold opened this issue Mar 7, 2025 · 0 comments
Open

Create a wrapper around YAML metadata #4084

Marigold opened this issue Mar 7, 2025 · 0 comments

Comments

@Marigold
Copy link
Collaborator

Marigold commented Mar 7, 2025

We use YAML files extensively to manage metadata. This wasn't always the case, and over time we've accumulated a lot of technical debt from managing metadata in YAML files. It would be great to have everything centralized and refactored into a single class.

Proposal (in progress)

Create a class YAMLMeta with methods like

class YAMLMeta:

  def save(...)
  def load(...)
  def update(...)
  def merge(...)
  def validate(...)
  def render(dim_dict):
     # render Jinja with values given in dim_dict, should replace `render_yaml_file`
  ...

Since we have several types of YAML configs (for dataset metadata, MDIMs, snapshots, etc.), it would make sense to have a base class with subclasses for each case.

Overview of libraries for working with YAML files

  • dynamic_yaml – used to load YAML files and evaluate placeholders.
  • jinja2 – used to render Jinja templates with dimension values (it's not run on the entire YAML file, but on text inside fields like title).
  • ruamel.yaml – used for editing YAML files while preserving comments and overall structure.
  • yaml_dump – a function used instead of yaml.dump with better defaults.

There's also an interesting library, OmegaConf, which could potentially replace dynamic_yaml. It offers neat features, like accessing attributes via both .field and ["field"], and merging two YAML files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant