From 87325878949d5a315535720828af5185ebaa7a9f Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Thu, 1 Mar 2018 23:47:31 +0100 Subject: [PATCH] generate_config: New `-i` arg for j2 includes dir jinja2 does not support imports from parent directories, so in order for j2 to be able to use '{% from .j2 import ... %}' constructs with included j2 residing on a separate dirpath than current j2, add support for explicitly adding directories to the templater search path. This also allows calling generate_config with only file basename as '-j' arg value, as long as the dirname is passed via '-i' (can be extended later to parsing multiple j2 files at once). Change-Id: I943fda9262a6f7de5ee6fcc3e7bc9828c339651a Signed-off-by: Alexandru Avadanii --- config/utils/generate_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/utils/generate_config.py b/config/utils/generate_config.py index 6adbb44e..1387ed12 100755 --- a/config/utils/generate_config.py +++ b/config/utils/generate_config.py @@ -21,10 +21,11 @@ from jinja2 import Environment, FileSystemLoader PARSER = argparse.ArgumentParser() PARSER.add_argument("--yaml", "-y", type=str, required=True) PARSER.add_argument("--jinja2", "-j", type=str, required=True) +PARSER.add_argument("--includesdir", "-i", type=str, action='append') ARGS = PARSER.parse_args() ENV = Environment( - loader=FileSystemLoader(os.path.dirname(ARGS.jinja2)), + loader=FileSystemLoader([os.path.dirname(ARGS.jinja2)] + ARGS.includesdir), extensions=['jinja2.ext.do'] ) gen_config_lib.load_custom_filters(ENV) -- 2.16.6