a
    /§»aÿ  ã                   @   s®  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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 e
r¼ddlmZ eejdœdd„Zeeeeeeee f f  dœdd„Zee e	ee ee eeeeee f f f dœdd„Zee edœdd„Zee ee dœdd„ZdZd$ee ee ee ed  e	eee eeeeee f f f d!œd"d#„ZdS )%é    N)ÚPath)ÚDict)ÚIterable)ÚList)ÚOptional)ÚSequence)ÚTuple)ÚTYPE_CHECKING)ÚUnioné   )Ú
UsageError)Úfail©Úabsolutepath)Ú
commonpath)ÚConfig©Ú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)Ú	iniconfigÚ	IniConfigÚstrÚ
ParseErrorr   )r   Úexc© r   úR/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/_pytest/config/findpaths.pyÚ_parse_ini_config   s    r   )Úfilepathr   c                    s  | 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 rft|d  ¡ ƒS d|jv r„ttjdd�dd	� nz| j d
k�r ddl	}| 
t| ƒ¡}| di ¡ di ¡ dd¡}|du�r ttttt f 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.tomlr   NZtoolZini_options)Úvr   c                 S   s   t | tƒr| S t| ƒS ©N)Ú
isinstanceÚlistr   )r!   r   r   r   Úmake_scalarL   s    z/load_config_dict_from_file.<locals>.make_scalarc                    s   i | ]\}}|ˆ |ƒ“qS r   r   )Ú.0Úkr!   ©r%   r   r   Ú
<dictcomp>O   ó    z.load_config_dict_from_file.<locals>.<dictcomp>)Úsuffixr   ÚdictÚitemsÚnameÚsectionsr   ÚCFG_PYTEST_SECTIONÚformatÚtomlÚloadr   ÚgetÚobjectr
   r   )r   r   r2   ÚconfigÚresultr   r(   r   Úload_config_dict_from_file#   s(    	





r8   )Úargsr   c                 C   s”   g d¢}dd„ | D ƒ} | s$t  ¡ g} | D ]`}t|ƒ}|g|j¢R D ]D}|D ]:}|| }| ¡ rJt|ƒ}|durJ|||f      S qJqBq(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pyproject.tomlztox.inir   c                 S   s   g | ]}t |ƒ d ¡s|‘qS )ú-)r   Ú
startswith)r&   Úxr   r   r   Ú
<listcomp>a   r*   z!locate_config.<locals>.<listcomp>N)r   Úcwdr   ÚparentsÚis_filer8   )r9   Zconfig_namesÚargZargpathÚbaseZconfig_nameÚpZ
ini_configr   r   r   Úlocate_configT   s    
rD   )Ú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 rtt ¡ }n| ¡ r‚|j}|S r"   )Úexistsr?   r   r   r>   r@   Úparent)rE   Zcommon_ancestorr   Zsharedr   r   r   Úget_common_ancestorp   s$    


rH   c                    sh   t tdœdd„‰t t dœdd„‰ttdœdd„‰ ttdœd	d
„‰‡‡fdd„| D ƒ}‡ ‡fdd„|D ƒS )N)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   )ÚsplitrI   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                 S   s$   z
|   ¡ W S  ty   Y dS 0 d S )NF)rF   ÚOSErrorrN   r   r   r   Úsafe_exists“   s    
z'get_dirs_from_args.<locals>.safe_existsc                 3   s"   | ]}ˆ|ƒst ˆ |ƒƒV  qd S r"   r   )r&   rA   )rL   rJ   r   r   Ú	<genexpr>œ   s   þz%get_dirs_from_args.<locals>.<genexpr>c                    s   g | ]}ˆ|ƒrˆ |ƒ‘qS r   r   )r&   r   )rO   rQ   r   r   r=   ¢   r*   z&get_dirs_from_args.<locals>.<listcomp>)r   Úboolr   )r9   Zpossible_pathsr   )rO   rL   rJ   rQ   r   Úget_dirs_from_args‡   s    	þrT   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.r   )Úinifiler9   Úrootdir_cmd_argr6   r   c                 C   s<  d }t |ƒ}| r:t| ƒ}|}t|ƒp&i }|d u rðt|ƒ}n¶t|ƒ}	t|	gƒ\}}}|d u rð|d u rð|	g|	j¢R D ]}
|
d  ¡ rp|
} qðqp||	gkr¢t|ƒ\}}}|d u rð|d ur¼|jj}nt	 
¡ }t||	gƒ}tj t|ƒ¡d dk}|rð|	}|�rttj |¡ƒ}| ¡ �std |¡ƒ‚|d u�s,J ‚|||�p8i fS )Nzsetup.pyr   ú/z8Directory '{}' not found. Check your '--rootdir' option.)rT   r   r8   rH   rD   r?   r@   Zinvocation_paramsÚdirr   r>   Úosr   Ú
splitdriver   Ú
expandvarsrM   r   r1   )rU   r9   rV   r6   ÚrootdirÚdirsZinipath_ZinipathZinicfgZancestorZpossible_rootdirr>   Z
is_fs_rootr   r   r   Údetermine_setup¨   sF    



ÿÿr^   )NN)rY   Úpathlibr   Útypingr   r   r   r   r   r   r	   r
   r   Ú
exceptionsr   Z_pytest.outcomesr   Z_pytest.pathlibr   r   Ú r   r   r   r   r8   rD   rH   rT   r0   r^   r   r   r   r   Ú<module>   sJ   þ2$ÿþ  ü$û