
    X-PhV                       U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZ ddlmZmZ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"m#Z# ddl$m%Z%  G d d          Z&e'e(e)f         Z*e+e*         Z,e-e(e'e'e.e.f         ee'e.e.f                  f         f         Z/de0d<   ddgZ1de0d<   e G d de                      Z2ee(e2f         Z3 G d d          Z4 G d d          Z5 G d d          Z6dId)Z7dJd*Z8ej9        dKd-            Z:dLd/Z;dMd2Z<dNd4Z=dOd5Z>dPd;Z?ej@        dQd>            ZA	 dRdSdDZBdTdEZCdUdGZDdVdHZEdS )WzmLow-level infrastructure to find modules.

This builds on fscache.py; find_sources.py builds on top of this.
    )annotationsN)Enumunique)FinalOptionalUnion)	TypeAlias)PathSpec)GitWildMatchPatternError)pyinfo)CompileError)FileSystemCache)MypyFile)Options)stub_distribution_name)os_path_joinc                      e Zd ZddZdd
ZdS )SearchPathspython_pathtuple[str, ...]	mypy_pathpackage_pathtypeshed_pathreturnNonec                   t          t          t          j        j        |                    | _        t          t          t          j        j        |                    | _        t          t          t          j        j        |                    | _        t          t          t          j        j        |                    | _        d S N)	tuplemapospathabspathr   r   r   r   )selfr   r   r   r   s        Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/modulefinder.py__init__zSearchPaths.__init__!   s     !RW_k!B!BCCs27?I>>??!#bgo|"D"DEE"3rw#F#FGG    dict[str, tuple[str, ...]]c                8    | j         | j        | j        | j        dS )Nr   r   r   r   r)   r#   s    r$   asdictzSearchPaths.asdict1   s(    + -!/	
 
 	
r&   N)
r   r   r   r   r   r   r   r   r   r   )r   r'   )__name__
__module____qualname__r%   r+    r&   r$   r   r       s@        H H H H 
 
 
 
 
 
r&   r   
_TypeAliasStdlibVersions.pyi.pyr   PYTHON_EXTENSIONSc                  &    e Zd ZdZdZdZdZdd	Zd
S )ModuleNotFoundReasonr            daemonboolr   tuple[str, list[str]]c                
   d}| t           j        u rd}|g}nj| t           j        u rd}dg}nV| t           j        u rd}|g}nB| t           j        u r2d}dg}|s|                    d           |                    |           nJ ||fS )NzKSee https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-importszFCannot find implementation or library stub for module named "{module}"zOYou may be running mypy in a subpackage, mypy should be run on the package rootz`Skipping analyzing "{module}": module is installed, but missing library stubs or py.typed markerz*Library stubs not installed for "{module}"z*Hint: "python3 -m pip install {stub_dist}"zD(or run "mypy --install-types" to install all missing stub packages))r6   	NOT_FOUNDWRONG_WORKING_DIRECTORYFOUND_WITHOUT_TYPE_HINTSAPPROVED_STUBS_NOT_INSTALLEDappend)r#   r:   doc_linkmsgnotess        r$   error_message_templatesz,ModuleNotFoundReason.error_message_templatesZ   s    `'111ZCJEE)AAAZCaEE )BBB%  JEE)FFF>CABE Z   LL""""LEzr&   N)r:   r;   r   r<   )r,   r-   r.   r>   r@   r?   rA   rF   r/   r&   r$   r6   r6   G   sG         I  !   $%      r&   r6   c                  *    e Zd ZdZ	 	 	 dddZddZdS )BuildSourcezA single source file.NFr!   
str | Nonemoduletextbase_dirfollowedr;   r   r   c                P    || _         |pd| _        || _        || _        || _        d S )N__main__)r!   rJ   rK   rL   rM   )r#   r!   rJ   rK   rL   rM   s         r$   r%   zBuildSource.__init__   s0     	*
	  r&   strc                j    d                     | j        | j        | j        d u| j        | j                  S )NzLBuildSource(path={!r}, module={!r}, has_text={}, base_dir={!r}, followed={}))formatr!   rJ   rK   rL   rM   r*   s    r$   __repr__zBuildSource.__repr__   s4    Zaa	4;	(=t}dm 	
