def _read(self, directory_path, basename):
"""
Traverses the directory_path, from top to bottom, reading in all
relevant config files. If config items appear in files lower down the
environment tree, they overwrite items from further up.
:param directory_path: Relative directory path to config to read.
:type directory_path: str
:param filename: Base config to provide defaults.
:type filename: dict
:returns: Representation of inherited config.
:rtype: dict
"""
abs_directory_path = path.join(self.config_folder, directory_path)
if path.isfile(path.join(abs_directory_path, basename)):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(abs_directory_path),
undefined=jinja2.StrictUndefined
)
template = env.get_template(basename)
rendered_template = template.render(
environment_variable=environ,
environment_path=directory_path.split("/"),
**self.templating_vars
)
config = yaml.safe_load(rendered_template)
return config
评论列表
文章目录