Skip to content

Commit

Permalink
Merge pull request #10 from gadorlhiac/MNT/template_cfg
Browse files Browse the repository at this point in the history
MNT/BUG Rename TemplateConfig attributes + bug fix
  • Loading branch information
valmar authored Mar 26, 2024
2 parents 063bb13 + 02029cc commit 743a878
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
14 changes: 11 additions & 3 deletions lute/io/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,15 @@ def extra_fields_to_thirdparty(cls, values):


class TemplateConfig(BaseModel):
"""Parameters used for templating of third party configuration files."""
"""Parameters used for templating of third party configuration files.
template_dir: str
output_dir: str
Attributes:
template_name (str): The name of the template to use. This template must
live in `config/templates`.
output_path (str): The FULL path, including filename to write the
rendered template to.
"""

template_name: str
output_path: str
6 changes: 3 additions & 3 deletions lute/io/models/smd.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SubmitSMDParameters(BaseBinaryParameters):
False, description="Whether to not use archiver data.", flag_type="--"
)

lute_template_cfg: TemplateConfig = TemplateConfig(template_dir="", output_dir="")
lute_template_cfg: TemplateConfig = TemplateConfig(template_name="", output_path="")

@validator("producer", always=True)
def validate_producer_path(cls, producer: str) -> str:
Expand All @@ -140,8 +140,8 @@ def validate_producer_path(cls, producer: str) -> str:
def use_producer(
cls, lute_template_cfg: TemplateConfig, values: Dict[str, Any]
) -> TemplateConfig:
if not lute_template_cfg.output_dir:
lute_template_cfg.output_dir = values["producer"]
if not lute_template_cfg.output_path:
lute_template_cfg.output_path = values["producer"]
return lute_template_cfg

# detnames: ThirdPartyParameters = ThirdPartyParameters({})
Expand Down
7 changes: 4 additions & 3 deletions lute/tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def _template_to_config_file(self) -> None:
"""
from jinja2 import Environment, FileSystemLoader, Template

out_file: str = self._task_parameters.lute_template_cfg.output_dir
template_file: str = self._task_parameters.lute_template_cfg.template_dir
out_file: str = self._task_parameters.lute_template_cfg.output_path
template_name: str = self._task_parameters.lute_template_cfg.template_name

lute_path: Optional[str] = os.getenv("LUTE_PATH")
template_dir: str
Expand All @@ -227,7 +227,7 @@ def _template_to_config_file(self) -> None:
else:
template_dir = f"{lute_path}/config/templates"
environment: Environment = Environment(loader=FileSystemLoader(template_dir))
template: Template = environment.get_template(template_file)
template: Template = environment.get_template(template_name)

with open(out_file, "w", encoding="utf-8") as cfg_out:
cfg_out.write(template.render(self._template_context))
Expand Down Expand Up @@ -276,6 +276,7 @@ def _pre_run(self) -> None:
if isinstance(self._task_parameters.__dict__[param], ThirdPartyParameters):
# ThirdPartyParameters objects have a single parameter `params`
self._add_to_jinja_context(param_name=param, value=value.params)
continue

param_attributes: Dict[str, Any] = full_schema["properties"][param]
# Some model params do not match the commnad-line parameter names
Expand Down

0 comments on commit 743a878

Please sign in to comment.