o
    tBh                     @  sd  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
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mZmZmZ ddlmZmZ ddlZddlZddlZddlm Z  ddl!m"Z"m#Z# dd	l$m%Z% dd
l&m'Z'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z; ddl<m=Z=m>Z> ddl?m@Z@ dZAdeBd< e
jCdkrddl	mDZD 	dSdTd#d$ZEndUdVd'd(ZF	dSdTd)d$ZEd*ZGdeBd+< dWd0d1ZHdXd3d4ZIeeJeJf ZKd5eBd6< eeK ZLd5eBd7< eeLeLf ZMd5eBd8< G d9d: d:ZNd;ZOdeBd<< dYd>d?ZP	@dZd[dFdGZQd\dIdJZRd]dQdRZSdS )^zServer for mypy daemon mode.

This implements a daemon process which keeps useful state in memory
to enable fine-grained incremental reprocessing of changes.
    )annotationsN)redirect_stderrredirect_stdout)AbstractSetAnyCallableListSequenceTuple)Final	TypeAlias)receive)InvalidSourceListcreate_source_list)FileSystemCache)FileDataFileSystemWatcher)InspectionEngine)	IPCServer)BuildSourceFindModuleCacheSearchPathscompute_search_paths)Options)FineGrainedBuildManagerrefresh_suppressed_submodules)SuggestionEngineSuggestionFailure)reset_global_state)FancyFormattercount_stats)__version__Fr   MEM_PROFILEwin32)STARTUPINFOoptionsr   status_filestrtimeout
int | Nonelog_file
str | Nonereturnintc              
   C  s   t jddd|dg}t|  ||f}|dt|  d t	 }d|_
d|_ztj|d	|d
 W dS  tjyK } z	|jW  Y d}~S d}~ww )a  Create the daemon process via "dmypy daemon" and pass options via command line

        When creating the daemon grandchild, we create it in a new console, which is
        started hidden. We cannot use DETACHED_PROCESS since it will cause console windows
        to pop up when starting. See
        https://github.com/python/cpython/pull/4150#issuecomment-340215696
        for more on why we can't have nice things.

        It also pickles the options to be unpickled by mypy.
        z-mz
mypy.dmypyz--status-filedaemonz--options-data=""   r      )creationflagsstartupinfoN)sys
executablepickledumpssnapshotappendbase64	b64encodedecoder$   dwFlagswShowWindow
subprocessPopenCalledProcessError
returncode)r%   r&   r(   r*   commandpickled_optionsinfoe rG   h/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/dmypy_server.py	daemonize-   s   rI   funcCallable[[], None]c              	   C  s*  t j  t j  t }|r3t|d\}}|d@ }|r&td| | S |d? }|r1td| |S z[t  t	d t
dtj}t|d t|d t|d	 t| t }|rftd |rt
|d
dd t _t _t j }t|d	 t|d |   W td dS td w )zArrange to call func() in a grandchild of the current process.

        Return 0 for success, exit status for failure, negative if
        subprocess killed by signal.
        r      zChild killed by signal   zChild exit status   z	/dev/nullr0      a)	bufferingN)r4   stdoutflushstderrosforkwaitpidprintsetsidumaskopenO_RDWRdup2close_exitfileno)rJ   r*   pidnpidstssigdevnullfdrG   rG   rH   _daemonize_cbH   s>   







rg   c                 C  s   t t| ||j|S )zRun the mypy daemon in a grandchild of the current process

        Return 0 for success, exit status for failure, negative if
        subprocess killed by signal.
        )rg   Serverserve)r%   r&   r(   r*   rG   rG   rH   rI   u   s   dmypyCONNECTION_NAMEflags	list[str]allow_sourcesboolc                 C  sf   t jjdg|  ddd\}}|jrtd |jrtd d |_|js'td |j	dvr1td	 |S )
N-iFT)require_targetsserver_optionszRdmypy: Ignoring report generation settings. Start/restart cannot generate reports.zxdmypy: Ignoring report generation settings. Start/restart does not support --junit-xml. Pass it to check/recheck insteadz8dmypy: start/restart should not disable incremental mode)skiperrornormalz*dmypy: follow-imports=silent not supported)
mypymainprocess_optionsreport_dirsrX   	junit_xmlincrementalr4   exitfollow_imports)rl   rn   _r%   rG   rG   rH   process_start_options   s   



