From b736d6b00edf21b286547ae0165cdd17b6149a3a Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Tue, 17 Oct 2023 15:54:06 +0000 Subject: [PATCH] f-sa --- .../computational_resources.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/aiidalab_widgets_base/computational_resources.py b/aiidalab_widgets_base/computational_resources.py index 7e97d5b5d..2b29481f8 100644 --- a/aiidalab_widgets_base/computational_resources.py +++ b/aiidalab_widgets_base/computational_resources.py @@ -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 @@ -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 @@ -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, @@ -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( @@ -1431,11 +1430,11 @@ def _render(self): self._help_text.value = f"""
{tooltip}
""" 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 @@ -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. @@ -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: