U
    `»{j~  ã                   @  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œ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*œd+d,„ZdS )-é    )ÚannotationsN)ÚPath)ÚIterable)ÚSequenceé   )Ú
UsageError)Úfail©Úabsolutepath)Ú
commonpath©Úsafe_existsr   ziniconfig.IniConfig©ÚpathÚreturnc              
   C  sH   zt  t| ƒ¡W S  t jk
rB } ztt|ƒƒ|‚W 5 d}~X Y nX 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   úW/var/www/html/bwave/python/venv/lib/python3.8/site-packages/_pytest/config/findpaths.pyÚ_parse_ini_config   s    r   z!dict[str, str | list[str]] | None)Úfilepathr   c              
     sV  | j dkr<t| ƒ}d|kr*t|d  ¡ ƒS | jdkr8i S �n| j dkrˆt| ƒ}d|jkrht|d  ¡ ƒS d|jkr†ttjdd�dd	� nÊ| j d
k�rRt	j
dkr¨ddl}nddl}| jdd�}z| |¡}W n: |jk
�r } zt| › d|› �ƒ|‚W 5 d}~X Y nX | di ¡ di ¡ dd¡}|dk	�rRd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_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>)Úsuffixr   ÚdictÚitemsÚnameÚsectionsr   ÚCFG_PYTEST_SECTIONÚformatÚsysÚversion_infoÚtomllibÚtomliÚ	read_textÚloadsÚTOMLDecodeErrorr   Úget)r   r   r1   Z	toml_textÚconfigr   Úresultr   r&   r   Úload_config_dict_from_file   s4    






&
r9   zIterable[Path]z;tuple[Path | None, Path | None, dict[str, str | list[str]]])Úinvocation_dirÚargsr   c           
      C  sÂ   dddddg}dd„ |D ƒ}|s&| g}d}|D ]t}t |ƒ}|f|j˜D ]Z}|D ]P}|| }| ¡ rN|jdkrx|dkrx|}t|ƒ}	|	dk	rN|||	f      S qNqFq.|dk	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.iniz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>N)r
   ÚparentsÚis_filer+   r9   Úparent)
r:   r;   Zconfig_namesZfound_pyproject_tomlÚargZargpathÚbaseZconfig_nameÚpZ
ini_configr   r   r   Úlocate_configU   s0    ûrF   )r:   Úpathsr   c                 C  s‚   d }|D ]X}|  ¡ sq|d kr$|}q||jks||kr:qq||jkrJ|}qt||ƒ}|d k	r|}q|d krp| }n| ¡ r~|j}|S r    )Úexistsr@   r   rA   rB   )r:   rG   Zcommon_ancestorr   Zsharedr   r   r   Úget_common_ancestorv   s$    

rI   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)r>   r   c                 S  s
   |   d¡S )Nr<   )r=   ©r>   r   r   r   Ú	is_option‘   s    z%get_dirs_from_args.<locals>.is_optionc                 S  s   |   d¡d S )Nz::r   )ÚsplitrK   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_dirrB   )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$   rC   )rN   rL   r   r   Ú	<genexpr>�   s   þz%get_dirs_from_args.<locals>.<genexpr>c                   s   g | ]}t |ƒrˆ |ƒ‘qS r   r   )r$   r   )rP   r   r   r?   £   s      z&get_dirs_from_args.<locals>.<listcomp>r   )r;   Zpossible_pathsr   )rP   rN   rL   r   Úget_dirs_from_args�   s    þrR   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.z
str | NonezSequence[str]z4tuple[Path, Path | None, dict[str, str | list[str]]])Úinifiler;   Úrootdir_cmd_argr:   r   c                 C  s  d}t |ƒ}| r8t| ƒ}|}t|ƒp&i }|dkrÆ|j}nŽt||ƒ}	t||	gƒ\}}}|dkrÆ|dkrÆ|	f|	j˜D ]}
|
d  ¡ rp|
} qÆqp||	gkr¤t||ƒ\}}}|dkrÆt|||	gƒ}t|ƒrÆ|	}|ròtt	j
 |¡ƒ}| ¡ sòtd|› d�ƒ‚|dk	sþt‚|||�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.)rR   r
   r9   rB   rI   rF   r@   rA   Ú
is_fs_rootÚosr   Ú
expandvarsrO   r   ÚAssertionError)rS   r;   rT   r:   ÚrootdirÚdirsZinipath_ZinipathZinicfgZancestorZpossible_rootdirr   r   r   Údetermine_setup©   s@    

 ÿ
ÿr[   rJ   )rE   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   )rV   r   Ú
splitdriver   Úsep)rE   r   r   r   rU   ß   s    rU   )Ú
__future__r   rV   Úpathlibr   r/   Útypingr   r   r   Ú
exceptionsr   Z_pytest.outcomesr   Z_pytest.pathlibr
   r   r   r   r9   rF   rI   rR   r-   r[   rU   r   r   r   r   Ú<module>   s&   7!6