r   modulec                 C  s
   |  dS )z=Can we skip looking for newly unsuppressed imports to module?z
encodings.)
startswithr   rG   rG   rH   ignore_suppressed_imports   s   
r   
_TypeAliasModulePathPairModulePathPairsChangesAndRemovalsc                   @  sJ  e Zd Zdxdyd
dZdzddZd{ddZd|ddZdxd}ddZd~ddZdd$d%Z	dd'd(Z
		ddd,d-Zdd1d2Zd{d3d4Zdd6d7Zdd8d9Zdd:d;Z		ddd=d>Zdd?d@ZddIdJZddMdNZddRdSZddUdVZ	W	dddYdZZdd[d\Zdd^d_Zdd`daZddbdcZ	d	d	W	W	W	W	WdddndoZddtduZd~dvdwZdS )rh   Nr%   r   r&   r'   r(   r)   r,   Nonec                 C  s   || _ | | _|| _d| _tj|rt| t	 | _
d|_d|_d|_d|_|jr0d|_ntj|_d|_|| _ttjtj|j| _dS )z2Initialize the server with the desired mypy flags.NT)r%   r8   options_snapshotr(   fine_grained_managerrU   pathisfileunlinkr   fscacheraise_exceptionsr{   fine_grained_incrementalshow_tracebackuse_fine_grained_cachecache_fine_grainedre   	cache_dirlocal_partial_typesr&   r   r4   rR   rT   show_error_codes	formatter)selfr%   r&   r(   rG   rG   rH   __init__   s"   

zServer.__init__dict[str, str]c                 C  s,   | j jd  d| j jd  }| j j|dS )Nr   r~   r0   )platformpython_version)r%   r   r   )r   
py_versionrG   rG   rH   _response_metadata   s   zServer._response_metadatac                 C  s  d}t t| j}zt| jd}tt |j	d| |
d W d   n1 s+w   Y  	 | t|}i }d|vrCddi}nF|d }t|tsQdd	i}n8|d}z| ||}W n* ty   tjt  }dd
d| i}||   |
t|d  w z||   |
t|d W n	 ty   Y nw |dkrt  td W d   n1 sw   Y  q1|dkrt| j z|  W n	 ty   Y nw t }|d r|d turtj |  w w w )z2Serve requests, synchronously (no thread or fork).Nw)ra   connection_name
TrC   rt   zNo command found in requestzCommand is not a stringzDaemon crashed!
 utf8stopr   )!r   rk   r(   r[   r&   jsondumprU   getpidr   writer   
isinstancer'   poprun_command	Exception	tracebackformat_exceptionr4   exc_infojoinupdater   r7   encodeOSErrorr   r|   r   cleanup
SystemExitprint_exception)r   rC   serverfdataresptbr   rG   rG   rH   ri      sb   




#zServer.serverC   r   dict[str, object]c                 C  sR   d| }t | j|d}|du rdd| diS |dvr!|d= |d= || fi |S )	z)Run a specific command from the registry.cmd_Nrt   zUnrecognized command ''>   runcheckrecheckis_ttyterminal_width)getattr	__class__)r   rC   r   keymethodrG   rG   rH   r     s   zServer.run_commandfswatcher_dump_filer+   c                 C  sp   i }| t  |r6t| dr| j ni }t|}t|d}|| W d   |S 1 s1w   Y  |S )zReturn daemon status.	fswatcherr   N)	r   get_meminfohasattrr   dump_file_datar   r7   r[   r   )r   r   resr   sr   rG   rG   rH   
cmd_status  s   

zServer.cmd_statusc                 C  s   t | j i S )zStop daemon.)rU   r   r&   r   rG   rG   rH   cmd_stop  s   zServer.cmd_stopversionargsSequence[str]export_typesro   r   r   r-   c              
   C  sx  t  }t  }zut|1 t| tjjdgt| dd| jdt	j
d\}}	W d   n1 s2w   Y  W d   n1 sAw   Y  | j|	 krRddiW S t|kr[ddiW S | jr|| jj}
|
j}tjj|	|
jtjd	d
\}}||kr|ddiW S W n6 ty } zdt|ddW  Y d}~S d}~w ty } z| | |jdW  Y d}~S d}~ww | ||||S )z6Check a list of files, triggering a restart if needed.rp   Tzmypy-daemon)rq   rr   r   programheaderNrestartzconfiguration changedzmypy version changedrG   )extra_pluginszplugins changedr   rO   outerrstatus)ioStringIOr   r   rv   rw   rx   listr   argparseSUPPRESSr   r8   r!   r   managerplugins_snapshotbuildload_pluginserrorsr4   rR   r   r'   r   getvaluecoder   )r   r   r   r   r   r   rT   rR   sourcesr%   r   start_plugins_snapshotr~   current_plugins_snapshotr   rF   rG   rG   rH   cmd_run'  sJ   	





"zServer.cmd_runfilesc              
   C  sZ   z
t || j| j}W n ty$ } zdt|ddW  Y d}~S d}~ww | ||||S )zCheck a list of files.r   rO   r   N)r   r%   r   r   r'   r   )r   r   r   r   r   r   r   rG   rG   rH   	cmd_checkR  s   zServer.cmd_checkremovelist[str] | Noner   c              
     s<  t   }| jsddiS | j}|rt|fdd|D }|rXdd |D   fdd|D }z
t|| j| j}	W n tyS }
 zdt|
d	d
W  Y d}
~
S d}
~
ww ||	 }t   }| jj	}|
d|| dd || j_|  s|| |||}n|du r|du sJ | |}| ||||}|   | | |S )zCheck the same list of files we checked most recently.

        If remove/update is given, they modify the previous list;
        if all are None, stat() is called for each file in the previous list.
        rt   z7Command 'recheck' is only valid after a 'check' commandc                   s    g | ]}|j r|j  vr|qS rG   r   .0r   )removalsrG   rH   
<listcomp>o  s     z&Server.cmd_recheck.<locals>.<listcomp>c                 S  s   h | ]}|j r|j qS rG   r   r   rG   rG   rH   	<setcomp>q      z%Server.cmd_recheck.<locals>.<setcomp>c                   s   g | ]}| vr|qS rG   rG   )r   p)knownrG   rH   r   r  r   r   rO   r   Nz%fine-grained increment: cmd_recheck: .3fr   )timer   previous_sourcessetr   r%   r   r   r'   r   logr   following_importsfine_grained_increment%fine_grained_increment_follow_importsincrement_outputflush_cachesupdate_stats)r   r   r   r   r   r   t0r   addedadded_sourcesr   t1r   messagesr   rG   )r   r   rH   cmd_recheck\  s:   

zServer.cmd_recheckr   list[BuildSource]dict[str, Any]c                 C  sb   || j _| js| |||}n|  s| |}n| |}| ||||}|   | 	| |S )zCheck using fine-grained incremental mode.

        If is_tty is True format the output nicely with colors and summary line
        (unless disabled in self.options). Also pass the terminal_width to formatter.
        )
r%   r   r   initialize_fine_grainedr   r  r  r  r  r  )r   r   r   r   r   r   r
  rG   rG   rH   r     s   

zServer.checkc                 C  s"   | j   | jr| j  d S d S N)r   rS   r   flush_cacher   rG   rG   rH   r    s   
zServer.flush_cachesr   c                 C  s.   | j r| j j}|  |j|d< i |_d S d S )Nstats)r   r   
dump_statsr  )r   r   r   rG   rG   rH   r    s   

zServer.update_statsc                 C  s   | j jdkS )zAre we following imports?ru   )r%   r}   r   rG   rG   rH   r     s   zServer.following_importsc              
   C  sr  t | j| _t }| | t }ztjj|| j| jd}W n3 tjj	yS } z%d
dd |jD }|jr>|d}	}
nd|}	}
|	|
ddW  Y d }~S d }~ww |j}t|| _|  rlt| jj|}| | || _|jrt }| jj D ]#}|j}|d u rq}|jd usJ | j|jtt|j|j|jd q}| |\}}|| | jjt | jj j!7 }| jj D ]}|" s|jd usJ |#|j$|jf qt }| j%||}|  r| &|}t }| jj j'|| || || || t(|t(| d n| j  t)rd	d
l*m+} |dd |rdnd	}| ,|t(|||}d
dd |D d|dS )N)r   r%   r   r   c                 s      | ]}|d  V  qdS r   NrG   r   rG   rG   rH   	<genexpr>      z1Server.initialize_fine_grained.<locals>.<genexpr>rO   r   )st_mtimest_sizehash)update_sources_time
build_timefind_changes_timefg_update_timefiles_changedr   )print_memory_profileF)run_gcr0   c                 s  r  r  rG   r   rG   rG   rH   r    r  )-r   r   r   r   update_sourcesrv   r   r%   r   CompileErrorr   r
  
use_stdoutr   r   r   find_all_sources_in_buildgraphr   
used_cachevaluesmetar   set_file_datar   floatmtimesizer  find_changedfind_added_suppressedr   r   search_pathsis_freshr9   idr   r  	add_statslenr"   mypy.memprofiler  pretty_messages)r   r   r   r   r  r	  resultrF   outputr   r   r
  t2stater(  changedremovedt3t4r  r   rG   rG   rH   r    sz   







zServer.initialize_fine_grainedrm   c                 C  s
  | j dusJ | j j}t }|du r$|du r$| | | |\}}n| ||p*g |p-g \}}|| | j jt |j	7 }t
||j|j|_	t }|d|| dd | j ||}	t }
|d|
| dd |j|| |
| t|t| d || _|	S )a  Perform a fine-grained type checking increment.

        If remove and update are None, determine changed paths by using
        fswatcher. Otherwise, assume that only these files have changes.

        Args:
            sources: sources passed on the command line
            remove: paths of files that have been removed
            update: paths of files that have been changed or created
        N&fine-grained increment: find_changed: r   r    fine-grained increment: update: )r  r  r  )r   r   r   r!  r-  update_changedr.  r%  r   r/  r   r%   data_dirr   r   r2  r3  r   )r   r   r   r   r   r  r:  r;  r	  r
  r8  rG   rG   rH   r    s.   
zServer.fine_grained_incrementc                   s  t   }| jdusJ | j  j} j}t| }| | | j }t	||j
|j|_t   }|d|| dd dd |D | |||\}}	||	  |g }
|dd }|r| }|d |vrlq_| ||}fdd	|D }| |||\}}	| |	  |g }
|| |sat   }d fdd}t| D ]\}}t||j j|| j|}|dur|}
qt   }	 | ||j}|sn0dd	 |D }	||	 | |	  |g }
|D ]\}}t|| j|| j|}|dur|}
qqt   }g }|D ]"}||vrq|vr(|| j}|dus!J |||f q|r3 g |}
t| t|| _| | j | j  t   }|d|| dd |j|| || || || || d |
S )z0Like fine_grained_increment, but follow imports.Nr>  r   r   c                 S     h | ]}|j qS rG   r   r   sourcerG   rG   rH   r   D      z?Server.fine_grained_increment_follow_imports.<locals>.<setcomp>r   c                      g | ]	}|j  vr|qS rG   r   rC  )seenrG   rH   r   Y      z@Server.fine_grained_increment_follow_imports.<locals>.<listcomp>r   r'   r   r,   rm   c                   s     | |fgg S r  )r   )r   r   )r   rG   rH   refresh_filec  s   zBServer.fine_grained_increment_follow_imports.<locals>.refresh_fileTc                 S  s   g | ]}t |d  |d qS )r0   r   )r   )r   modrG   rG   rH   r   u  s    r?  )r  r  refresh_suppressed_timefind_added_supressed_timecleanup_time)r   r'   r   r'   r,   rm   )r   r   r%  r   r   keysr!  r   r-  r   r%   rA  r/  r   find_reachable_changed_modulesextendr   r   direct_importsitemsr   r   depsr   r.  r9   fix_module_depsr$  r   r2  )r   r   r  r%  r   orig_moduleschanged_pathsr	  r:  	new_filesr
  worklistr   sources2r8  rI  	module_idr9  new_messagesr<  new_unsuppressedr   r=  	to_deletemodule_patht5rG   )r   rG  rH   r  0  s   











z,Server.fine_grained_increment_follow_importsrootsr%  mypy.build.GraphrG  set[str]rV  AbstractSet[str]/tuple[list[tuple[str, str]], list[BuildSource]]c                 C  s   g }g }|dd }| dd |D  |ri| }|j|vr*||j || |j|v r@|jdus6J ||j|jf n'|j|v rg||j }	|	jD ]}
|
|vrf||
 |t||
 j||
 j qM|s||fS )aj  Follow imports within graph from given sources until hitting changed modules.

        If we find a changed module, we can't continue following imports as the imports
        may have changed.

        Args:
            roots: modules where to start search from
            graph: module graph to use for the search
            seen: modules we've seen before that won't be visited (mutated here!!)
            changed_paths: which paths have changed (stop search here and return any found)

        Return (encountered reachable changed modules,
                unchanged files not in sources_set traversed).
        Nc                 s  s    | ]}|j V  qd S r  r   rC  rG   rG   rH   r    s    z8Server.find_reachable_changed_modules.<locals>.<genexpr>)	r   r   r   addr9   r   dependenciesr   r1  )r   r`  r%  rG  rV  r:  rW  rX  nxtr9  deprG   rG   rH   rO    s*   






z%Server.find_reachable_changed_modulesr   tuple[str, str]c                   s     |d  } fdd|j D S )z9Return the direct imports of module not included in seen.r   c                   s   g | ]
}t  | j|qS rG   )r   r   )r   rh  r%  rG   rH   r         z)Server.direct_imports.<locals>.<listcomp>)rf  )r   r   r%  r9  rG   rj  rH   rQ    s   zServer.direct_importsr/  r   list[tuple[str, str]]c                   s   t  }  D ]}||jO }q fdd|D }dd |D }t||| j}t|| j| j}g }|D ]5}	|	ddd }
|
|vrAq2|j|	dd}t	|t
rg|	|vrg|  s[|d	s[q2||	|f ||	 q2|S )
zFind suppressed modules that have been added (and not included in seen).

        Args:
            seen: reachable modules we've seen before (mutated here!!)

        Return suppressed, added modules.
        c                   s    h | ]}| vrt |s|qS rG   )r   r   r   rj  rG   rH   r     s
    z/Server.find_added_suppressed.<locals>.<setcomp>c                 S  s   h | ]
}| d dd qS ).r0   r   )splitrm  rG   rG   rH   r     rk  rn  r0   r   T)	fast_path.pyi)r   r'  suppressed_set%filter_out_missing_top_level_packagesr   r   r%   ro  find_moduler   r'   r   endswithr9   re  )r   r%  rG  r/  all_suppressedr9  packagesfinderfoundr   top_level_pkgr6  rG   rj  rH   r.    s,   

	
zServer.find_added_suppressedr
  c                 C  s<   |rdnd}|  |t|||}ddd |D d|dS )Nr0   r   r   c                 s  r  r  rG   r   rG   rG   rH   r    r  z*Server.increment_output.<locals>.<genexpr>r   )r5  r3  r   )r   r
  r   r   r   r   rG   rG   rH   r    s   zServer.increment_outputF	n_sourcesc                   s    j jo|} j jo|}|r jj||d} j jrFd }t|\}}	}
