o
    tBh                     @  s  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 e	jdkr=ddlZnddlZddlmZmZmZmZmZmZ ddl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& G dd de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e.d< ddgZ/de.d< eG dd deZ0ee(e0f Z1G dd dZ2G dd dZ3G dd dZ4dOd'd(Z5dPd*d+Z6dQd.d/Z7dRd1d2Z8dSd3d4Z9dTd:d;Z:ej;dd<dUd?d@Z<	dVdWdFdGZ=dXdHdIZ>dYdKdLZ?dZdMdNZ@dS )[zmLow-level infrastructure to find modules.

This builds on fscache.py; find_sources.py builds on top of this.
    )annotationsN)Enumunique)CompileError)      )DictList
NamedTupleOptionalTupleUnion)Final	TypeAlias)pyinfo)FileSystemCache)MypyFile)Options)is_legacy_bundled_packagec                   @  s.   e Zd ZU ded< ded< ded< ded< dS )SearchPathstuple[str, ...]python_path	mypy_pathpackage_pathtypeshed_pathN)__name__
__module____qualname____annotations__ r   r   h/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/modulefinder.pyr   #   s
   
 r   
_TypeAliasStdlibVersionsz.pyi.pyr   PYTHON_EXTENSIONSc                   @  s&   e Zd ZdZdZdZdZdd	d
ZdS )ModuleNotFoundReasonr         r   daemonboolreturntuple[str, list[str]]c                 C  s   d}| t ju rd}|g}||fS | t ju rd}dg}||fS | t ju r,d}|g}||fS | t ju rFd}dg}|s=|d || ||fS J )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 markerzPLibrary stubs not installed for "{module}" (or incompatible with Python {pyver})z*Hint: "python3 -m pip install {stub_dist}"zD(or run "mypy --install-types" to install all missing stub packages))r%   	NOT_FOUNDWRONG_WORKING_DIRECTORYFOUND_WITHOUT_TYPE_HINTSAPPROVED_STUBS_NOT_INSTALLEDappend)selfr(   doc_linkmsgnotesr   r   r    error_message_templatesJ   s4   




z,ModuleNotFoundReason.error_message_templatesN)r(   r)   r*   r+   )r   r   r   r,   r.   r-   r/   r5   r   r   r   r    r%   7   s    r%   c                   @  s*   e Zd ZdZ		ddd
dZdddZdS )BuildSourcezA single source file.Npath
str | Nonemoduletextbase_dirr*   Nonec                 C  s    || _ |pd| _|| _|| _d S )N__main__)r7   r9   r:   r;   )r1   r7   r9   r:   r;   r   r   r    __init__r   s   

