
    eG                        d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ ej                  dk\  rd dl
Z
nd dlZ
 ed       ed      fZ ed      Zg ee ed	      Zdd
ZddZddZddZddZddZddZy)    )annotationsN)Iterator)Path)      pylintrc	.pylintrczpyproject.tomlz	setup.cfgc                 "   t        j                         j                         } d}|sh| t        z  j	                         r	| t        z  S | | j
                  k(  xs( | dz  j                         xs | dz  j                         }| j
                  } |sh| S )zSearch for file pyproject.toml in the parent directories recursively.

    It resolves symlinks, so if there is any symlink up in the tree, it does not respect them
    Fz.gitz.hg)r   cwdresolvePYPROJECT_NAMEis_fileparentis_dir)current_diris_roots     I/usr/lib/python3/dist-packages/pylint/config/find_default_config_files.py_find_pyprojectr      s    
 ((*$$&KG.(113//;--- .f$,,..e#++- 	
 "((      c                   t        | d      5 }	 t        j                  |      }	 d d d        dj                  dg       v S # t        j                  $ r#}t	        d|  d|        Y d }~d d d        yd }~ww xY w# 1 sw Y   VxY w)Nrb)modezFailed to load 'z': Fpylinttool)opentomllibloadTOMLDecodeErrorprintget)pathtoml_handlecontenterrors       r   _toml_has_configr%   +   s    	d	 +	ll;/G w{{62... && 	$TF#eW56 	 s.   A;AA8A3&A;3A88A;;Bc                    t        j                         }	 |j                  | d       t	        d |j                         D              S # t         j                  $ r Y yw xY w)Nzutf-8)encodingFc              3  >   K   | ]  }|j                  d         yw)zpylint.N)
startswith).0sections     r   	<genexpr>z"_cfg_has_config.<locals>.<genexpr>;   s     Nw!!),Ns   )configparserConfigParserreadErroranysections)r!   parsers     r   _cfg_has_configr4   5   sY    &&(FD7+ NFOO<MNNN  s   A	 	AAc               #     K   t         D ][  } 	 | j                         rH| j                  dk(  rt        |       s/| j                  dk(  rt	        |       sJ| j                          ] y# t        $ r Y jw xY ww)zAIterate over the default config file names and see if they exist.z.tomlz.cfgN)CONFIG_NAMESr   suffixr%   r4   r   OSError)config_names    r   _yield_default_filesr:   >   sz     # 
		""$%%09I+9V%%/8T!))++
  		s>   
A7*A(A7A(A7A(%A7(	A41A73A44A7c               #  d  K   t        d      j                         rt        t        j                               j	                         } | dz  j                         rT| j
                  } t        D ]*  }| |z  }|j                         s|j	                          , | dz  j                         rSyyyw)zTraverse up the directory tree to find a config file.

    Stop if no '__init__' is found and thus we are no longer in a package.
    z__init__.pyN)r   r   osgetcwdr   r   RC_NAMES)curdirrc_namerc_paths      r   _find_project_configrB   M   s     
 M""$biik"**,%..0]]F# , 7*??$!//++, %..0 %s   BB0'B0-B0c               #  F  K   dt         j                  v rt        t         j                  d         j                         rXt        t         j                  d         j	                         r-t        t         j                  d         j                          yy	 t        j                         } | at        |       dvrS| dz  }|j	                         r|j                          | dz  dz  }|j	                         r|j                          yyyy# t        $ r d} Y qw xY ww)zJFind a config file in the specified environment var or the home directory.PYLINTRCN)~z/rootr	   z.configr   )	r<   environr   existsr   r   homeRuntimeErrorstr)	user_homehome_rcs     r   #_find_config_in_home_or_environmentrM   \   s     RZZDJ)?$@$G$G$I

:&'//1rzz*-.6688 2			I
  S^>%I+-G oo'')+j8G oo'' ! &J 	  	I	s+   BD!D ,A$D!DD!DD!c               #    K   t               E d{    	 t               E d{    	 t               } | j	                         rt        |       r| j                          	 t               E d{    	 t        j                  j                  d      rt        d      j                          yy7 7 # t        $ r Y w xY w# t        $ r Y nw xY w7 c# t        $ r Y lw xY w# t        $ r Y yw xY ww)zFind all possible config files.Nz/etc/pylintrc)r:   rB   r8   r   r   r%   r   rM   r<   r!   isfiler   )parent_pyprojects    r   find_default_config_filesrQ   r   s     #%%%')))*,##%*:;K*L"**,,688877>>/*'//11 +) & 	*    	9   s   C2B0C2B4 B2B4 7C !C .C/C 4:C# .C22B4 4	C =C2?C  C2	CC2CC2C 	C C2C  C2#	C/,C2.C//C2)returnr   )r!   z
Path | strrR   bool)rR   zIterator[Path])
__future__r   r-   r<   syscollections.abcr   pathlibr   version_infor   tomlir>   r   r6   r   r%   r4   r:   rB   rM   rQ    r   r   <module>r[      s   
 #  	 
 $ wd;/0&'==>=4+<=(/O,(,r   