|r0 jj||
||d}n|r8|	t|kr? j	||}|rF||g }|rQ fdd|D }|S )N)fixed_terminal_width)	use_colorc                   s   g | ]} j |qS rG   )r   colorize)r   mr   rG   rH   r   '  r   z*Server.pretty_messages.<locals>.<listcomp>)
r%   color_outputprettyr   fit_in_terminalerror_summaryr    format_errorr3  format_success)r   r
  r{  r   r   r}  	fit_widthsummaryn_errorsn_notesn_filesrG   r   rH   r5    s(   
zServer.pretty_messagesc                   s8   dd |D }   r fdd|D } j| d S )Nc                 S  s   g | ]
}|j d ur|j qS r  r   rC  rG   rG   rH   r   +  rk  z)Server.update_sources.<locals>.<listcomp>c                   s   g | ]
} j |r|qS rG   )r   r   )r   r   r   rG   rH   r   .  rk  )r   r   add_watched_paths)r   r   pathsrG   r   rH   r!  *  s   zServer.update_sourcesr   c                 C  s   | j ||}| ||S r  )r   r@  _find_changed)r   r   r   r   rV  rG   rG   rH   r@  1  s   zServer.update_changedc                 C  s   | j  }| ||S r  )r   r-  r  )r   r   rV  rG   rG   rH   r-  8  s   
zServer.find_changedc           
        s    fdd|D }dd |D fdd| j D }g }|D ]}|j}|s'J ||j|f qdd | j D }|D ](}	|	jsAJ |	j|v rb||	j |	jkrb|||	j |	jf ||	j|	jf q:||fS )Nc                   s(   g | ]}|j r|j  v r|j|j fqS rG   r   r   rC  )rV  rG   rH   r   @  s    