zBuildSource.__init__strc                 C  s   d | j| j| jd u| jS )Nz?BuildSource(path={!r}, module={!r}, has_text={}, base_dir={!r}))formatr7   r9   r:   r;   r1   r   r   r    __repr__~   s   zBuildSource.__repr__NN)
r7   r8   r9   r8   r:   r8   r;   r8   r*   r<   )r*   r?   )r   r   r   __doc__r>   rB   r   r   r   r    r6   o   s    r6   c                   @  s$   e Zd ZdZdddZd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                 C  s^   d| _ i | _t | _|D ] }|jd urd| _ |jr | j|j |jr,|jp'd| j|j< qd S )NFT )source_text_presentsource_modulessetsource_pathsr:   r7   addr9   )r1   rF   sourcer   r   r    r>      s   
zBuildSourceSet.__init__filer   r)   c                 C  s4   |j r|j | jv rdS |j| jv rdS | jrdS dS )NTF)r7   rL   	_fullnamerJ   rI   )r1   rO   r   r   r    	is_source   s   zBuildSourceSet.is_sourceN)rF   rG   r*   r<   )rO   r   r*   r)   )r   r   r   rD   r>   rQ   r   r   r   r    rE      s    
rE   c                   @  s   e Zd ZdZ		d>d?ddZd@ddZdAddZdBddZdCddZd d!dDd%d&Z	dEd(d)Z
dFd-d.ZdGd1d2ZdHd3d4ZdId6d7ZdJd9d:ZdKd<d=ZdS )L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                 C  sP   || _ || _|p
t | _i | _i | _i | _|| _d }|r|j}|p$t	|| _
d S N)rS   rZ   r   rT   initial_componentsresultsns_ancestorsrV   custom_typeshed_dirload_stdlib_py_versionsrX   )r1   rS   rT   rV   rX   rZ   r`   r   r   r    r>      s   
zFindModuleCache.__init__c                 C  s"   | j   | j  | j  d S r\   )r^   clearr]   r_   rA   r   r   r    rb      s   

zFindModuleCache.clearidr?   ModuleSearchResult | Nonec                   s   j sdS j j|d}|r<j|r<tj| t|	dD ]}t
 fddtD s3 dS tj  q"|S |d}|dkry|d| du sWttsYdS tj\}}t
fddtD sy|tv ryj|syt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  s*    | ]}j tj d | V  qdS r>   N)rT   isfileosr7   join.0x)dr1   r   r    	<genexpr>   s    
z=FindModuleCache.find_module_via_source_set.<locals>.<genexpr>c                 3  s    | ]
}  d | V  qdS rf   )endswithrj   )parentr   r    rn      s    )rZ   rJ   getrT   rg   rh   r7   dirnamerangecountanyr$   rfindfind_module_via_source_set
isinstancer?   splitextisdirr%   r,   )r1   rc   p_idxbasenameextr   )rm   rq   r1   r    rx      s,   
z*FindModuleCache.find_module_via_source_setlib_pathr   PackageDirsc                 C  sl   | d}tj|dd }g }| ||d D ]}tjtj||}| j|r3|	|df q|S )zFind which elements of a lib_path have the directory a module needs to exist.

        This is run for the python_path, mypy_path, and typeshed_path search paths.
        re   Nro   r   T)
splitrh   sepri   get_toplevel_possibilitiesr7   normpathrT   r{   r0   )r1   rc   r   
components	dir_chaindirspathitemdirr   r   r    find_lib_path_dirs   s   
z"FindModuleCache.find_lib_path_dirs	list[str]c              	   C  s   || j v r| j | |g S i }|D ],}z| j|}W n ty'   g }Y nw |D ]}tj|d }||g 	| q*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   )
r]   rr   rT   listdirOSErrorrh   r7   rz   
setdefaultr0   )r1   r   rc   r   r   contentsnamer   r   r    r   	  s   

z*FindModuleCache.get_toplevel_possibilitiesF)	fast_pathr   r)   ModuleSearchResultc                C  s   || j vrJ|dd }d}|| jv r| |}n
|| jv r#| |}| ||| j |< |sJ| jdur7| jjsJ| j | tju rJ| 	|rJtj
| j |< | 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.
        re   r   TN)r^   	partitionrX   _typeshed_has_version_find_modulerV   fast_module_lookupr%   r,   _can_find_module_in_parent_dirr-   )r1   rc   r   	top_leveluse_typeshedr   r   r    find_module(  s    




zFindModuleCache.find_moduler9   c                 C  s:   | j sdS t| j }| j| \}}||ko|d u p||kS )NT)rV   typeshed_py_versionrX   )r1   r9   versionmin_versionmax_versionr   r   r    r   >  s
   
z%FindModuleCache._typeshed_has_versionr   pkg_dir$OnePackageDir | ModuleNotFoundReasonc                 C  s   d}|}t |D ]D\}}tj||}| jtj|dr2tjj|g|d d R  |dkf  S |sD| j|sB| j|d rDd}| j|sL nqt|d rft|dksc| 	|d t
ju rft
jS td|d d	 rtt
jS |ryt
jS t
jS )
NFpy.typedro   r   r#   Tr&   re   r'   )	enumeraterh   r7   ri   rT   rg   r{   r   lenr   r%   r/   r.   r,   )r1   r   r   plausible_matchdir_pathindex	componentr   r   r    _find_module_non_stub_helperE  s4   (
z,FindModuleCache._find_module_non_stub_helpermatchtuple[str, bool]c                 C  s`   |\}}t dt|D ]"}d|d |  }|| jvr'| j|r'|| j|< tj|}qd S )Nr&   re   )	rt   r   ri   r_   rT   r{   rh   r7   rs   )r1   r   r   r7   verifyipkg_idr   r   r    _update_ns_ancestorsb  s   
z$FindModuleCache._update_ns_ancestorsc                 C  s   t  }ttdddd| j| j| jd}tdd t |D rFt j	
|}t|fddd|_t||dts:dS tdd t |D s dS )zsTest if a module can be found by checking the parent directories
        of the current working directory.
        r   )rX   c                 s  s    | ]}t |V  qd S r\   )is_init_file)rk   rO   r   r   r    rn   u  s    zAFindModuleCache._can_find_module_in_parent_dir.<locals>.<genexpr>FT)rh   getcwdrR   r   rT   rV   rX   rv   r   r7   rs   rS   ry   r   r%   )r1   rc   working_dirparent_searchr   r   r    r   j  s   z.FindModuleCache._can_find_module_in_parent_dirr   c           "        s  | j  | jd ur| jjr| nd }|r|S d}tj|d d }g }g }d}d}	| jj	D ]}
