Skip to content

Commit

Permalink
cache template
Browse files Browse the repository at this point in the history
  • Loading branch information
reschandreas committed Dec 31, 2023
1 parent 8ee65fb commit 64a89a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cli/generators/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class CliGenerator(BaseGenerator):

initial_directory_variable: str = "AEOLUS_INITIAL_DIRECTORY"

template: Optional[typing.Any] = None

def __init__(
self, windfile: WindFile, input_settings: InputSettings, output_settings: OutputSettings, metadata: PassMetadata
):
Expand Down Expand Up @@ -194,8 +196,9 @@ def generate_using_jinja2(self) -> str:
Generate the bash script to be used as a local CI system with jinja2.
"""
# Load the template from the file system
env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), "..", "templates")))
template = env.get_template("cli.sh.j2")
if not self.template:
env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), "..", "templates")))
self.template = env.get_template("cli.sh.j2")

# Prepare your data
data = {
Expand All @@ -214,7 +217,7 @@ def generate_using_jinja2(self) -> str:
}

# Render the template with your data
rendered_script = template.render(data)
rendered_script = self.template.render(data)

return rendered_script

Expand Down
8 changes: 4 additions & 4 deletions cli/templates/cli.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ set -e
export {{ initial_directory_variable }}=${PWD}
{%- endif -%}

{# Handling environment variables from windfile -#}
{%- for env_var in environment -%}
{%- if environment -%}
{% for env_var in environment -%}
export {{ env_var }}="{{ environment[env_var] }}"
{%- endfor -%}
{%- endif -%}

{# Additional functions based on steps -#}
{%- for step in steps %}
{{ step.name }} () {
echo '⚙️ executing {{ step.name }}'
Expand Down Expand Up @@ -71,7 +71,7 @@ set -e
{% endfor -%}

{%- if has_always_actions -%}
function final_aeolus_post_action () {
final_aeolus_post_action () {
set +e # from now on, we don't exit on errors
echo '⚙️ executing final_aeolus_post_action'
cd {{ initial_directory }}
Expand Down

0 comments on commit 64a89a4

Please sign in to comment.