z(Server._find_changed.<locals>.<listcomp>c                 S  rB  rG   r   rC  rG   rG   rH   r   G  rE  z'Server._find_changed.<locals>.<setcomp>c                   rF  rG   r   rC  )modulesrG   rH   r   H  rH  c                 S  s   i | ]}|j |jqS rG   r  r   rG   rG   rH   
<dictcomp>P  s    z(Server._find_changed.<locals>.<dictcomp>)r   r   r9   r   )
r   r   rV  r:  omittedr;  rD  r   lastr   rG   )rV  r  rH   r  <  s$   

zServer._find_changedr   showlocation	verbositylimitinclude_spaninclude_kindinclude_object_attrsunion_attrsforce_reloadc
              
   C  s   t jdk r	ddiS | jsddiS t| j|||||||	d}
| jj}d| j_z(|dkr0|
|}n|dkr:|
|}n|d	krD|
|}nJ dW || j_n|| j_w d|v rht	|d t
s`J |d  d7  < |S )z!Locate and inspect expression(s).)   rM   rt   z)Python 3.8 required for "inspect" commandzWCommand "inspect" is only valid after a "check" command (that produces no parse errors))r  r  r  r  r  r  r  Ttypeattrs
definitionFzUnknown inspection kindr   r   )r4   version_infor   r   r%   inspectionsget_type	get_attrsget_definitionr   r'   )r   r  r  r  r  r  r  r  r  r  engineold_inspectionsr6  rG   rG   rH   cmd_inspectZ  s>   

zServer.cmd_inspectfunction	callsiteskwargsr   c              
   K  s   | j sddiS t| j fi |}zFz|r||}n||}W n ty= } zdt|iW  Y d}~W |   S d}~ww |sCd}n	|dsL|d7 }|dddW |   S |   w )	z#Suggest a signature for a function.rt   zWCommand 'suggest' is only valid after a 'check' command (that produces no parse errors)NzNo suggestions
r   r   r   r   )r   r   suggest_callsitessuggestr   r'   r  ru  )r   r  r  r  r  r   r   rG   rG   rH   cmd_suggest  s(   


zServer.cmd_suggestc                 C  s   t d i S )z&Hang for 100 seconds, as a debug hack.d   )r   sleepr   rG   rG   rH   cmd_hang  s   
zServer.cmd_hangr  )r%   r   r&   r'   r(   r)   r,   r   )r,   r   )r,   r   )rC   r'   r   r   r,   r   )r   r+   r,   r   )r,   r   )r   r'   r   r   r   ro   r   ro   r   r-   r,   r   )
r   r   r   ro   r   ro   r   r-   r,   r   NN)r   ro   r   r-   r   ro   r   r   r   r   r,   r   )
r   r  r   ro   r   ro   r   r-   r,   r  )r   r  r,   r   )r,   ro   )r   r  r   ro   r   r-   r,   r  )r   r  r   r   r   r   r,   rm   )r   r  r,   rm   )
r`  r  r%  ra  rG  rb  rV  rc  r,   rd  )r   ri  r%  ra  r,   r  )r%  ra  rG  rb  r/  r   r,   rl  )
r
  rm   r   r  r   ro   r   r-   r,   r  )FN)