|d d }tj
|
|} |r| |rtj
|d}|g|dd   }tj
j|
g|d d R  } |r |r |  dkrtj
|
|}||d	f ||df n||d	f n||d	f | ||
}t|tr|tju rd	}q2|tju rd	}	q2|| | || q2| jr| jjr|  |  d}| jj| jj }| |}|r|| | jj7 }||| 7 }tj|d  }tjd
 }g }|D ]\}}|| }d}|}tt|d D ]	}tj
 |}qt!D ]U}|| | }|d | | } "||r^d	}|rXt# ||sX|||f q+|    S  "||r|ryt# ||sy|||f q+|    S q+| jr| jj$r %||r|s|||f t!D ](}|| } "||r|rt# ||s|||f q|    S qq| jr| jj$r|r fdd|D }|&t'|} ||  d S | j()}!|!d ur|!S |	rtjS |rtjS tj*S )Nre   ro   Fr   z-stubsr   r&   partialTr>   c                   s   g | ]\}}t  ||qS r   )highest_init_level)rk   r7   
dir_prefixrT   rc   r   r    
<listcomp>!  s    z0FindModuleCache._find_module.<locals>.<listcomp>)+rT   rV   r   rx   r   rh   r   ri   rS   r   r7   r{   _is_compatible_stub_packagerg   readdecodestripr0   r   ry   r%   r.   r/   r   use_builtins_fixturesrb   r   r   r   r   rt   r   rs   r$   isfile_caseverify_modulenamespace_packagesexists_caser   maxr_   rr   r,   )"r1   rc   r   r|   r   r   third_party_inline_dirsthird_party_stubs_dirs-found_possible_third_party_missing_type_hintsneed_installed_stubsr   	stub_namestub_dirstub_typed_filestub_componentsr7   runtime_pathnon_stub_matchpython_mypy_pathcandidate_base_dirsseplastsepinitnear_missesr;   r   	base_pathhas_initr   r}   	extension
path_stubslevelsr   ancestorr   r   r    r   |  s   









