o
    h                     @   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rhddlmZ dedejfddZdedeeeeeee f f  fddZdee de
ee ee eeeeee f f f fddZdee defddZdee dee fdd Zd!Z		d+d"ee de	e d#ee d$ed% de
eee eeeeee f f f f
d&d'Z d(ede!f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   s:   zt t| W S  t jy } ztt||d}~ww )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str
ParseErrorr   )r   exc r   N/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/config/findpaths.py_parse_ini_config   s   r   filepathc              
      sV  | j dkrt| }d|v rt|d  S | jdkri S dS | j dkrEt| }d|jv r4t|d  S d|jv rCttjdddd	 dS | j d
krt	j
dkrTddl}nddl}| jdd}z||}W n |jy| } z
t|  d| |d}~ww |di di dd}|durdtdtttt f f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.inipytest
pytest.iniz.cfgztool:pytest	setup.cfg)filenameF)pytracez.toml)      r   Nzutf-8)encodingz: tool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   s    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   r;   	toml_textconfigr   resultr   r0   r   load_config_dict_from_file%   s<   
	
$





rE   argsc                 C   s   g d}dd | D } | st  g} | D ]0}t|}|g|jR D ]"}|D ]}|| }| rBt|}|durB|||f      S q%q!q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   s    z!locate_config.<locals>.<listcomp>N)r   cwdr   parentsis_filerE   )rF   config_namesargargpathbaseconfig_namep
ini_configr   r   r   locate_config]   s"   

rU   pathsc                 C   s   d }| D ]+}|  sq|d u r|}q||jv s||krq||jv r$|}qt||}|d ur/|}q|d u r:t }|S | rA|j}|S r*   )existsrL   r   r   rK   rM   parent)rV   common_ancestorr   sharedr   r   r   get_common_ancestorx   s(   

r[   c                    s\   dt dtfdddt dt fdddtdtfdd	 fd
d| D } fdd|D S )NrI   r   c                 S   s
   |  dS )NrG   )rH   rI   r   r   r   	is_option   s   
z%get_dirs_from_args.<locals>.is_optionc                 S   s   |  dd S )Nz::r   )splitr\   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_dirrX   )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.   rO   )r_   r]   r   r   	<genexpr>   s    

z%get_dirs_from_args.<locals>.<genexpr>c                    s   g | ]
}t |r |qS r   r   )r.   r   )ra   r   r   rJ      s    z&get_dirs_from_args.<locals>.<listcomp>)r   boolr   )rF   possible_pathsr   )ra   r_   r]   r   get_dirs_from_args   s   re   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifilerootdir_cmd_argrC   r   c                 C   s  d }t |}| rt| }|}t|pi }|d u r|j}nQt|}	t|	g\}}}|d u rm|d u rm|	g|	jR D ]}
|
d  rC|
} n*q7||	gkrPt|\}}}|d u rm|d ur]|jj	}nt
 }t||	g}t|rm|	}|rttj|}| std||d usJ |||pi fS )Nzsetup.pyz8Directory '{}' not found. Check your '--rootdir' option.)re   r   rE   rX   r[   rU   rL   rM   invocation_paramsdirr   rK   
is_fs_rootosr   
expandvarsr`   r   r8   )rf   rF   rg   rC   rootdirdirsinipath_inipathinicfgancestorpossible_rootdirrK   r   r   r   determine_setup   sH   

rt   rS   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   )rk   r   
splitdriver   sep)rS   r   r   r   rj      s   rj   )NN)#rk   r9   pathlibr   typingr   r   r   r   r   r   r	   r
   r   
exceptionsr   _pytest.outcomesr   _pytest.pathlibr   r   r    r   r   r   r   rE   rU   r[   re   r7   rt   rc   rj   r   r   r   r   <module>   s^    
8(
$
-