r
  rm   r{  r-   r   ro   r   r)   r,   rm   )r   r  r,   r   )r   r  r   rm   r   rm   r,   r   )r   r  r,   r   )r   r  rV  rc  r,   r   )r   r   FFFFF)r  r'   r  r'   r  r-   r  r-   r  ro   r  ro   r  ro   r  ro   r  ro   r,   r   )r  r'   r  ro   r  r   r,   r   )__name__
__module____qualname__r   r   ri   r   r   r   r   r   r  r   r  r  r   r  r  r  rO  rQ  r.  r  r5  r!  r@  r-  r  r  r  r  rG   rG   rG   rH   rh      sT    
 

5

	
+
*



X
/
t
)

2



"
0rh   i   MiBr  c                  C  s   i } zdd l }W n ty   d| d< Y | S w | }| }|jt | d< |jt | d< tjdkr;|j	t | d< | S dd l
}||j}tjdkrMd	}nd
}|j| t | d< | S )Nr   zXpsutil not found, run pip install mypy[dmypy] to install the needed components for dmypymemory_psutil_missingmemory_rss_mibmemory_vms_mibr#   memory_maxrss_mibdarwinr0   i   )psutilImportErrorProcessmemory_inforssr  vmsr4   r   	peak_wsetresource	getrusageRUSAGE_SELF	ru_maxrss)r   r  processmeminfor  rusagefactorrG   rG   rH   r     s,   