zFindModuleCache._find_moduler   c                 C  sb   t j|d}t j|r/t|d}t|}W d   n1 s"w   Y  t|ddS dS )zDoes a stub package support the target Python version?

        Stub packages may contain a metadata file which specifies
        whether the stubs are compatible with Python 2 and 3.
        zMETADATA.tomlrbNpython3T)	rh   r7   ri   rg   opentomllibloadr)   rr   )r1   r   metadata_fnamfmetadatar   r   r    r   7  s   z+FindModuleCache._is_compatible_stub_packagerG   c                 C  s  |  |}t|trg S t||d g}d }t|r tj|}n| j	|r(|}|d u r.|S t
 }t| j|}|D ]}|dv sF|drGq;tj||}| jr`t|| jj| j| jjdkr`q;| j	|r| jrm| jjs| jtj|ds| jtj|dr|| || |d |  q;tj|\}	}
|	dkrq;|	|vrd|	vr|
tv r||	 || |d |	  q;|S )N)__pycache__zsite-packagesnode_modulesre   r'   __init__.py__init__.pyir>   )r   ry   r%   r6   r   rh   r7   rs   rT   r{   rK   sortedr   
startswithri   rV   matches_excludeexclude	verbosityr   rg   rM   extendfind_modules_recursiverz   r$   )r1   r9   module_pathrF   r   seennamesr   subpathstemsuffixr   r   r    r   D  sL   



z&FindModuleCache.find_modules_recursiverC   )rS   r   rT   rU   rV   rW   rX   rY   rZ   r[   r*   r<   )r*   r<   )rc   r?   r*   rd   )rc   r?   r   r   r*   r   )r   r   rc   r?   r*   r   )rc   r?   r   r)   r*   r   )r9   r?   r*   r)   )r   r   r   r?   r*   r   )r   r   r   r   r*   r<   )rc   r?   r*   r)   )rc   r?   r   r)   r*   r   )r   r?   r*   r)   )r9   r?   r*   rG   )r   r   r   rD   r>   rb   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r    rR      s$    


1





 
<rR   r   r?   excludesr   rT   r   verboser)   r*   c                 C  sp   |sdS t j| t jd}|| r|d7 }|D ]}t||r5|r2td| d| dt	j
d  dS qdS )NF/zTRACE: Excluding z (matches pattern )rO   T)rh   r7   relpathreplacer   r{   researchprintsysstderr)r   r   rT   r   subpath_strr   r   r   r    r   x  s   
r   r7   c                 C  s   t j| dv S )N)r   r   )rh   r7   r   )r7   r   r   r    r     s   r   rc   prefixc                   sX   t r
tjt|dD ]}tjt fddtD s) dS qdS )z;Check that all packages containing id have a __init__ file.re   c                 3  ,    | ]}  tjd | V  qdS rf   r   rh   r7   ri   rk   r   rT   r7   r   r   r    rn     
    
z verify_module.<locals>.<genexpr>FTr   rh   r7   rs   rt   ru   rv   r$   )rT   rc   r7   r   r   r   r  r    r     s   r   intc                   s^   t r
tjd}t|dD ]}tjt fddtD r,|d }q|S )z:Compute the highest level where an __init__ file is found.r   re   c                 3  r   rf   r  r  r  r   r    rn     r  z%highest_init_level.<locals>.<genexpr>r&   r  )rT   rc   r7   r   levelr   r   r  r    r     s   r   c                  C  s   t d} | s	g S | t jS )NMYPYPATH)rh   getenvr   pathsep)path_envr   r   r    r     s   
r   data_dir	pyversiontuple[int, int]r`   r8   c                 C  s   g }|r3t j|d}t j|dd}t j|d}t j|r&t j|s2td| td n t j| d}t j|rB|} t j| dd}t j| ddd}|	| |	| tj
d	krg|	d
 |sztdtj| tjd td |S )z-Return default standard library search paths.stdlibstubszmypy-extensionsVERSIONSzDerror: --custom-typeshed-dir does not point to a valid typeshed ({})r'   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   r&   )rh   r7   ri   r{   rg   r   r@   r   exitr0   platform
executabler   )r  r  r`   r7   typeshed_dirmypy_extensions_dirversions_fileautor   r   r    default_lib_path  s@   