r&   )NNF)r!   rI   rJ   rI   rK   rI   rL   rI   rM   r;   r   r   )r   rP   )r,   r-   r.   __doc__r%   rS   r/   r&   r$   rH   rH   |   sR          #! ! ! ! !
 
 
 
 
 
r&   rH   c                  "    e Zd ZdZddZdd
ZdS )BuildSourceSetzIHelper to efficiently test a file's membership in a set of build sources.sourceslist[BuildSource]r   r   c                    d| _         i | _        t                      | _        |D ]S}|j        d| _         |j        r| j                            |j                   |j        r|j        pd| j        |j        <   Td S )NFT )source_text_presentsource_modulessetsource_pathsrK   r!   addrJ   )r#   rW   sources      r$   r%   zBuildSourceSet.__init__   s    #( .0&)ee 	G 	GF{&+/({ 3!%%fk222} G5;[5FB#FM2	G 	Gr&   filer   r;   c                V    |j         r|j         | j        v p|j        | j        v p| j        S r   )r!   r^   	_fullnamer\   r[   )r#   ra   s     r$   	is_sourcezBuildSourceSet.is_source   s8    Y949(99 (~!44('	
r&   N)rW   rX   r   r   )ra   r   r   r;   )r,   r-   r.   rT   r%   rd   r/   r&   r$   rV   rV      sF        SSG G G G
 
 
 
 
 
r&   rV   c                  ~    e Zd ZdZ	 	 d0d1dZd2dZd3dZd4dZd5dZddd6d Z	d7d"Z
d8d%Zd9d)Zd:d*Zd;d-Zd<d/ZdS )=FindModuleCacheaK  Module finder with integrated cache.

    Module locations and some intermediate results are cached internally
    and can be cleared with the clear() method.

    All file system accesses are performed through a FileSystemCache,
    which is not ever cleared by this class. If necessary it must be
    cleared by client code.
    Nsearch_pathsr   fscacheFileSystemCache | NoneoptionsOptions | Nonestdlib_py_versionsStdlibVersions | None
source_setBuildSourceSet | Noner   r   c                    || _         || _        |pt                      | _        i | _        i | _        i | _        || _        d }|r|j        }|pt          |          | _
        d S r   )rg   rn   r   rh   initial_componentsresultsns_ancestorsrj   custom_typeshed_dirload_stdlib_py_versionsrl   )r#   rg   rh   rj   rl   rn   rt   s          r$   r%   zFindModuleCache.__init__   s     )$3/"3"3 PR68,." 	>")"="4 #
8O9
 9