r   rG   r%  ra  extraSequence[BuildSource]r  c                 C  sF   t |}dd |D }|  D ]\}}||vr |t|j| q|S )Nc                 S  rB  rG   r   rC  rG   rG   rH   r     rE  z,find_all_sources_in_build.<locals>.<setcomp>)r   rR  r9   r   r   )r%  r  r6  rG  r   r9  rG   rG   rH   r$    s   r$  r   c                 C  sn   |   D ]0\}}g }g }|j|j D ]}|| v r|| q|| q||_t||_||_t||_qdS )zAfter an incremental update, update module dependencies to reflect the new state.

    This can make some suppressed dependencies non-suppressed, and vice versa (if modules
    have been added to or removed from the build).
    N)rR  rf  
suppressedr9   r   dependencies_setrr  )r%  r   r9  new_suppressednew_dependenciesrh  rG   rG   rH   rT    s   
rT  rw  rb  r/  r   r   r   c              	   C  s   t  }|j|j |j |j }|D ]F}z||}W n ty%   g }Y nw |D ].}|dr6|dd }n|drB|dd }n|drM|dd }|| v rV|| q(q|S )a  Quickly filter out obviously missing top-level packages.

    Return packages with entries that can't be found removed.

    This is approximate: some packages that aren't actually valid may be
    included. However, all potentially valid packages must be returned.
    z.pyNrq  z-stubsi)	r   python_path	mypy_pathpackage_pathtypeshed_pathlistdirr   ru  re  )rw  r/  r   ry  r  r   entriesentryrG   rG   rH   rs    s6   



rs  r  )
r%   r   r&   r'   r(   r)   r*   r+   r,   r-   r  )rJ   rK   r*   r+   r,   r-   )rl   rm   rn   ro   r,   r   )r   r'   r,   ro   )r,   r  )rG   )r%  ra  r  r  r,   r  )r%  ra  r,   r   )rw  rb  r/  r   r   r   r,   rb  )T__doc__
__future__r   r   r:   r   r   rU   r6   r?   r4   r   r   
contextlibr   r   typingr   r   r   r   r	   r
   typing_extensionsr   r   r   
mypy.buildrv   mypy.errors	mypy.mainmypy.dmypy_utilr   mypy.find_sourcesr   r   mypy.fscacher   mypy.fswatcherr   r   mypy.inspectionsr   mypy.ipcr   mypy.modulefinderr   r   r   r   mypy.optionsr   mypy.server.updater   r   mypy.suggestionsr   r   mypy.typestater   	mypy.utilr   r    mypy.versionr!   r"   __annotations__r   r$   rI   rg   rk   r   r   r'   r   r   r   rh   r  r   r$  rT  rs  rG   rG   rG   rH   <module>   st     
.

      

