a
    =aU                     @   s   d dl Z d dlZd dlmZmZmZ d dlmZ dddZe	e	dddZ
e	ee ed	d
dZee	 ee	 ee ee eee ee f dddZdS )    N)ListPatternTuple)modutilsc                    s    fdd}t j| ||dS )Nc                    s   t | |p S )N)r   Zcheck_modpath_has_init)pathpartsis_namespace 9lib/python3.9/site-packages/pylint/lint/expand_modules.py_is_package_cb	   s    z*_modpath_from_file.<locals>._is_package_cb)r   Zis_package_cb)r   Zmodpath_from_file_with_callback)filenamer	   r   r   r
   r   r   _modpath_from_file   s    r   )filepathreturnc                 C   sl   t jt j| }t j|s,t j|}t jt j|dsF|S |}t j|}||kr,t  S q,dS )zTODO This get the python path with the (bad) assumption that there is always
    an __init__.py. This is not true since python 3.3 and is causing problem.__init__.pyN)	osr   realpath
expanduserisdirdirnameexistsjoingetcwd)r   r   Zold_dirnamer
   r
   r   get_python_path   s    r   )elementignore_list_rer   c                 C   s   |D ]}| | r dS qdS )z;determines if the element is matched in a regex ignore-listTF)match)r   r   Zfile_patternr
   r
   r   _is_in_ignore_list_re    s    
r   )files_or_modulesignore_listr   ignore_list_paths_rer   c                 C   s  g }g }t j }| D ]b}tj|}||v sttj||st||rNqt|}	d|	g| }
tj|rzdt	j
||
d}W n" ty   tj|d }Y n0 tj|rtj|d}n|}nr|}z$t	j|d|
d}|du rW qW nH ttfy< } z*|d||d W Y d}~qW Y d}~n
d}~0 0 tj|}|pR|d}zt	j||
d}W n$ ty   d}tj|}Y n0 t	|}t	|}|s|||d	||d
 |dp|dk otj|dk}|s|s|rt	jtj|||dD ]f}||kr$qttj||st||rHqt|||
d}d|}|||d||d
 qq||fS )ztake a list of files/modules/packages and return the list of tuple
    (file, module name) which have to be actually checked
    .)r   r   r   NZfatal)keymodexFT)r   nameZisargZbasepathbasenamez	.__init____init__)Zlist_all)sysr   copyr   r'   r   r   r   r   r   Zmodpath_from_fileImportErrorsplitextr   Zfile_from_modpathsplitSyntaxErrorappendnormpathZfile_info_from_modpathr	   is_directoryendswithZget_module_filesr   r   )r   r    r   r!   resulterrorsr   Z	somethingr'   Zmodule_pathZadditional_search_pathmodnamer   r%   Zmodpartsspecr	   r1   Zhas_initZsubfilepathmodpathZ
submodnamer
   r
   r   expand_modules(   s    	


"







	r8   )N)r   r)   typingr   r   r   Zastroidr   r   strr   boolr   dictr8   r
   r
   r
   r   <module>   s   
		