Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT/BUG Rename TemplateConfig attributes + bug fix #10

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading