
    d                        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 erddlmZ dedej        fdZdedeeeeeee         f         f                  fdZdee         de
ee         ee         eeeeee         f         f         f         fdZdee         defdZdee         dee         f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 Zd!ede fd"Z!dS )$    N)Path)Dict)Iterable)List)Optional)Sequence)Tuple)TYPE_CHECKING)Union   )
UsageError)failabsolutepath)
commonpath)Configpathreturnc                     	 t          j        t          |                     S # t           j        $ r"}t	          t          |                    |d}~ww xY 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   excs     8lib/python3.11/site-packages/_pytest/config/findpaths.py_parse_ini_configr      sV    ,"3t99--- , , ,S""+,s    # AAAfilepathc                    | j         dk    rIt          |           }d|v r't          |d                                                   S | j        dk    ri S n| j         dk    rtt          |           }d|j        v r't          |d                                                   S d|j        v r*t          t                              d          d	           n| j         d
k    rt          j
        dk    rddl}nddl}|                     d          }	 |                    |          }n'# |j        $ r}t!          |  d|           |d}~ww xY w|                    di                               di                               dd          }|Odt$          dt&          t(          t*          t(                   f         fdf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                 N    t          | t                    r| nt          |           S N)
isinstancelistr   )r)   s    r   make_scalarz/load_config_dict_from_file.<locals>.make_scalarT   s!    &q$//;qqSVV;    c                 .    i | ]\  }}| |          S  r1   ).0kr)   r.   s      r   
<dictcomp>z.load_config_dict_from_file.<locals>.<dictcomp>W   s'    AAA$!QA{{1~~AAAr/   )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.   s          @r   load_config_dict_from_filerH   $   s    &  %h//	y  	(+1133444 },,	 - 
F	"	"%h//	I...	-06688999+++ #**K*@@%PPPP 
G	#	#w&&NNNN####&&&88		<]]9--FF& 	< 	< 	<11C1122;	< FB''++Hb99==mTRR<v <%T#Y*? < < < < BAAA&,,..AAAA4s   D& &
E
0EE
argsc                    g d}d | D             } | st          j                    g} | D ]Y}t          |          }|g|j        R D ]<}|D ]7}||z  }|                                rt          |          }||||fc c c S 8=Zd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                 V    g | ]&}t          |                              d           $|'S )-)r   
startswith)r2   xs     r   
<listcomp>z!locate_config.<locals>.<listcomp>h   s1    :::!3q66#4#4S#9#9:A:::r/   N)r   cwdr   parentsis_filerH   )rI   config_namesargargpathbaseconfig_namep
ini_configs           r   locate_configrZ   \   s    
  L ;:t:::D 

| 3 3s##/w// 	3 	3D+ 3 3;&99;; 3!;A!>!>J!-#Q
222222223	3 r>r/   pathsc                 
   d }| D ]L}|                                 s||}||j        v s||k    r,||j        v r|}8t          ||          }||}M|t          j                    }n|                                r|j        }|S r+   )existsrQ   r   r   rP   rR   parent)r[   common_ancestorr   shareds       r   get_common_ancestorra   w   s    &*O - -{{}} 	""OO$,..$/2I2I000"&#D/::%&,O(**		 	 	"	" 1)0r/   c                     dt           dt          fddt           dt           fddt          dt          fddt          dt          fdfd| D             }fd	|D             S )
NrN   r   c                 ,    |                      d          S )NrL   )rM   rN   s    r   	is_optionz%get_dirs_from_args.<locals>.is_option   s    ||C   r/   c                 8    |                      d          d         S )Nz::r   )splitrd   s    r   get_file_part_from_node_idz6get_dirs_from_args.<locals>.get_file_part_from_node_id   s    wwt}}Qr/   r   c                 <    |                                  r| S | j        S r+   )is_dirr^   r   s    r   get_dir_from_pathz-get_dirs_from_args.<locals>.get_dir_from_path   s    ;;== 	K{r/   c                 N    	 |                                  S # t          $ r Y dS w xY w)NF)r]   OSErrorrk   s    r   safe_existsz'get_dirs_from_args.<locals>.safe_exists   s7    	;;==  	 	 	55	s    
$$c              3   ^   K   | ]'} |          t           |                    V  (d S r+   r   )r2   rT   rh   re   s     r   	<genexpr>z%get_dirs_from_args.<locals>.<genexpr>   sY        y~~//4455     r/   c                 <    g | ]} |           |          S r1   r1   )r2   r   rl   ro   s     r   rO   z&get_dirs_from_args.<locals>.<listcomp>   s4    TTT++dBSBSTd##TTTr/   )r   boolr   )rI   possible_pathsrl   rh   re   ro   s     @@@@r   get_dirs_from_argsru      s    !S !T ! ! ! ! c  c             
$ 4          N UTTTTTTTTr/   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifilerootdir_cmd_argrF   r   c                    d }t          |          }| r,t          |           }|}t          |          pi }||j        }nt	          |          }	t          |	g          \  }}}|||	g|	j        R D ]}
|
dz                                  r|
} na||	gk    rt          |          \  }}}|D||j        j	        }nt          j                    }t	          ||	g          }t          |          r|	}|rbt          t          j                            |                    }|                                s"t#          d                    |                    |J |||pi fS )Nzsetup.pyz8Directory '{}' not found. Check your '--rootdir' option.)ru   r   rH   r^   ra   rZ   rQ   rR   invocation_paramsdirr   rP   
is_fs_rootosr   
expandvarsrj   r   r;   )rv   rI   rw   rF   rootdirdirsinipath_inipathinicfgancestorpossible_rootdirrP   s               r   determine_setupr      s    Gd##D +(("*+H55;"oG&t,,#0(#<#< &?6%-$A0@$A$A + + $z1::<< .GE H:%%/<T/B/B,GWf?)$6:"hjj13/BBG!'** +"* rw11/BBCC~~ 	JQQ   
 GV\r))r/   rX   c                     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)rX   s    r   r{   r{      s,    
 7c!ff%%a(BF22r/   )NN)"r|   r<   pathlibr   typingr   r   r   r   r   r	   r
   r   r   
exceptionsr   _pytest.outcomesr   _pytest.pathlibr   r    r   r   r   r   rH   rZ   ra   ru   r:   r   rs   r{   r1   r/   r   <module>r      s   				 



                                                                 " " " " " " ! ! ! ! ! ! ( ( ( ( ( ( & & & & & & 	,D 	,Y%8 	, 	, 	, 	,55d3c49n--./5 5 5 5p
4.
8D>8D>4U3S	>5J0J+KKL   6x~ $    .UXc] UtDz U U U U< u  &*!%	** **c]**
3-** c]** X	**
 4$c5d3i+@&@!AAB** ** ** **Z3$ 34 3 3 3 3 3 3r/   