peru
peru copied to clipboard
feature_request(dry): get variables from another YAML files
#199 — partially related issue
1. Summary
It would be nice, if peru can get variables from another YAML files.
2. Argumentation
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:
-
pick
variable in peru andPLUGINS
variable for Pelican. -
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
- Unfortunately, YAML doesn't support any kind of
include
orimport
statement. I can't find, how I can solve my problem use third-party tools. - Pelican required, for example,
PLUGINS
variable name. I can't change it togit 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.
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.