a
    !f                     @   s  d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d d	lmZ d d
lmZ d dlZddlmZ d dlmZ d dlmZ d dlmZ d dlmZ erddlmZ eejdddZeeeeeeee f f  dddZee e
ee ee eeeeee f f f dddZee edddZee ee dddZd Zd(ee e	e ee ed! e
eee eeeeee f f f d"d#d$Z ee!d%d&d'Z"dS ))    N)Path)Dict)Iterable)List)Optional)Sequence)Tuple)TYPE_CHECKING)Union   )
UsageError)failabsolutepath)
commonpathsafe_exists)Configpathreturnc              
   C   sJ   zt t| W S  t jyD } ztt||W Y d}~n
d}~0 0 dS )zParse the given generic '.ini' file using legacy IniConfig parser, returning
    the parsed object.

    Raise UsageError if the file cannot be parsed.
    N)	iniconfig	IniConfigstrZ
ParseErrorr   )r   exc r   Y/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/config/findpaths.py_parse_ini_config   s    r   )filepathr   c              
      sd  | j dkr<t| }d|v r*t|d  S | jdkr8i S n$| j dkrt| }d|jv rht|d  S d|jv rttjdddd	 n| j d
kr`t	j
dkrddl}nddl}| jdd}z||}W n< |jy } z t|  d| |W Y d}~n
d}~0 0 |di di dd}|dur`ttttt f ddd  fdd| D S dS )zLoad pytest configuration from the given file path, if supported.

    Return None if the file does not contain valid pytest configuration.
    z.iniZpytest
pytest.iniz.cfgztool:pytest	setup.cfg)filenameF)Zpytracez.toml)      r   Nzutf-8)encodingz: ZtoolZini_options)vr   c                 S   s   t | tr| S t| S N)
isinstancelistr   )r%   r   r   r   make_scalarU   s    z/load_config_dict_from_file.<locals>.make_scalarc                    s   i | ]\}}| |qS r   r   ).0kr%   r)   r   r   
<dictcomp>X       z.load_config_dict_from_file.<locals>.<dictcomp>)suffixr   dictitemsnamesectionsr   CFG_PYTEST_SECTIONformatsysversion_infotomllibtomli	read_textloadsTOMLDecodeErrorr   getobjectr
   r   r   )r   r   r8   Z	toml_textconfigr   resultr   r,   r   load_config_dict_from_file%   s4    	






*
rA   )argsr   c                 C   s   g d}dd | D } | s$t  g} | D ]`}t|}|g|jR D ]D}|D ]:}|| }| rJt|}|durJ|||f      S qJqBq(ddi fS )zxSearch in the list of arguments for a valid ini-file for pytest,
    and return a tuple of (rootdir, inifile, cfg-dict).)r   z.pytest.inizpyproject.tomlztox.inir    c                 S   s   g | ]}t |d s|qS )-)r   
startswith)r*   xr   r   r   
<listcomp>i   r.   z!locate_config.<locals>.<listcomp>N)r   cwdr   parentsis_filerA   )rB   Zconfig_namesargZargpathbaseZconfig_namepZ
ini_configr   r   r   locate_config]   s    
rM   )pathsr   c                 C   s   d }| D ]X}|  sq|d u r$|}q||jv s||kr:qq||jv rJ|}qt||}|d ur|}q|d u rtt }n| r|j}|S r&   )existsrH   r   r   rG   rI   parent)rN   Zcommon_ancestorr   Zsharedr   r   r   get_common_ancestorx   s$    


rQ   c                    sV   t tdddt t dddttddd fd	d
| D } fdd|D S )N)rE   r   c                 S   s
   |  dS )NrC   )rD   rE   r   r   r   	is_option   s    z%get_dirs_from_args.<locals>.is_optionc                 S   s   |  dd S )Nz::r   )splitrR   r   r   r   get_file_part_from_node_id   s    z6get_dirs_from_args.<locals>.get_file_part_from_node_idr   c                 S   s   |   r| S | jS r&   )is_dirrP   )r   r   r   r   get_dir_from_path   s    z-get_dirs_from_args.<locals>.get_dir_from_pathc                 3   s"   | ]}|st  |V  qd S r&   r   )r*   rJ   )rU   rS   r   r   	<genexpr>   s   z%get_dirs_from_args.<locals>.<genexpr>c                    s   g | ]}t |r |qS r   r   )r*   r   )rW   r   r   rF      r.   z&get_dirs_from_args.<locals>.<listcomp>)r   boolr   )rB   Zpossible_pathsr   )rW   rU   rS   r   get_dirs_from_args   s    rZ   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.r   )inifilerB   rootdir_cmd_argr?   r   c                 C   s&  d }t |}| r8t| }|}t|p&i }|d u r|j}nt|}	t|	g\}}}|d u r|d u r|	g|	jR D ]}
|
d  rn|
} qqn||	gkrt|\}}}|d u r|d ur|jj	}nt
 }t||	g}t|r|	}|rttj|}| std||d usJ |||p"i fS )Nzsetup.pyz8Directory '{}' not found. Check your '--rootdir' option.)rZ   r   rA   rP   rQ   rM   rH   rI   Zinvocation_paramsdirr   rG   
is_fs_rootosr   
expandvarsrV   r   r5   )r[   rB   r\   r?   rootdirdirsZinipath_ZinipathZinicfgZancestorZpossible_rootdirrG   r   r   r   determine_setup   sD    


rc   )rL   r   c                 C   s   t jt| d t jkS )z
    Return True if the given path is pointing to the root of the
    file system ("/" on Unix and "C:\\" on Windows for example).
    r   )r_   r   
splitdriver   sep)rL   r   r   r   r^      s    r^   )NN)#r_   r6   pathlibr   typingr   r   r   r   r   r   r	   r
   r   
exceptionsr   Z_pytest.outcomesr   Z_pytest.pathlibr   r   r    r   r   r   r   rA   rM   rQ   rZ   r4   rc   rY   r^   r   r   r   r   <module>   sL   9(  $-