r&   c                    | j                                          | j                                         | j                                         d S r   )rr   clearrq   rs   r*   s    r$   rw   zFindModuleCache.clear   sF    %%'''!!!!!r&   idrP   ModuleSearchResult | Nonec                ,     j         sdS  j         j                            |d          }|r j                            |          rt
          j                            |          t          |	                    d                    D ]E}t           fdt          D                       s dS t
          j                                      F|S |                    d          }|dk    r                     |d|                   t          t                    sdS t
          j                                      \  }}t          fdt          D                       s/|t          v r& j                            |          st$          j        S dS )zFast path to find modules by looking through the input sources

        This is only used when --fast-module-lookup is passed on the command line.N.c              3  n   K   | ]/}j                             t          d |z                       V  0dS r%   N)rh   isfiler   ).0xdr#   s     r$   	<genexpr>z=FindModuleCache.find_module_via_source_set.<locals>.<genexpr>   sR        MNDL''Q
Q(G(GHH     r&   c              3  H   K   | ]}                     d |z             V  dS r}   )endswith)r   r   parents     r$   r   z=FindModuleCache.find_module_via_source_set.<locals>.<genexpr>   s3      RR1vzA~66RRRRRRr&   )rn   r\   getrh   r~   r    r!   dirnamerangecountanyr4   rfindfind_module_via_source_set
isinstancerP   splitextisdirr6   r>   )	r#   rx   p_idxbasenameextr   r   s	   `      @@r$   r   z*FindModuleCache.find_module_via_source_set   s     	4O*..r488 	$$Q'' 	
 ""A288C==)) ' '     Rc        44GOOA&&Hhhsmm"99 44RX>>F~Z%<%<~tG,,V44MHcRRRR@QRRRRR 6(((1C1CH1M1M( ,55tr&   lib_pathr   PackageDirsc                L   |                     d          }t          j                            |dd                   }g }|                     ||d                   D ]H}|rt          ||          }n|}| j                            |          r|                    |df           I|S )zMFind which elements of a lib_path have the directory a module needs to exist.r{   Nr   r   T)	splitr    sepjoinget_toplevel_possibilitiesr   rh   r   rB   )r#   rx   r   
components	dir_chaindirspathitemdirs           r$   find_lib_path_dirsz"FindModuleCache.find_lib_path_dirs  s    XXc]]
FKK
3B300	77*Q-PP 	) 	)H "8Y77|!!#&& )S$K(((r&   	list[str]c                   || j         v r!| j         |                             |g           S i }|D ]}	 | j                            |          }n# t          $ r g }Y nw xY w|D ]P}t
          j                            |          d         }|                    |g           	                    |           Q|| j         |<   |                    |g           S )a  Find which elements of lib_path could contain a particular top-level module.

        In practice, almost all modules can be routed to the correct entry in
        lib_path by looking at just the first component of the module name.

        We take advantage of this by enumerating the contents of all of the
        directories on the lib_path and building a map of which entries in
        the lib_path could contain each potential top-level module that appears.
        r   )
rq   r   rh   listdirOSErrorr    r!   r   
setdefaultrB   )r#   r   rx   r   r   contentsnames          r$   r   z*FindModuleCache.get_toplevel_possibilities  s     t...*8488R@@@ ,.
 
	< 
	<C<//44   
 ! < <w''--a0%%dB//66s;;;;< -7)~~b"%%%s   AAAF	fast_pathr   r;   ModuleSearchResultc                  || j         vr|                    d          d         }d}|| j        v r|                     |          }n|| j        v r|                     |          }|                     ||          \  }}|rd|sK| j        | j        j        s8|t          j        u r*| 	                    |          rt          j
        | j         |<   n
|| j         |<   | j         |         S |S | j         |         S )zReturn the path of the module source file or why it wasn't found.

        If fast_path is True, prioritize performance over generating detailed
        error descriptions.
        r{   r   T)rr   	partitionrl   _typeshed_has_version_find_modulerj   fast_module_lookupr6   r>   _can_find_module_in_parent_dirr?   )r#   rx   r   	top_leveluse_typeshedresultshould_caches          r$   find_modulezFindModuleCache.find_module6  s    T\!!S))!,ILT,,,#99"==d555#99)DD#'#4#4R#F#F FL  "	.&*l&>4<Cb&>"6"@@@;;B?? A (<'SDL$$'-DL$|B''|Br&   rJ   c                |    | j         sdS t          | j                   }| j        |         \  }}||k    o	|d u p||k    S )NT)rj   typeshed_py_versionrl   )r#   rJ   versionmin_versionmax_versions        r$   r   z%FindModuleCache._typeshed_has_versionT  sQ    | 	4%dl33#'#:6#B [+%Y;$+>+X'[BXYr&   pkg_dir$OnePackageDir | ModuleNotFoundReasonc                   d}|}|                     d          }t          |          D ]\  }}t          ||          }| j                            t          |d                    r't          j        j        |g|d d         R  |dk    fc S |s9| j                            |          s| j                            |dz             rd}| j                            |          s n|rU| j	        rB| j	        
                    |          }|j        r!t          j        j        |g|d d         R  dfS t          j        S t          j        S )NFr{   py.typedr   r   r3   T)r   	enumerater   rh   r~   r    r!   r   r   rj   clone_for_modulefollow_untyped_importsr6   r@   r>   )	r#   rx   r   plausible_matchdir_pathr   index	componentmodule_specific_optionss	            r$   _find_module_non_stub_helperz,FindModuleCache._find_module_non_stub_helper[  so     XXc]]
 )* 5 5 
	 
	E9#Hi88H|""<*#E#EFF 'w|G>j"o>>>
JJJJ$ '""8,,'040C0CHuDT0U0U' #'<%%h//  	2| J*.,*G*G*K*K'*A J7<B*SbS/BBBEII'@@'11r&   r   matchtuple[str, bool]c                $   |\  }}t          dt          |                    D ]l}d                    |d |                    }|| j        vr$| j                            |          r
|| j        |<   t          j                            |          }md S )Nr7   r{   )	r   lenr   rs   rh   r   r    r!   r   )r#   r   r   r!   verifyipkg_ids          r$   _update_ns_ancestorsz$FindModuleCache._update_ns_ancestorsu  s    fq#j//** 	) 	)AXXj1"o..FT...4<3E3Ed3K3K.,0!&)7??4((DD		) 	)r&   c                   t          j                    }t          t          dddd          | j        | j        | j                  }t          d t          j        |          D                       rt           j	        
                    |          }t          |fddd          |_        t          |                    |d          d         t                    sdS t          d t          j        |          D                       dS )zsTest if a module can be found by checking the parent directories
        of the current working directory.
        r/   )rl   c              3  4   K   | ]}t          |          V  d S r   )is_init_file)r   ra   s     r$   r   zAFindModuleCache._can_find_module_in_parent_dir.<locals>.<genexpr>  s*      II,t$$IIIIIIr&   Fr   T)r    getcwdrf   r   rh   rj   rl   r   r   r!   r   rg   r   r   r6   )r#   rx   working_dirparent_searchs       r$   r   z.FindModuleCache._can_find_module_in_parent_dir}  s     ikk'BB''LL#6	
 
 
 IIK1H1HIIIII 	'//+66K)4k^RR)P)PM&m88UCCAFH\]] t	 IIK1H1HIIIII 	
 ur&   r   tuple[ModuleSearchResult, bool]c                l   &  j         & j        ! j        j        r                               nd}|r|dfS                     d          }t
          j                            |dd                   }g }g }d} fd|d         |d         dz   fD             }	d}
 j        j	        D ]}||	vr|d         dz   }t          ||          }&                    |          rt          |d	          }|g|d
d         z   }t          j        j        |g|dd         R  }&                    |          r&                    |          r&                    |                                                                          dk    r?t          ||          }|                    |df           |                    |df           n/|                    |df           n|                    |df                                |          }t'          |t(                    r|t(          j        u rd}d}
|                    |                                ||            j        r6 j        j        r*|                                 |                                 d} j        j         j        j        z   }                     |          }|r#|                      j        j                  z  }|||z   z  }t
          j        |d         z   }t
          j        dz   }g }|D ]\  }}||z   }d}|}t;          t=          |          d
z
            D ]!}t
          j                            |          }"| d| d}&                     ||          r2|r*tC          &||          s|                    ||f           n|dfc S tD          D ]V}||z   |z   }&                     ||          r6d}|r*tC          &||          s|                    ||f           N|dfc c S W j        rQ j        j#        rE|sC&$                    ||          r-&                     ||          s|                    ||f           tD          D ]Q}||z   }&                     ||          r4|r*tC          &||          s|                    ||f           I|dfc c S R j        rO j        j#        rC|rA&fd|D             } | %                    tM          |                     }!||!         d         dfS  j'        (                              }"|"|"dfS tS                    }#|#rt=          |          d
k    rt(          j*        dfS t;          d
t=          |                    D ]4}$d                    |d|$                   }%tS          |%          |#k    r n5t(          j*        dfS  +                    |%          t(          j*        u rt(          j*        dfS t(          j,        dfS |rt(          j        |
fS t(          j,        dfS )zwTry to find a module in all available sources.

        Returns:
            ``(result, can_be_cached)`` pair.
        NTr{   r   Fc                f    h | ]-}                     |j        j                  D ]
}|d          .S )r   )r   rg   r   )r   r   package_dirr#   s      r$   	<setcomp>z/FindModuleCache._find_module.<locals>.<setcomp>  sZ     "
 "
 "
#66y$BSB`aa"
 "
  N"
 "
 "
 "
r&   r   z-stubsr   r7   partialr%   r2   c                :    g | ]\  }}t          ||          S r/   )highest_init_level)r   r!   
dir_prefixrh   rx   s      r$   
<listcomp>z0FindModuleCache._find_module.<locals>.<listcomp>I  s;       $D* #7BjAA  r&   )-rh   rj   r   r   r   r    r   r   rg   r   r   r   r!   r~   readdecodestriprB   r   r   r6   r@   r   use_builtins_fixturesrw   r   r   r   r   r   r   r   isfile_caseverify_moduler4   namespace_packagesexists_caser   maxrs   r   r   rA   r   r>   )'r#   rx   r   r   r   r   third_party_inline_dirsthird_party_stubs_dirs-found_possible_third_party_missing_type_hintscandidate_package_dirscan_cache_any_resultr   	stub_namestub_dirstub_typed_filestub_componentsr!   runtime_pathnon_stub_matchpython_mypy_pathcandidate_base_dirsseplastsepinitnear_missesrL   r   	base_pathhas_initr   r   
path_stubs	extensionlevelsr   ancestorapproved_dist_namer   	parent_idrh   s'   ``                                    @r$   r   zFindModuleCache._find_module  s    ,> (T\-L( ++B/// 	

  	d7N XXc]]
FKK
3B300	 02.08=5"
 "
 "
 "
(mZ]X-EF"
 "
 "
  $(5 "	F "	FG444"10I#GY77H}}X&& D".x"D"D#,+
122">w|GCocrc.BCCC==&& D~~o66 D
 #<<88??AAGGIIYVV+7+K+KL3::L$;OPPP 3994-HHHH 3994,GGGG.55tTlCCC!>>r7KKN.*>?? F!%9%RRRDHA+0('..~>>>))*nEEEE< 	BDL> 	B#))+++"((***<A9,69J9VV"55b:JKK 	`  4#:#:2t?P?^#_#__58OOO &:b>)&:% 3 )	& )	&Hf 7*IH!J3z??Q.// 9 9W__Z88

 &::W:::J"":z:: , ,-Z"T"T ,&&
J'?@@@@%t++++ / & &	 7*Y6&&tZ88 &#H !mGRz&R&R !#**D*+=>>> :%%%%%& | @ ? @ @++IzBB@ $//	:FF@
  &&	:'>??? / & &	 9,&&tZ88 & !mGRz&R&R !#**D*+=>>> :%%%%%	&&: < 	/DL; 	/ 	/    (3  F LLV--Eu%a($.. $((,,T>!3B77 	8:!##+H$NN 1c*oo.. O OHHZ^44	))448JJJE K ,H$NN	**.B.___+H$NN'14778 	W'@BVVV#-t33r&   rX   c                R   |                      |d          }t          |t                    rg S t          ||d           g}d }t	          |          r t
          j                            |          }n| j        	                    |          r|}||S t                      }t          | j                            |                    }|D ]}|dv s|                    d          rt          ||          }| j        r0t!          || j        j        | j        | j        j        dk              rd| j        r1| j        j        r%t)          || j        | j        j        dk              r| j        	                    |          r| j        r| j        j        sP| j                            t          |d                    s(| j                            t          |d                    rC|                    |           |                    |                     |dz   |z                        ^t
          j                            |          \  }	}
|	dk    r|	|vrPd|	vrL|
t6          v rC|                    |	           |                    |                     |dz   |	z                        |S )	NTr   )__pycache__zsite-packagesnode_modulesr{   r8   __init__.py__init__.pyir%   )r   r   r6   rH   r   r    r!   r   rh   r   r]   sortedr   
startswithr   rj   matches_excludeexclude	verbosityexclude_gitignorematches_gitignorer   r~   r_   extendfind_modules_recursiver   r4   )r#   rJ   module_pathrW   r   seennamesr   subpathstemsuffixs              r$   r  z&FindModuleCache.find_modules_recursivel  s   &&v&>>k#788 	I{FD99:$$ 	'7??;77LL\,, 	'&LN t|++L99:: !	U !	UDGGG4??[^K_K_G"<66G| -t|T\=SWX=X! !  L2 &gt|T\=SWX=XYY
 |!!'** UL UT\%D UL''Wm(L(LMMU|**<+P+PQQU HHTNNNNN4#>#>v|d?R#S#STTT!w//55f:%%t##4FFW<W<W HHTNNNNN4#>#>v|d?R#S#STTTr&   )NN)rg   r   rh   ri   rj   rk   rl   rm   rn   ro   r   r   )r   r   )rx   rP   r   ry   )rx   rP   r   r   r   r   )r   r   rx   rP   r   r   )rx   rP   r   r;   r   r   )rJ   rP   r   r;   )rx   rP   r   rP   r   r   )r   r   r   r   r   r   )rx   rP   r   r;   )rx   rP   r   r;   r   r   )rJ   rP   r   rX   )r,   r-   r.   rT   r%   rw   r   r   r   r   r   r   r   r   r   r  r/   r&   r$   rf   rf      s4         59,0
 
 
 
 
2" " " "
/ / / /b    & & & &> 9>            <Z Z Z Z2 2 2 24) ) ) )   $[4 [4 [4 [4z7 7 7 7 7 7r&   rf   r  rP   excludesr   rh   r   verboser;   r   c                >   |sdS t           j                            |                               t           j        d          }|                    |           r|dz  }|D ]>}t          j        ||          r'|r"t          d| d| dt          j
                    dS ?dS )NF/TRACE: Excluding z (matches pattern )ra   T)r    r!   relpathreplacer   r   researchprintsysstderr)r  r  rh   r  subpath_strr  s         r$   r
  r
    s      u'//'**22263??K}}W s  9Wk** 	 QQQwQQQX[Xb    44	 5r&   c                ^   t           j                            |           \  }}t          |          D ]z\  }}t           j                            | |          }|                    |          r|dz   }|                    |          r&|r!t          d| d| t          j	                    dS {dS )Nr  r  z (matches .gitignore) in r  TF)
r    r!   r   find_gitignoresr  r   
match_filer"  r#  r$  )r  rh   r  r   r   gi_pathgi_specrelative_paths           r$   r  r    s    W]]7##FC+C00 
 
99=='' 	0)C/Mm,, 	 YYYPWYY    44	 5r&   r   list[tuple[str, PathSpec]]c                    t           j                            |           }|| k    rg }nt          |          }t           j                            | d          }t           j                            |          rt          |          5 }|                                }d d d            n# 1 swxY w Y   	 || t          j	        d|          fgz   S # t          $ r# t          d| t          j                   |cY S w xY w|S )Nz
.gitignoregitwildmatchzerror: could not parse r  )r    r!   r   r'  r   r~   open	readlinesr
   
from_linesr   r"  r#  r$  )r   
parent_dirparent_gitignores	gitignorefliness         r$   r'  r'    s@   %%JS+J77S,//I	w~~i   %)__ 	"KKMME	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"	%$h.A.RW.X.X(Y'ZZZ' 	% 	% 	%7I77cjIIII$$$$	% s$   B''B+.B+3C *C;:C;r!   c                D    t           j                            |           dv S )N)r  r  )r    r!   r   )r!   s    r$   r   r     s    7D!!%DDDr&   rx   prefixc                :    t                    rt          j                                      t	          |                    d                    D ]F}t          j                                      t           fdt          D                       s dS GdS )z;Check that all packages containing id have a __init__ file.r{   c              3  f   K   | ]+}                     t          d |                     V  ,dS r}   r   r   r   r   rh   r!   r8  s     r$   r   z verify_module.<locals>.<genexpr>  sZ       
 
 T3Ii3I3I J JFSS
 
 
 
 
 
r&   FTr   r    r!   r   r   r   r   r4   )rh   rx   r!   r8  r   s   ` `` r$   r   r     s    D %wt$$288C==!!  wt$$ 
 
 
 
 
 
.
 
 
 
 
 	 55		
 4r&   intc                B    t                    rt          j                                      d}t	          |                    d                    D ]H}t          j                                      t           fdt          D                       r|dz   }I|S )z:Compute the highest level where an __init__ file is found.r   r{   c              3  f   K   | ]+}                     t          d |                     V  ,dS r}   r;  r<  s     r$   r   z%highest_init_level.<locals>.<genexpr>  sZ       
 
 T3Ii3I3I J JFSS
 
 
 
 
 
r&   r7   r=  )rh   rx   r!   r8  levelr   s   ` ``  r$   r   r     s    D %wt$$E288C==!!  wt$$ 
 
 
 
 
 
.
 
 
 
 
 	 EELr&   c                 p    t          j        d          } | sg S |                     t           j                  S )NMYPYPATH)r    getenvr   pathsep)path_envs    r$   r   r     s2    y$$H 	>>"*%%%r&   data_dir	pyversiontuple[int, int]rt   rI   c                z   t           j                            |           } g }|rt           j                            |          }t           j                            |d          }t           j                            |dd          }t           j                            |d          }t           j                            |          rt           j                            |          s6t          d                    |                     t          j	        d           nt           j                            | d          }t           j                            |          r|} t           j                            | dd          }t           j                            | ddd          }|
                    |           |
                    |           t          j        d	k    r|
                    d
           |sMt          d                    t          j        |           t          j                   t          j	        d           |S )zJReturn default standard library search paths. Guaranteed to be normalised.stdlibstubszmypy-extensionsVERSIONSzDerror: --custom-typeshed-dir does not point to a valid typeshed ({})r8   z
stubs-autotypeshedwin32z/usr/local/lib/mypyz~Could not resolve typeshed subdirectories. Your mypy install is broken.
Python executable is located at {}.
Mypy located at {}r  r7   )r    r!   r"   r   r   r~   r"  rR   r#  exitrB   platform
executabler$  )rG  rH  rt   r!   typeshed_dirmypy_extensions_dirversions_fileautos           r$   default_lib_pathrW    s   
 wx((HD ] goo.ABBw||$7BB gll+>IZ[[\:>>w}}\** 	"'..2O2O 	V]]'   
 HQKKKw||Hl337== 	Hw||Hj(CC gll8ZJ[\\KK 	KK#$$$ |w)*** FFLfG G 	
 	
 	
 	
 	Kr&   python_executabletuple[list[str], list[str]]c                \   | g g fS | t           j        k    rt          j                    \  }}ni t	          t
          j                  ddi}	 t          j        t          j
        | t          j        dg|t          j                                                            \  }}n# t          j        $ r.}t          |j                   t          |j                    d}~wt$          $ r>}|j        J t          j        |j                  }t+          d|  d| g          |d}~ww xY w||fS )a  Find package directories for given python. Guaranteed to return absolute paths.

    This runs a subprocess call, which generates a list of the directories in sys.path.
    To avoid repeatedly calling a subprocess (which can be slow!) we
    lru_cache the results.
    NPYTHONSAFEPATH1getsearchdirs)envr$  z!mypy: Invalid python executable 'z': )r#  rR  r   r]  dictr    environastliteral_eval
subprocesscheck_output__file__PIPEr   CalledProcessErrorr"  r$  stdoutr   errnostrerrorr   )rX  sys_pathsite_packagesr^  errreasons         r$   get_search_dirsro  3  s]     Bx	cn	,	,"("6"8"8-- :bj!!9#3S99	&)&6'&I%?   &((' '#Hmm , 	 	 	#*#* 	 	 	9((([++FS5FSS6SST 	 ]""s%   AB$ $D'3)CD')9D""D'rW   rX   rj   r   alt_lib_pathc                6   t          j        t          ||j        |j                            }|j        rt          j        dd          }|sAt          j        	                    t          j        	                    t                              }t          j                            |          }|                    t          j                            |ddd                     g }|sc| D ])}|j        r |j        }||vr|                    |           *|j        rd}nt          j                    }||vr|                    d|           t'                      }	|	                    |j                   |r|	                    d|           t+          |j                  \  }
}|D ]|vsJ |	v sGt/          fd	|	D                       s,t          j        j        rht/          fd
|	D                       rMt3           dt4          j                   t3          dt4          j                   t5          j        d           t;          t=          t?          |                    t=          |	          t=          |
|z             t=          |                    S )a/  Compute the search paths as specified in PEP 561.

    There are the following 4 members created:
    - User code (from `sources`)
    - MYPYPATH (set either via config or environment variable)
    - installed package directories (which will later be split into stub-only and inline)
    - typeshed
    )rt   MYPY_TEST_PREFIXNz	test-dataunitzlib-stubr{   r   c              3  f   K   | ]+}|                     t          j        j        z             V  ,d S r   )r	  r    r!   r   r   r   sites     r$   r   z'compute_search_paths.<locals>.<genexpr>  s8      FF1<<rw{ 233FFFFFFr&   c              3  f   K   | ]+}|                     t          j        j        z             V  ,d S r   )r	  r    r!   altsepru  s     r$   r   z'compute_search_paths.<locals>.<genexpr>  s8      &]&]qq||D27>4I'J'J&]&]&]&]&]&]r&   z& is in the MYPYPATH. Please remove it.r  zbSee https://mypy.readthedocs.io/en/stable/running_mypy.html#how-mypy-handles-imports for more infor7   r)   ) collectionsdequerW  python_versionrt   r   r    rD  r!   r   re  r"   
appendleftr   rL   rB   bazelr   insertr   r  ro  rX  r   rx  r"  r#  r$  rP  r   r   reversed)rW   rj   rG  rp  r   root_dirr   r`   r   mypypathrk  rl  rv  s               @r$   compute_search_pathsr  Z  s     g,'B]	
 	
 	
 H $ 	U
 9/66 	Bwrwx'@'@AAH7??8,,BGLL;
SSTTT  K ' 	, 	,F ,ok))&&s+++ = 	CC)++Chq#&&& {{H OOG%&&&  )<(((-g.GHHHm  8####HFFFFXFFFFF  #&&]&]&]&]T\&]&]&]#]#]  TAAA
SSSS:Z   
 HQKKK(;//00//8m344Hoo	   r&   c                   | p1t          t          j                            t                    d          }t          |d          }i }t          |d          }t          j                            |          sJ | |t          f            t          |          5 }|D ]}|                    d          d                                         }|dk    r6|                    d          \  }}|                    d          }	t          |	d                   }
t          |	          d	k    r/|	d
                                         rt          |	d
                   nd}|
|f||<   	 ddd           n# 1 swxY w Y   |S )zReturn dict with minimum and maximum Python versions of stdlib modules.

    The contents look like
    {..., 'secrets': ((3, 6), None), 'symbol': ((2, 7), (3, 9)), ...}

    None means there is no maximum version.
    rN  rK  rM  #r   rZ   :-r8   r7   N)r   r    r!   r   re  r~   r/  r   r   parse_versionr   )rt   rS  
stdlib_dirr   versions_pathr5  linerJ   version_rangeversionsr   r   s               r$   ru   ru     s    '],rwx7P7PR\*]*]LlH55JF Z88M7>>-((XX+>x*XXXX	m		 6 
	6 
	6D::c??1%++--Drzz$(JJsOO!FM$**3//H'44K.1(mmq.@.@Xa[EVEVEXEX.@hqk***^b  )+5F6NN
	66 6 6 6 6 6 6 6 6 6 6 6 6 6 6 Ms   CE++E/2E/r   c                    |                                                      d          \  }}t          |          t          |          fS )Nr{   )r   r   r>  )r   majorminors      r$   r  r    s8    ==??((--LE5u::s5zz!!r&   c                ,    t          | j        d          S )zIReturn Python version used for checking whether module supports typeshed.)r9      )r   r{  )rj   s    r$   r   r     s     w%v...r&   )
r  rP   r  r   rh   r   r  r;   r   r;   )r  rP   rh   r   r  r;   r   r;   )r   rP   r   r,  )r!   rP   r   r;   )
rh   r   rx   rP   r!   rP   r8  rP   r   r;   )
rh   r   rx   rP   r!   rP   r8  rP   r   r>  )r   r   )rG  rP   rH  rI  rt   rI   r   r   )rX  rI   r   rY  r   )
rW   rX   rj   r   rG  rP   rp  rI   r   r   )rt   rI   r   r1   )r   rP   r   rI  )rj   r   r   rI  )FrT   
__future__r   ra  ry  	functoolsr    r   rc  r#  enumr   r   typingr   r   r   typing_extensionsr	   r0   pathspecr
   pathspec.patterns.gitwildmatchr   mypyr   mypy.errorsr   mypy.fscacher   
mypy.nodesr   mypy.optionsr   mypy.stubinfor   	mypy.utilr   r   r   rP   r;   OnePackageDirlistr   r_  r>  r1   __annotations__r4   r6   r   rH   rV   rf   r
  r  	lru_cacher'  r   r   r   r   rW  cachero  r  ru   r  r   r/   r&   r$   <module>r     s    
 # " " " " " 



         				 				     



         ) ) ) ) ) ) ) ) ) ) 5 5 5 5 5 5       C C C C C C       $ $ $ $ $ $ ( ( ( ( ( (                   0 0 0 0 0 0 " " " " " "
 
 
 
 
 
 
 
6 c4i =! "#uU38_huSRUX>W-W'X"XY Y Y Y Y"E?  * * * * , , , , ,4 , , ,b 3 445 
 
 
 
 
 
 
 
2
 
 
 
 
 
 
 
0v v v v v v v vr   $        &E E E E      & & & &, , , ,^ ## ## ## ##N ]aU U U U Up   :" " " "
/ / / / / /r&   