r  )maxsizepython_executabletuple[list[str], list[str]]c              
   C  s   | du rg g fS | t jkrt \}}||fS zttj| tjdgtj	d
 \}}W ||fS  tyM } zt|j}td|  d| g|d}~ww )zFind package directories for given python.

    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getsearchdirs)r   z!mypy: Invalid python executable 'z': )r   r  r   r  astliteral_eval
subprocesscheck_output__file__PIPEr   r   rh   strerrorerrnor   )r  sys_pathsite_packageserrreasonr   r   r    get_search_dirs  s,   	


r,  rF   rG   rV   r   alt_lib_pathc                   s  t t||j|jd}|jr-tdd}|s!tj	tj	t
}|tj|ddd g }|sY| D ]}|jrD|j}||vrD|| q3|jrKd}nt }||vrY|d| t }	|	|j |rj|	d| t|j\}
}|D ]<  |vs{J  |	v st fd	d
|	D stjjrt fdd
|	D rt  dtjd tdtjd td qsttt|t|	t|
| t|d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
    )r`   MYPY_TEST_PREFIXNz	test-dataunitzlib-stubre   r   c                 3  "    | ]}|  tjj V  qd S r\   )r   rh   r7   r   rk   r|   siter   r    rn   A       z'compute_search_paths.<locals>.<genexpr>c                 3  r0  r\   )r   rh   r7   altsepr1  r2  r   r    rn   B  r4  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 infor&   )r   r   r   r   )collectionsdequer  python_versionr`   r   rh   r	  r7   rs   r$  
appendleftri   r;   r0   bazelr   insertr   r   r,  r  rv   r5  r   r   r   r  r   tuplereversed)rF   rV   r  r-  r   root_dirr   rN   r   mypypathr(  r)  r   r2  r    compute_search_paths  sd   




r@  c                 C  s   | pt jt jtd}t j|d}i }t j|d}t j|s*J | |tft|H}|D ]<}|dd  }|dkrAq1|d\}}|d}	t	|	d }
t
|	d	kre|	d
  ret	|	d
 nd}|
|f||< q1W d   |S 1 syw   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.
    r  r  r  #r   rH   :-r'   r&   N)rh   r7   ri   rs   r$  rg   r   r   r   parse_versionr   )r`   r  
stdlib_dirresultversions_pathr   liner9   version_rangeversionsr   r   r   r   r    ra   T  s*   

&
ra   r   c                 C  s"   |   d\}}t|t|fS )Nre   )r   r   r  )r   majorminorr   r   r    rD  q  s   rD  c                 C  s   t | jdS )zIReturn Python version used for checking whether module supports typeshed.)r      )r   r8  )rV   r   r   r    r   v  s   r   )
r   r?   r   r   rT   r   r   r)   r*   r)   )r7   r?   r*   r)   )
rT   r   rc   r?   r7   r?   r   r?   r*   r)   )
rT   r   rc   r?   r7   r?   r   r?   r*   r  )r*   r   )r  r?   r  r  r`   r8   r*   r   )r  r8   r*   r  r\   )
rF   rG   rV   r   r  r?   r-  r8   r*   r   )r`   r8   r*   r"   )r   r?   r*   r  )rV   r   r*   r  )ArD   
__future__r   r   r6  	functoolsrh   r   r"  r   enumr   r   mypy.errorsr   version_infor   tomlitypingr   r	   r
   r   r   r   typing_extensionsr   r   r!   mypyr   mypy.fscacher   
mypy.nodesr   mypy.optionsr   mypy.stubinfor   r   r?   r)   OnePackageDirr   r  r"   r   r$   r%   r   r6   rE   rR   r   r   r   r   r   r  	lru_cacher,  r@  ra   rD  r   r   r   r   r    <module>   s`    

 04   
\





,
W
