Skip to content

Commit

Permalink
f-sa
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Oct 17, 2023
1 parent 1184f99 commit b736d6b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import copy
import enum
import os
import re
import subprocess
import threading
import jinja2
from collections import namedtuple
from pathlib import Path
from uuid import UUID
Expand All @@ -18,7 +20,6 @@
from aiida.transports.plugins import ssh as aiida_ssh_plugin
from humanfriendly import InvalidSize, parse_size
from IPython.display import clear_output, display
from jinja2 import Environment, meta

from .databases import ComputationalResourcesDatabaseWidget
from .utils import MessageLevel, StatusHTML, wrap_message
Expand Down Expand Up @@ -277,11 +278,11 @@ def __init__(self, ssh_folder=None, **kwargs):
)

# Username.
self.username = ipw.Text(description="username:", layout=LAYOUT, style=STYLE)
self.username = ipw.Text(description="Username:", layout=LAYOUT, style=STYLE)

# Port.
self.port = ipw.IntText(
description="port:",
description="Port:",
value=22,
layout=LAYOUT,
style=STYLE,
Expand Down Expand Up @@ -1248,8 +1249,6 @@ def _observe_code_setup(self, _=None):
try:
self.default_calc_job_plugin.value = value
except tl.TraitError:
import re

# If is a template then don't raise the error message.
if not re.match(r".*{{.+}}.*", value):
self.message = wrap_message(
Expand Down Expand Up @@ -1431,11 +1430,11 @@ def _render(self):
self._help_text.value = f"""<div>{tooltip}</div>"""

for line_key, line_str in self.templates.items():
env = Environment()
env = jinja2.Environment()
parsed_content = env.parse(line_str)

# vars is a set of variables in the template
line_vars = meta.find_undeclared_variables(parsed_content)
line_vars = jinja2.meta.find_undeclared_variables(parsed_content)

# Create a widget for each variable.
# The var is the name in a template string
Expand Down Expand Up @@ -1518,7 +1517,7 @@ def _on_template_variable_filled(self, change):
}

# re-render the template
env = Environment()
env = jinja2.Environment()
filled_str = env.from_string(line.str).render(**inp_dict)

# Update the filled template.
Expand Down Expand Up @@ -1890,9 +1889,9 @@ def _fill_template(self):
filled_templates = copy.deepcopy(w_tmp.filled_templates)

for k, v in w_tmp.filled_templates.items():
env = Environment()
env = jinja2.Environment()
parsed_content = env.parse(v)
vs = meta.find_undeclared_variables(parsed_content)
vs = jinja2.meta.find_undeclared_variables(parsed_content)

# No variables in the template, all filled.
if len(vs) == 0:
Expand Down

0 comments on commit b736d6b

Please sign in to comment.