a
    …Ï?e\
  ã                
   @   s¶   d dl Z d dlmZmZmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ d dlmZ eeƒ ed	d
ddddd�d�Zdd„ Zdd„ Zddd„Zd dlmZ ddd„ZdS )é    N)ÚmetaÚEnvironmentÚFileSystemLoaderé   )Úcpp)Úpython)Újsonnet)Ú	find_typeÚlistifyÚrelpathÚdebug)Úsearch_pathz~{#z#}~z~{z}~z~{{z}}~)Zcomment_start_stringZcomment_end_stringZblock_start_stringZblock_end_stringZvariable_start_stringZvariable_end_string)ÚnormalÚlatexc                 C   s   d}d| v rd}t | S )z2Return the markup style to use for a template filer   z.texr   )Ústyles)ÚfilenameÚstyle© r   úY/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/moo/templates/jinjaint.pyÚ	get_style   s    r   c                 K   sV   t f t| ƒddddgdœ|¤Ž}t|jd< t|jd< t|jd< |jjtt	t
td� |S )	z8Create and return Jinja environment for template at pathTzjinja2.ext.dozjinja2.ext.loopcontrols)ÚloaderZtrim_blocksZlstrip_blocksÚ
extensionsr
   r   r   )r	   r   Úpyr   )r   r   r
   Úfiltersr   r   ÚglobalsÚupdater	   r   r   r   )ÚpathÚkwdsÚenvr   r   r   Úmake_env   s    
ýü


ÿr   c                 C   sD   t | |ƒ}t| ƒ}t|fi |¤Ž}| tj | ¡¡}|jf i |¤ŽS )z6Render template against dictionary of model parameters)r   r   r   Zget_templateÚosr   ÚbasenameÚrender)ÚtemplateÚmodelÚtpathr   Ústyle_paramsr   Útmplr   r   r   r"   6   s
    
r"   )Úresolvec                    sV   t | |ƒ}t| ƒ}t|fi |¤Ž‰ ˆ  t| dƒ ¡  ¡ ¡}t |¡}‡ fdd„|D ƒS )z%Return all files imported by templateÚrbc                    s   g | ]}ˆ j  ˆ |¡d  ‘qS )r   )r   Ú
get_source)Ú.0Ús©r   r   r   Ú
<listcomp>M   ó    zimports.<locals>.<listcomp>)	r   r   r   ÚparseÚopenÚreadÚdecoder   Zfind_referenced_templates)r#   r%   r   r&   ÚastÚsubsr   r-   r   Úimports@   s    

r6   )N)N)r    Újinja2r   r   r   Ú r   r   r   Úutilr	   r
   r   r   Zmoo.utilr   Údictr   r   r   r"   r(   r6   r   r   r   r   Ú<module>   s*   ûþ	
	