a
    xd\                     @   s`   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Zd dl
ZG dd deZdS )    )absolute_importNc                   @   s   e Zd ZdZddi dfddZedd Zed	d
 Zejdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )	LitConfigaU  LitConfig - Configuration data for a 'lit' test runner instance, shared
    across all tests.

    The LitConfig object is also used to communicate with client configuration
    files, it is always passed in as the global variable 'lit' so that
    configuration files can access common functionality and internal components
    easily.
    Nr   Fc                    s(  | _ dd |D  _t| _t| _t| _t| _| _| _	t|	 _
|
 _t| _d  _|ppd _ddg _ fdd jD  _ fdd jD  _ fdd jD  _d	 _d	 _g  _ jrg d
 _ jr jd n jd  j j | _| _| _d S )Nc                 S   s   g | ]}t |qS  )str).0pr   r   V/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lit/LitConfig.py
<listcomp>!       z&LitConfig.__init__.<locals>.<listcomp>litzcfg.pycfgc                    s   g | ]}d  j |f qS )z%s.%sconfig_prefixr   xselfr   r   r	   0   r
   c                    s   g | ]}d  j |f qS )z
%s.site.%sr   r   r   r   r   r	   1   r
   c                    s   g | ]}d  j |f qS )z%s.local.%sr   r   r   r   r   r	   2   r
   r   )Zvalgrindz-qz--run-libc-freeres=noz--tool=memcheckz--trace-children=yesz--error-exitcode=123z--leak-check=fullz--leak-check=no)prognamepathboolquietuseValgrindvalgrindLeakChecklistZvalgrindUserArgs	noExecutedebug	isWindowsorderdictparamsbashPathr   suffixesZconfig_namesZsite_config_namesZlocal_config_names	numErrorsnumWarningsvalgrindArgsappendextendmaxIndividualTestTimeparallelism_groupsecho_all_commands)r   r   r   r   r   r   r$   r   r   r   r   r   r   r'   r(   r)   r   r   r   __init__   s:    








zLitConfig.__init__c                 C   s   | j S )ze
            Interface for getting maximum time to spend executing
            a single test
        )_maxIndividualTestTimer   r   r   r   r'   G   s    zLitConfig.maxIndividualTestTimec                 C   s
   t j S )a  
            Returns a tuple (<supported> , <error message>)
            where
            `<supported>` is True if setting maxIndividualTestTime is supported
                on the current host, returns False otherwise.
            `<error message>` is an empty string if `<supported>` is True,
                otherwise is contains a string describing why setting
                maxIndividualTestTime is not supported.
        )r   utilZ!killProcessAndChildrenIsSupportedr   r   r   r    maxIndividualTestTimeIsSupportedO   s    z*LitConfig.maxIndividualTestTimeIsSupportedc                 C   sZ   t |ts| d || _| jdkrB| j\}}|sV| d|  n| jdk rV| d dS )ze
            Interface for setting maximum time to spend executing
            a single test
        z6maxIndividualTestTime must set to a value of type int.r   z*Setting a timeout per test not supported. z)The timeout per test must be >= 0 secondsN)
isinstanceintfatalr+   r'   r-   )r   value	supportedZerrormsgr   r   r   r'   \   s    




c                 C   s$   | j r| d|  |||  |S )zPload_config(config, path) - Load a config object from an alternate
        path.zload_config from %r)r   noteZload_from_path)r   configr   r   r   r   load_configp   s    zLitConfig.load_configc                 C   s   | j dur| j S tjdtj| j| _ | j du rBtjd| _ | j du rRd| _ | jr| j r| j dd| j 	dd g}tj
|\}}}|r| dd	d
d |D   d| _ | j s| d | j S )z$getBashPath - Get the path to 'bash'Nbash z-cz[[ -f "%s" ]]\z\\zbash command failed: %s c                 s   s   | ]}d | V  qdS )z"%s"Nr   )r   cr   r   r   	<genexpr>   r
   z(LitConfig.getBashPath.<locals>.<genexpr>z(Unable to find a usable version of bash.)r    r   r,   whichospathsepjoinr   r   replaceZexecuteCommandr3   warning)r   command_ZexitCoder   r   r   getBashPathx   s(    



zLitConfig.getBashPathc                 C   sf   |d ur4t j|r4t j|r4tj||sBd S ntj||}tjd|| _	| j	d u rbd| _	|S )Nr6   r7   )
r=   r   isabsisdirr   r,   ZcheckToolsPathZ
whichToolsr<   r    )r   dirpathsZtoolsr   r   r   getToolsPath   s     
zLitConfig.getToolsPathc                 C   s\   t  }|jj}tjt |}t |}tj	
d| j||||f  | jrXtj	  d S )Nz%s: %s:%d: %s: %s
)inspectcurrentframef_backr=   r   abspathgetsourcefile	getlinenosysstderrwriter   r   flush)r   kindmessageffileliner   r   r   _write_message   s    
zLitConfig._write_messagec              
   C   sP   z|| j  W S  tyJ } z&|j\}| d||f  W Y d}~n
d}~0 0 dS )z-substitute - Interpolate params into a stringz3unable to find %r parameter, use '--param=%s=VALUE'N)r   KeyErrorargsr0   )r   stringekeyr   r   r   
substitute   s    zLitConfig.substitutec                 C   s   | j s| d| d S )Nr3   )r   rY   r   rU   r   r   r   r3      s    zLitConfig.notec                 C   s$   | j s| d| |  jd7  _d S )NrA      )r   rY   r#   r`   r   r   r   rA      s    zLitConfig.warningc                 C   s   |  d| |  jd7  _d S )Nerrorra   )rY   r"   r`   r   r   r   rb      s    zLitConfig.errorc                 C   s   |  d| td d S )Nr0      )rY   rP   exitr`   r   r   r   r0      s    zLitConfig.fatal)__name__
__module____qualname____doc__r*   propertyr'   r-   setterr5   rD   rI   rY   r_   r3   rA   rb   r0   r   r   r   r   r      s*   
0


	r   )
__future__r   rJ   r=   platformrP   Zlit.Testr   Zlit.formatsZlit.TestingConfigZlit.utilobjectr   r   r   r   r   <module>   s   