(file_src)
return env.render()
Process Jinja2 template input

    :param file_src: file contents
    :type file_src: str
Process Jinja2 template input
Process Jinja2 template input
def process_template(file_src):
    """ Process Jinja2 template input

    :param file_src: file contents
    :type file_src: str
    """
    def tmpl_sqrt(x):
        """ Square-root of 'x' """
        return math.sqrt(x)

    def tmpl_cubert(x):
        """ Cube-root of 'x' """
        return x ** (1.0 / 3.0) if x >= 0 else -(-x) ** (1.0 / 3.0)

    def tmpl_pow(x, y):
        """ 'x' to the power 'y' """
        return math.pow(x, y)

    # Check if it is possible to import 'jinja2'
    try:
        import jinja2
    except ImportError:
        raise GeomdlException("Please install 'jinja2' package to use templated input: pip install jinja2")

    # Replace jinja2 template tags for compatibility
    fsrc = file_src.replace("{%", "<%").replace("%}", "%>").replace("{{", "<{").replace("}}", "}>")

    # Generate Jinja2 environment
    env = jinja2.Environment(
        loader=jinja2.BaseLoader(),
        trim_blocks=True,
        block_start_string='<%', block_end_string='%>',
        variable_start_string='<{', variable_end_string='}>'
    ).from_string(fsrc)

    # Load custom functions into the Jinja2 environment
    template_funcs = dict(
        knot_vector=utilities.generate_knot_vector,
        sqrt=tmpl_sqrt,
        cubert=tmpl_cubert,
        pow=tmpl_pow,
    )
    for k, v in template_funcs.items():
        env.globals[k] = v

    # Process Jinja2 template functions & variables inside the input file
    return env.render()
def process_template ( file_src ) : def tmpl_sqrt ( x ) : """ Square-root of 'x' """ return math . sqrt ( x ) def tmpl_cubert ( x ) : """ Cube-root of 'x' """ return x ** ( 1.0 / 3.0 ) if x >= 0 else - ( - x ) ** ( 1.0 / 3.0 ) def tmpl_pow ( x , y ) : """ 'x' to the power 'y' """ return math . pow ( x , y ) # Check if it is possible to import 'jinja2' try : import jinja2 except ImportError : raise GeomdlException ( "Please install 'jinja2' package to use templated input: pip install jinja2" ) # Replace jinja2 template tags for compatibility fsrc = file_src . replace ( "{%" , "<%" ) . replace ( "%}" , "%>" ) . replace ( "{{" , "<{" ) . replace ( "}}" , "}>" ) # Generate Jinja2 environment env = jinja2 . Environment ( loader = jinja2 . BaseLoader ( ) , trim_blocks = True , block_start_string = '<%' , block_end_string = '%>' , variable_start_string = '<{' , variable_end_string = '}>' ) . from_string ( fsrc ) # Load custom functions into the Jinja2 environment template_funcs = dict ( knot_vector = utilities . generate_knot_vector , sqrt = tmpl_sqrt , cubert = tmpl_cubert , pow = tmpl_pow , ) for k , v in template_funcs . items ( ) : env . globals [ k ] = v # Process Jinja2 template functions & variables inside the input file return env . render ( )