earthmover icon indicating copy to clipboard operation
earthmover copied to clipboard

Make YAML parser use config file path to render Jinja

Open alchenist opened this issue 1 month ago • 0 comments

Potential fix for #177, which documents the case where

  1. Jinja is imported in an earthmover config YAML, but installing that package via earthmover deps breaks, because the relative imports cannot be found from the root directory of the importing project (e.g. student_id_wrapper).
  2. Jinja is imported in an earthmover destination template, but running that package under project composition breaks (assuming you get past the install issues above), because the relative imports cannot be found from the root directory of the importing project.

To fix these, this commit:

  1. Adds an optional parameter to util.build_jinja_template that gets passed to jinja2.FileSystemLoader to control where templates are searched for. This replaces the original behavior, where FileSystemLoader was always initialized with the current working directory of the root earthmover.yaml.
  2. Modifies JinjaEnvironmentLoader.load_config_file to pass the parent directory of the config file being rendered to util.build_jinja_template. Deps thus runs succesasfully.
  3. Modifies Destination nodes to pass the directory of the associated config file to util.build_jinja_template.

Open to other fixes, but this seems like an easy minimal fix to me that doesn't require changing the working directory. Could write out tests for the desired behavior if needed.

alchenist avatar Nov 20 '25 22:11 alchenist