tanbro / pyyaml-include

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

Added handling of non yaml file types as strings #8

Closed groundnuty closed 4 years ago

groundnuty commented 4 years ago

I have a use case when I want to include a bash code or a JSON file into the yaml as strings. When loading everything as YAML such include results with an error. Adding a wildcard to load *.yaml or *.yml files with YAML loader and others read as plain string solves the issue.

compute:
  shell: sh
  command: !include script.sh
apk update; apk add bash;
prepare() {
  echo "Changing working directo to: $work_dir" ;
  cd "$work_dir" ;
  pwd ;
  printf "$(date) " ; echo "Starting ioping prep with truncate." ;
  eval truncate $env_prepare_args ;
  printf "$(date) " ; echo "ioping prep end" ;
} ;
compute() {
  printf "$(date)" ; echo "Starting computation sysbench run." ;
  bash -c 'eval ioping $0 | tee >(sed -ne "/ioping statistics/,$ p" > /results/compute_results)' "$env_compute_args" ;
  printf "$(date) " ; echo "sysbench compute end" ;
} ;
clean() {
  printf "$(date)" ; echo "Starting cleaning." ;
  echo "No cleaning needed." ;
  printf "$(date) " ; echo "clean end" ;
} ;
freddrake commented 4 years ago

Would it be better to use a dispatch table based on extension? I could certainly see including JSON files into OpenAPI or RAML specification documents. (Or even just wanting to add .raml to the set of extensions recognized as YAML.)

tanbro commented 4 years ago

Thanks for the advice and the PR, it's a good idea.

Such a feature is started on https://github.com/tanbro/pyyaml-include/tree/feature/non-yaml-files