o
    Zh                      @   s  d dl 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	 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 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dee de
ee ee eeeeee f f f fddZdedee defddZdee dee fddZd Zd!ee de	e d"ee de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)Union   )
UsageError)failabsolutepath)
commonpathsafe_exists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strZ
ParseErrorr   )r   exc r   O/var/www/html/lang_env/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.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_scalarP   s   z/load_config_dict_from_file.<locals>.make_scalarc                    s   i | ]	\}}| |qS r   r   ).0kr"   r&   r   r   
<dictcomp>S   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   r4   Z	toml_textconfigr   resultr   r)   r   load_config_dict_from_file!   s<   

$





r=   invocation_dirargsc           
      C   s   g d}dd |D }|s| g}d}|D ];}t |}|g|jR D ]-}|D ](}|| }| rM|jdkr:|du r:|}t|}	|	durM|||	f      S q%q!q|durZ|j|i fS 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.inipyproject.tomlztox.inir   c                 S   s   g | ]}t |d s|qS )-)r   
startswith)r'   xr   r   r   
<listcomp>e   s    z!locate_config.<locals>.<listcomp>Nr@   )r   parentsis_filer.   r=   parent)
r>   r?   Zconfig_namesZfound_pyproject_tomlargZargpathbaseZconfig_namepZ
ini_configr   r   r   locate_configX   s,   	
rK   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 r8| }|S | r?|j}|S r#   )existsrE   r   rF   rG   )r>   rL   Zcommon_ancestorr   Zsharedr   r   r   get_common_ancestory   s(   

rN   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 )NrC   r   c                 S   s
   |  dS )NrA   )rB   rC   r   r   r   	is_option   s   
z%get_dirs_from_args.<locals>.is_optionc                 S   s   |  dd S )Nz::r   )splitrO   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_dirrG   )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'   rH   )rR   rP   r   r   	<genexpr>   s    

z%get_dirs_from_args.<locals>.<genexpr>c                    s   g | ]
}t |r |qS r   r   )r'   r   )rT   r   r   rD      s    z&get_dirs_from_args.<locals>.<listcomp>)r   boolr   )r?   Zpossible_pathsr   )rT   rR   rP   r   get_dirs_from_args   s   rW   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifilerootdir_cmd_argc                 C   s  d}t |}| rt| }|}t|pi }|du r|j}nHt||}	t||	g\}}}|du rd|du rd|	g|	jR D ]}
|
d  rE|
} nq9||	gkrSt||\}}}|du rdt|||	g}t|rd|	}|rztt	j
|}| sztd| d|dusJ |||pi fS )a  Determine the rootdir, inifile and ini configuration values from the
    command line arguments.

    :param inifile:
        The `--inifile` command line argument, if given.
    :param args:
        The free command line arguments.
    :param rootdir_cmd_arg:
        The `--rootdir` command line argument, if given.
    :param invocation_dir:
        The working directory when pytest was invoked.
    Nzsetup.pyzDirectory 'z+' not found. Check your '--rootdir' option.)rW   r   r=   rG   rN   rK   rE   rF   
is_fs_rootosr   
expandvarsrS   r   )rX   r?   rY   r>   rootdirdirsZinipath_ZinipathZinicfgZancestorZpossible_rootdirr   r   r   determine_setup   sB   


r_   rJ   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)rJ   r   r   r   rZ      s   rZ   ) r[   pathlibr   r2   typingr   r   r   r   r   r   r	   r   
exceptionsr   Z_pytest.outcomesr   Z_pytest.pathlibr   r   r   r   r   r   r=   rK   rN   rW   r0   r_   rV   rZ   r   r   r   r   <module>   sd    
7(
!
$
6