a
    *ñ»jÔ   ã                   @  sP  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
rÎd dl	mZ d dlmZ eeeeee f f Zded< dddœdd„Zdddœdd„Zddddœdd„Zddddœd d!„Zd"d#d$œd%d&„Z d'Z!d(d)d(dd*d+œd,d-„Z"dd.d/œd0d1„Z#dS )2é    )Úannotations)ÚIterable)ÚSequenceN)ÚPath)ÚTYPE_CHECKINGé   )Ú
UsageError)Úfail©Úabsolutepath)Ú
commonpath©Úsafe_exists)ÚUnion)Ú	TypeAliasr   Ú
ConfigDictr   ziniconfig.IniConfig©ÚpathÚreturnc              
   C  sJ   zt  t| ƒ¡W S  t jyD } ztt|ƒƒ|‚W Y d}~n
d}~0 0 dS )zœParse the given generic '.ini' file using legacy IniConfig parser, returning
    the parsed object.

    Raise UsageError if the file cannot be parsed.
    N)Ú	iniconfigZ	IniConfigÚstrZ
ParseErrorr   )r   Úexc© r   ú>E:\soccer\ml_env\Lib\site-packages\_pytest/config/findpaths.pyÚ_parse_ini_config   s    r   zConfigDict | None)Úfilepathr   c              
     sX  | j dkr<t| ƒ}d|v r*t|d  ¡ ƒS | jdkr8i S �n| j dkrˆt| ƒ}d|jv rht|d  ¡ ƒS d|jv r†ttjdd�dd	� nÌ| j d
k�rTt	j
dkr¨ddl}nddl}| jdd�}z| |¡}W n< |j�y } z t| › d|› �ƒ|‚W Y d}~n
d}~0 0 | di ¡ di ¡ dd¡}|du�rTdddœdd„‰ ‡ fdd„| ¡ D ƒS dS )z�Load 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Úobjectzstr | list[str])Úvr   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>[   ó    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)r   r   r6   Z	toml_textÚconfigr   Úresultr   r*   r   Úload_config_dict_from_file)   s4    






*
r>   zIterable[Path]z+tuple[Path | None, Path | None, ConfigDict])Úinvocation_dirÚargsr   c           
      C  s¾   g d¢}dd„ |D ƒ}|s | g}d}|D ]v}t |ƒ}|g|j¢R D ]Z}|D ]P}|| }| ¡ rJ|jdkrt|du rt|}t|ƒ}	|	durJ|||	f      S qJqBq(|dur´|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>m   r,   z!locate_config.<locals>.<listcomp>NrA   )r   ÚparentsÚis_filer0   r>   Úparent)
r?   r@   Zconfig_namesZfound_pyproject_tomlÚargZargpathÚbaseZconfig_nameÚpZ
ini_configr   r   r   Úlocate_config`   s&    rL   )r?   Úpathsr   c                 C  s‚   d }|D ]X}|  ¡ sq|d u r$|}q||jv s||kr:qq||jv rJ|}qt||ƒ}|d ur|}q|d u rp| }n| ¡ r~|j}|S r$   )ÚexistsrF   r   rG   rH   )r?   rM   Zcommon_ancestorr   Zsharedr   r   r   Úget_common_ancestor�   s$    

rO   zIterable[str]z
list[Path])r@   r   c                   sV   dddœdd„‰dddœdd„‰ddd	œd
d„‰ ‡‡fdd„| D ƒ}‡ fdd„|D ƒS )Nr   Úbool)rD   r   c                 S  s
   |   d¡S )NrB   )rC   ©rD   r   r   r   Ú	is_optionœ   s    z%get_dirs_from_args.<locals>.is_optionc                 S  s   |   d¡d S )Nz::r   )ÚsplitrQ   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_dirrH   )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(   rI   )rT   rR   r   r   Ú	<genexpr>¨   s   þz%get_dirs_from_args.<locals>.<genexpr>c                   s   g | ]}t |ƒrˆ |ƒ‘qS r   r   )r(   r   )rV   r   r   rE   ®   r,   z&get_dirs_from_args.<locals>.<listcomp>r   )r@   Zpossible_pathsr   )rV   rT   rR   r   Úget_dirs_from_args›   s    þrX   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.z
str | NonezSequence[str]z$tuple[Path, Path | None, ConfigDict])Úinifiler@   Úrootdir_cmd_argr?   r   c                 C  s  d}t |ƒ}| r8t| ƒ}|}t|ƒp&i }|du rÈ|j}n�t||ƒ}	t||	gƒ\}}}|du rÈ|du rÈ|	g|	j¢R D ]}
|
d  ¡ rr|
} qÈqr||	gkr¦t||ƒ\}}}|du rÈt|||	gƒ}t|ƒrÈ|	}|rôtt	j
 |¡ƒ}| ¡ sôtd|› d�ƒ‚|du�sJ ‚|||�pi 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.)rX   r   r>   rH   rO   rL   rF   rG   Ú
is_fs_rootÚosr   Ú
expandvarsrU   r   )rY   r@   rZ   r?   ÚrootdirÚdirsZinipath_ZinipathZinicfgZancestorZpossible_rootdirr   r   r   Údetermine_setup´   s>    

ÿ
ÿr`   rP   )rK   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   )r\   r   Ú
splitdriver   Úsep)rK   r   r   r   r[   ê   s    r[   )$Ú
__future__r   Úcollections.abcr   r   r\   Úpathlibr   r4   Útypingr   r   Ú
exceptionsr   Z_pytest.outcomesr	   Z_pytest.pathlibr   r   r   r   Ztyping_extensionsr   r.   r   r&   r   Ú__annotations__r   r>   rL   rO   rX   r2   r`   r[   r   r   r   r   Ú<module>   s0    7!6