o
    rh~                     @  s   d dl mZ 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	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dZd0ddZd1ddZd2ddZd3d!d"Zd#Zd4d)d*Zd5d-d.ZdS )6    )annotationsN)Path)Iterable)Sequence   )
UsageError)failabsolutepath)
commonpathsafe_existspathr   returniniconfig.IniConfigc              
   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   V/var/www/html/alpaca_bot/venv/lib/python3.10/site-packages/_pytest/config/findpaths.py_parse_ini_config   s   r   filepath!dict[str, str | list[str]] | Nonec              
     sB  | 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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vobjectr   str | list[str]c                 S  s   t | tr| S t| S N)
isinstancelistr   )r%   r   r   r   make_scalarM   s   z/load_config_dict_from_file.<locals>.make_scalarc                   s   i | ]	\}}| |qS r   r   ).0kr%   r+   r   r   
<dictcomp>P   s    z.load_config_dict_from_file.<locals>.<dictcomp>)r%   r&   r   r'   )suffixr   dictitemsnamesectionsr   CFG_PYTEST_SECTIONformatsysversion_infotomllibtomli	read_textloadsTOMLDecodeErrorr   get)r   r   r9   	toml_textconfigr   resultr   r.   r   load_config_dict_from_file   s<   

$






rB   invocation_dirargsIterable[Path];tuple[Path | None, Path | None, dict[str, str | list[str]]]c           
      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>b   s    z!locate_config.<locals>.<listcomp>NrG   )r
   parentsis_filer3   rB   parent)
rC   rD   config_namesfound_pyproject_tomlargargpathbaseconfig_namep
ini_configr   r   r   locate_configU   s,   	
rW   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(   )existsrL   r   rM   rN   )rC   rX   common_ancestorr   sharedr   r   r   get_common_ancestorv   s(   

r\   Iterable[str]
list[Path]c                   sD   ddddddddd fdd| D } fdd|D S )NrJ   r   r   boolc                 S  s
   |  dS )NrH   )rI   rJ   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   r   c                 S  s   |   r| S | jS r(   )is_dirrN   )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,   rQ   )rc   ra   r   r   	<genexpr>   s    

z%get_dirs_from_args.<locals>.<genexpr>c                   s   g | ]
}t |r |qS r   r   )r,   r   )re   r   r   rK      s    z&get_dirs_from_args.<locals>.<listcomp>)rJ   r   r   r_   )rJ   r   r   r   )r   r   r   r   r   )rD   possible_pathsr   )re   rc   ra   r   get_dirs_from_args   s   


rh   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifile
str | NoneSequence[str]rootdir_cmd_arg4tuple[Path, Path | None, dict[str, str | list[str]]]c                 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.)rh   r
   rB   rN   r\   rW   rL   rM   
is_fs_rootosr   
expandvarsrd   r   )ri   rD   rl   rC   rootdirdirsinipath_inipathinicfgancestorpossible_rootdirr   r   r   determine_setup   sB   


rx   rU   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   )ro   r   
splitdriver   sep)rU   r   r   r   rn      s   rn   )r   r   r   r   )r   r   r   r   )rC   r   rD   rE   r   rF   )rC   r   rX   rE   r   r   )rD   r]   r   r^   )
ri   rj   rD   rk   rl   rj   rC   r   r   rm   )rU   r   r   r_   )
__future__r   ro   pathlibr   r7   typingr   r   r   
exceptionsr   _pytest.outcomesr   _pytest.pathlibr
   r   r   r   rB   rW   r\   rh   r5   rx   rn   r   r   r   r   <module>   s(    


7
!

6