tanbro / pyyaml-include

yaml include other yaml
https://pypi.org/project/pyyaml-include/
GNU General Public License v3.0
78 stars 20 forks source link

Wildcard with Hash/Dict/Map #30

Closed jose-pr closed 1 year ago

jose-pr commented 1 year ago

More of a question, but also a request if it is possible. Can i include wildcard and instead of a list fill a object with filename (with/without suffix) as the key and loaded value as the value?

files: !include {path_name: include.d/*.yml, map: full_name/without_prefix/custom_function}
files: !include {path_name: include.d/*.yml, map: without_prefix}

This should be:

files:
  1:
    name: 1
 2:
    name: 2
files: !include {path_name: include.d/*.yml, map:  true}

This should be:

files:
  1.yaml:
    name: 1
 2.yaml:
    name: 2
def custom_function(file:str, value:any):
  return Path(file).name
tanbro commented 1 year ago

Thanks for the advice.

Currently, wildcard files are loaded as a list, that's handy enough for most simple usages.

To load matched files as a mapping, we shall write the map function object inside the YAML text, but SafeLoader won't load !!Python tags by default.

And also i think it may be a little overheaded.