more efficient algorithm for getting applied templates with sources
Opened this issue · 0 comments
github-actions commented
more efficient algorithm for getting applied templates with sources
flexlate/flexlate/config_manager.py
Line 115 in 170bd1e
config: Optional[FlexlateConfig] = None,
) -> List[AppliedTemplateWithSource]:
config = config or self.load_config(project_root)
# TODO: more efficient algorithm for getting applied templates with sources
def get_source_config_path(source_name: str) -> Path:
if config is None:
raise ValueError("should not hit this, for type narrowing")
for child_config in config.child_configs:
for source in child_config.template_sources:
if source.name == source_name:
return child_config.settings.config_location
raise ValueError(f"could not find source {source_name}")
sources = config.template_sources_dict
applied_template_with_sources: List[AppliedTemplateWithSource] = []
for child_config in config.child_configs:
for i, applied_template in enumerate(child_config.applied_templates):
source = sources[applied_template.name]
source_config_path = get_source_config_path(source.name)
applied_template_config_path = child_config.settings.config_location
if (
relative_to is not None
and source.git_url is None
and not Path(source.path).is_absolute()
):
new_path = (relative_to / Path(source.path)).resolve()
use_source = source.copy(update=dict(path=new_path))
else:
use_source = source
applied_template_with_sources.append(
AppliedTemplateWithSource(
applied_template=applied_template,
source=use_source,
index=i,
source_config_path=source_config_path,
applied_template_config_path=applied_template_config_path,
)
)
return applied_template_with_sources
def get_all_renderables(
07b2332c4e8c75086847d35f9414aca5441cdd80