B
    `                 @   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
rd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   sF   yt t| S  t jk
r@ } ztt||W dd}~X Y nX dS )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   `/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/_pytest/config/findpaths.py_parse_ini_config   s    r   )filepathr   c                s  | j dkr:t| }d|kr*t|d  S | jdkr8i S n| j dkrt| }d|jkrft|d  S d|jkrttjdddd	 nz| j d
kr ddl	}|
t| }|di di dd}|dk	r ttttt f d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.iniZpytestz
pytest.iniz.cfgztool:pytestz	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   s    z.load_config_dict_from_file.<locals>.<dictcomp>)suffixr   dictitemsnamesectionsr   CFG_PYTEST_SECTIONformattomlloadr   getobjectr
   r   )r   r   r+   configresultr   )r    r   load_config_dict_from_file#   s(    	





r1   )argsr   c             C   s   ddddg}dd | D } | s(t  g} xb| D ]Z}t|}xL|f|jD ]<}x6|D ].}|| }| rRt|}|dk	rR|||fS qRW qHW q.W 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).z
pytest.inizpyproject.tomlztox.iniz	setup.cfgc             S   s   g | ]}t |d s|qS )-)r   
startswith)r!   xr   r   r   
<listcomp>a   s    z!locate_config.<locals>.<listcomp>N)r   cwdr   parentsis_filer1   )r2   Zconfig_namesargZargpathbaseZconfig_namepZ
ini_configr   r   r   locate_configT   s"    


r=   )pathsr   c             C   s   d }x`| D ]X}|  sq
|d kr&|}q
||jks
||kr<q
q
||jkrL|}q
t||}|d k	r
|}q
W |d krxt }n| r|j}|S )N)existsr8   r   r   r7   r9   parent)r>   Zcommon_ancestorr   Zsharedr   r   r   get_common_ancestorp   s$    



rA   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)r5   r   c             S   s
   |  dS )Nr3   )r4   )r5   r   r   r   	is_option   s    z%get_dirs_from_args.<locals>.is_optionc             S   s   |  dd S )Nz::r   )split)r5   r   r   r   get_file_part_from_node_id   s    z6get_dirs_from_args.<locals>.get_file_part_from_node_id)r   r   c             S   s   |   r| S | jS )N)is_dirr@   )r   r   r   r   get_dir_from_path   s    z-get_dirs_from_args.<locals>.get_dir_from_pathc             S   s"   y|   S  tk
r   dS X d S )NF)r?   OSError)r   r   r   r   safe_exists   s    z'get_dirs_from_args.<locals>.safe_existsc             3   s"   | ]}|st  |V  qd S )N)r   )r!   r:   )rD   rB   r   r   	<genexpr>   s   z%get_dirs_from_args.<locals>.<genexpr>c                s   g | ]}|r |qS r   r   )r!   r   )rF   rH   r   r   r6      s    z&get_dirs_from_args.<locals>.<listcomp>)r   boolr   )r2   Zpossible_pathsr   )rF   rD   rB   rH   r   get_dirs_from_args   s    
rK   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.r   )inifiler2   rootdir_cmd_argr/   r   c             C   s<  d }t |}| r:t| }|}t|p&i }|d krt|}nt|}	t|	g\}}}|d kr|d krx|	f|	jD ]}
|
d  rp|
}P qpW ||	gkrt|\}}}|d kr|d k	r|jj}nt	
 }t||	g}tjt|d dk}|r|	}|rttj|}| std||d k	s,t|||p8i fS )Nzsetup.pyr   /z8Directory '{}' not found. Check your '--rootdir' option.)rK   r   r1   rA   r=   r8   r9   Zinvocation_paramsdirr   r7   osr   
splitdriver   
expandvarsrE   r   r*   AssertionError)rL   r2   rM   r/   rootdirdirsZinipath_ZinipathZinicfgZancestorZpossible_rootdirr7   Z
is_fs_rootr   r   r   determine_setup   sB    



rV   )NN)rP   pathlibr   typingr   r   r   r   r   r   r	   r
   r   
exceptionsr   Z_pytest.outcomesr   Z_pytest.pathlibr   r    r   r   r   r   r1   r=   rA   rK   r)   rV   r   r   r   r   <module>   s8   &02 