peru icon indicating copy to clipboard operation
peru copied to clipboard

feature_request(dry): get variables from another YAML files

Open Kristinita opened this issue 5 years ago • 1 comments

#199 — partially related issue

1. Summary

It would be nice, if peru can get variables from another YAML files.

2. Argumentation

Don't Repeat Yourself.

At the time I need to write duplicate code for using Peru.

3. Example

3.1. Structure and files

Part of my real project structure:

peru.yaml
site_variables.yaml
pelican-config/
  pelican_plugins_settings.yaml
  • peru.yaml:
imports:
  pelican-plugins: plugins/

git module pelican-plugins:
  url: https://github.com/getpelican/pelican-plugins
  pick:
  - filetime_from_git
  - interlinks
  - just_table
  - neighbors
  - pelican-open_graph
  - section_number
  - sitemap
  • part of site_variables.yaml:
PLUGIN_PATHS:
- plugins
  • part of pelican-config/pelican_plugins_settings.yaml:
PLUGINS:
- filetime_from_git
- interlinks
- just_table
- neighbors
- pelican-open_graph
- section_number
- sitemap

3.2. Problem

I use duplicate values for:

  1. pick variable in peru and PLUGINS variable for Pelican.
  2. imports.pelican-plugins — peru; PLUGIN_PATHS — Pelican.

If I change Pelican variable, I need manually make the same change for peru. I need to repeat myself.

4. Not helped

  1. Unfortunately, YAML doesn't support any kind of include or import statement. I can't find, how I can solve my problem use third-party tools.
  2. Pelican required, for example, PLUGINS variable name. I can't change it to git module pelican-plugins.pick for using peru with --file-basename flag.

5. Example of expected behavior

  • peru.yaml:
include: site_variables.yaml
include: pelican-config/pelican_plugins_settings.yaml

imports:
  pelican-plugins: site-variables.PLUGIN_PATHS

git module pelican-plugins:
  url: https://github.com/getpelican/pelican-plugins
  pick: pelican_plugins_settings.PLUGINS

Thanks.

Kristinita avatar Mar 14 '19 09:03 Kristinita

Have you considered writing a program to generate one YAML file from the other. Or maybe generating both YAML files from some other shared input file?

The peru.yaml format is intended to be relatively simple, both to read and to write. I'm a little wary of adding more complicated behavior to it, because that would make it harder for other programs to parse it and figure out what it's doing.

oconnor663 avatar Sep 06 '19 17:09 oconnor663