o
    h                      @  s  U 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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
rgd dl	mZ d dlmZ eeeeee f f Zded< d4ddZd5ddZd6dd Zd7d"d#Zd8d&d'Z d(Z!d9d.d/Z"d:d2d3Z#dS );    )annotations)Iterable)SequenceN)Path)TYPE_CHECKING   )
UsageError)failabsolutepath)
commonpathsafe_exists)Union)	TypeAliasr   
ConfigDict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   Y/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/config/findpaths.py_parse_ini_config   s   r   filepathConfigDict | 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_scalarX   s   z/load_config_dict_from_file.<locals>.make_scalarc                   s   i | ]	\}}| |qS r   r   ).0kr)   r/   r   r   
<dictcomp>[   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   r=   	toml_textconfigr   resultr   r2   r   load_config_dict_from_file)   s<   

$






rF   invocation_dirargsIterable[Path]+tuple[Path | None, Path | None, ConfigDict]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)r0   xr   r   r   
<listcomp>m   s    z!locate_config.<locals>.<listcomp>NrK   )r   parentsis_filer7   rF   parent)
rG   rH   config_namesfound_pyproject_tomlargargpathbaseconfig_namep
ini_configr   r   r   locate_config`   s,   	
r[   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,   )existsrP   r   rQ   rR   )rG   r\   common_ancestorr   sharedr   r   r   get_common_ancestor   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 )NrN   r   r   boolc                 S  s
   |  dS )NrL   )rM   rN   r   r   r   	is_option   s   
z%get_dirs_from_args.<locals>.is_optionc                 S  s   |  dd S )Nz::r   )splitrd   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_dirrR   )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
   )r0   rU   )rg   re   r   r   	<genexpr>   s    

z%get_dirs_from_args.<locals>.<genexpr>c                   s   g | ]
}t |r |qS r   r   )r0   r   )ri   r   r   rO      s    z&get_dirs_from_args.<locals>.<listcomp>)rN   r   r   rc   )rN   r   r   r   )r   r   r   r   r   )rH   possible_pathsr   )ri   rg   re   r   get_dirs_from_args   s   


rl   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifile
str | NoneSequence[str]rootdir_cmd_arg$tuple[Path, Path | None, ConfigDict]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.)rl   r   rF   rR   r`   r[   rP   rQ   
is_fs_rootosr   
expandvarsrh   r   )rm   rH   rp   rG   rootdirdirsinipath_inipathinicfgancestorpossible_rootdirr   r   r   determine_setup   sB   


r|   rY   rc   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   )rs   r   
splitdriver   sep)rY   r   r   r   rr      s   rr   )r   r   r   r   )r   r   r   r   )rG   r   rH   rI   r   rJ   )rG   r   r\   rI   r   r   )rH   ra   r   rb   )
rm   rn   rH   ro   rp   rn   rG   r   r   rq   )rY   r   r   rc   )$
__future__r   collections.abcr   r   rs   pathlibr   r;   typingr   r   
exceptionsr   _pytest.outcomesr	   _pytest.pathlibr   r   r   r   typing_extensionsr   r5   r   r.   r   __annotations__r   rF   r[   r`   rl   r9   r|   rr   r   r   r   r   <module>   s2     


7
!

6