o
    2gɮ                     @  sv  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mZ ddlmZ ddlZddlZddlZddlm Z m!Z!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/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@ ddlAmBZB dZCdeDd< e
jEdkrddl	mFZF 	dXdYd#d$ZGndZd[d'd(ZH	dXdYd)d$ZGd*ZIdeDd+< d\d0d1ZJd]d3d4ZKeeLeLf ZMd5eDd6< eeM ZNd5eDd7< eeNeNf ZOd5eDd8< G d9d: d:ZPd;ZQdeDd<< d^d>d?ZR	@d_d`dFdGZSdadLdMZTdbdNdOZUdcdVdWZVdS )dzServer 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FinalListSequenceTuple)	TypeAlias)WriteToConnreceivesend)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|  }|dt|  d |r(|d|  |r2|d|  t	 }d	|_
d
|_ztj|d|d W d
S  tjy\ } 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=""z
--timeout=z--log-file=   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 rI   I/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/dmypy_server.py	daemonize-   s"   rK   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/nullr2      a)	bufferingN)r6   stdoutflushstderrosforkwaitpidprintsetsidumaskopenO_RDWRdup2close_exitfileno)rL   r,   pidnpidstssigdevnullfdrI   rI   rJ   _daemonize_cbL   s>   







ri   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.
        )ri   Serverserve)r'   r(   r*   r,   rI   rI   rJ   rK   y   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_dirsrZ   	junit_xmlincrementalr6   exitfollow_imports)rn   rp   _r'   rI   rI   rJ   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   rI   rI   rJ   ignore_suppressed_imports   s   
r   
_TypeAliasModulePathPairModulePathPairsChangesAndRemovalsc                   @  sP  e Zd Zdydzd
dZd{ddZd|ddZd}ddZdyd~ddZdddZdd$d%Z	dd'd(Z
		ddd,d-Zdd1d2Zd|d3d4Zdd6d7Zdd8d9Zdd:d;Z			<ddd?d@Z	<dddAdBZddKdLZddOdPZddTdUZddWdXZ	<	dddZd[Zdd\d]Zdd_d`ZddadbZddcddZ	e	e	<	<	<	<	<dddodpZddudvZddwdxZdS )rj   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'   r:   options_snapshotr*   fine_grained_managerrW   pathisfileunlinkr   fscacheraise_exceptionsr}   fine_grained_incrementalshow_tracebackuse_fine_grained_cachecache_fine_grainedrg   	cache_dirlocal_partial_typesr(   r!   r6   rT   rV   hide_error_codes	formatter)selfr'   r(   r*   rI   rI   rJ   __init__   s"   

zServer.__init__dict[str, str]c                 C  s,   | j jd  d| j jd  }| j j|dS )Nr   r   r2   )platformpython_version)r'   r   r   )r   
py_versionrI   rI   rJ   _response_metadata   s   zServer._response_metadatac           
      C  s"  d}t t| j}tj}tj}zt| jd}t	t
 |jd| |d W d   n1 s1w   Y  	 | t|}t|dtj t_t|dtj t_i }d|vr]d	d
i}nD|d }t|tskd	di}n6|d}z| ||}W n( ty   tjt  }d	dd| i}||   d|d< t||  w d|d< z||   t|| W n	 ty   Y nw |dkrt  td W d   n1 sw   Y  q7|t_|t_|dkrt
 | j z|!  W n	 ty   Y nw t }	|	d r|	d t"urtj#|	  w w w )z2Serve requests, synchronously (no thread or fork).Nw)rc   connection_name
TrT   rV   rE   rv   zNo command found in requestzCommand is not a stringzDaemon crashed!
 finalstopr   )$r   rm   r*   r6   rT   rV   r]   r(   jsondumprW   getpidr   writer   r   isatty
isinstancer)   poprun_command	Exception	tracebackformat_exceptionexc_infojoinupdater   r   OSErrorr    r~   r   cleanup
SystemExitprint_exception)
r   rE   serverorig_stdoutorig_stderrfdataresptbr   rI   rI   rJ   rk      sr   





#zServer.serverE   r   dict[str, object]c                 C  sd   d| }t | j|d}|du rdd| diS |dvr!|d= |d= || fi |}t|ts0J |S )	z)Run a specific command from the registry.cmd_Nrv   zUnrecognized command ''>   runcheckrecheckis_ttyterminal_width)getattr	__class__r   dict)r   rE   r   keymethodretrI   rI   rJ   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   r9   r]   r   )r   r   resr   sr   rI   rI   rJ   
cmd_status#  s   

zServer.cmd_statusc                 C  s   t | j i S )zStop daemon.)rW   r   r(   r   rI   rI   rJ   cmd_stop/  s   zServer.cmd_stopversionargsSequence[str]export_typesrq   r   r   r/   c              
   C  sv  t  }t  }ztt|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sQddiW S t|krZd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.rr   Tzmypy-daemon)rs   rt   r   programheaderNrestartzconfiguration changedzmypy version changedrI   )extra_pluginszplugins changedr   rQ   outerrstatus)ioStringIOr   r   rx   ry   rz   listr   argparseSUPPRESScompare_stabler   r#   r   managerplugins_snapshotbuildload_pluginserrorsr6   rT   r   r)   r   getvaluecoder   )r   r   r   r   r   r   rV   rT   sourcesr'   r   start_plugins_snapshotr   current_plugins_snapshotr   rH   rI   rI   rJ   cmd_run8  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   rQ   r   N)r   r'   r   r   r)   r   )r   r   r   r   r   r   r   rI   rI   rJ   	cmd_checkc  s   zServer.cmd_checkremovelist[str] | Noner   c              
     sn  t   }| jsddiS | j}|rt|fdd|D }|ra|jdd dd d	d
 |D   fdd|D }z
t|| j| j}	W n ty\ }
 zdt	|
ddW  Y d}
~
S d}
~
ww ||	 }t   }| jj
}|d|| dd | jj}| jjp~|| j_|  s| j||||d}n|du r|du sJ | j||d}| ||||}|   | | || j_|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.
        rv   z7Command 'recheck' is only valid after a 'check' commandc                   s    g | ]}|j r|j  vr|qS rI   r   .0r   )removalsrI   rJ   
<listcomp>       z&Server.cmd_recheck.<locals>.<listcomp>c                 S  s   t j| d S )Nr2   )rW   r   splitext)r   rI   rI   rJ   <lambda>  s    z$Server.cmd_recheck.<locals>.<lambda>T)r   reversec                 S  s   h | ]}|j r|j qS rI   r   r   rI   rI   rJ   	<setcomp>      z%Server.cmd_recheck.<locals>.<setcomp>c                   s   g | ]}| vr|qS rI   rI   )r   p)knownrI   rJ   r     r  r   rQ   r   Nz%fine-grained increment: cmd_recheck: .3fr   explicit_export_types)timer   previous_sourcessetsortr   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   old_export_typesmessagesr   rI   )r  r   rJ   cmd_recheckm  sH   
zServer.cmd_recheckr   list[BuildSource]dict[str, Any]c                 C  s   | j j}| j jp	|| j _| js| |||}n|  s#| j||d}n| j||d}| ||||}|   | 	| || j _|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   r   initialize_fine_grainedr  r  r  r  r  r  )r   r   r   r   r   r  r   r  rI   rI   rJ   r     s   
zServer.checkc                 C  s"   | j   | jr| j  d S d S N)r   rU   r   flush_cacher   rI   rI   rJ   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   rI   rI   rJ   r    s   

zServer.update_statsc                 C  s   | j jdkS )zAre we following imports?rw   )r'   r   r   rI   rI   rJ   r    s   zServer.following_importsc              
   C  s  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|| _t|}|  rpt| 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 t,|\}}}|r1|t|k r1dnd	}| -||||}d
dd |D d|dS )N)r   r'   r   r   c                 s      | ]}|d  V  qdS r   NrI   r   rI   rI   rJ   	<genexpr>      z1Server.initialize_fine_grained.<locals>.<genexpr>rQ   r   )st_mtimest_sizehash)update_sources_time
build_timefind_changes_timefg_update_timefiles_changedr   )print_memory_profileF)run_gcr2   c                 s  r"  r#  rI   r   rI   rI   rJ   r$     r%  ).r   r   r   r	  update_sourcesrx   r   r'   r   CompileErrorr   r  
use_stdoutr   r   lenr  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_freshr;   idr   r  	add_statsr$   mypy.memprofiler.  r"   pretty_messages)r   r   r   r   r  r  resultrH   outputr   r   r  original_sources_lent2stater8  changedremovedt3t4r.  __n_notesr   rI   rI   rJ   r    s~   







zServer.initialize_fine_grainedFr  ro   c                 C  s  | j dusJ | j j}t }|du r$|du r$| | | |\}}n| ||p*g |p-g \}}|r8t|| || | 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
            explicit_export_types: --export-type was passed in a check command
              (as opposite to being set in dmypy start)
        N&fine-grained increment: find_changed: r  r    fine-grained increment: update: )r+  r,  r-  )r   r   r	  r0  r=  update_changedadd_all_sources_to_changedr>  r5  r  r?  r   r'   data_dirr  r   rB  r3  r
  )r   r   r   r   r  r   r  rJ  rK  r  r  rH  rI   rI   rJ   r  "  s2   

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 | |||\}	}
|rUt||	 ||
  j|	g dd}|	 }|r| }|d	 |vrsqf| ||}fd
d|D }| |||\}	}
| |
  j|	g dd}||	 |sht   }d fdd}t| D ]\}}t||j j|| j|}|dur|}qt   }	 | ||j}|sn3dd |D }
||
 | |
  j|g dd}|D ]\}}t|| j|| j|}|dur	|}qqt   }g }|D ]"}||vrq|vr4|| j}|dus-J |||f q|r? g |}t| t|| _| | j | j  t   }|d|| dd |j|| || || || || d |S )z0Like fine_grained_increment, but follow imports.NrP  r  r   c                 S     h | ]}|j qS rI   r   r   sourcerI   rI   rJ   r  n      z?Server.fine_grained_increment_follow_imports.<locals>.<setcomp>Tfollowedr   c                      g | ]	}|j  vr|qS rI   r   rV  )seenrI   rJ   r         z@Server.fine_grained_increment_follow_imports.<locals>.<listcomp>r   r)   r   r.   ro   c                   s    j | |fgg ddS )NTrY  )r   )r   r   )r   rI   rJ   refresh_file  s   zBServer.fine_grained_increment_follow_imports.<locals>.refresh_filec                 S  s"   g | ]}t |d  |d ddqS )r2   r   TrY  )r   )r   modrI   rI   rJ   r     s   " rQ  )r+  r,  refresh_suppressed_timefind_added_supressed_timecleanup_time)r   r)   r   r)   r.   ro   ) r	  r   r5  r   r   keysr0  r   r=  r   r'   rT  r?  r  find_reachable_changed_modulesrS  extendr   copyr   direct_importsitemsr   r   depsr   r>  r;   fix_module_depsr4  r
  rB  )r   r   r  r  r5  r   orig_moduleschanged_pathsr  rJ  	new_filesr  worklistr   sources2rH  r^  	module_idrI  new_messagesrL  new_unsuppressedr   rM  	to_deletemodule_patht5rI   )r   r\  rJ   r  X  s   













z,Server.fine_grained_increment_follow_importsrootsr5  mypy.build.Graphr\  set[str]rl  AbstractSet[str]/tuple[list[tuple[str, str]], list[BuildSource]]c                 C  s   g }g }|  }|dd |D  |ri| }|j|vr(||j || |j|v r>|jdus4J ||j|jf n)|j|v rg||j }	|	jD ]}
|
|vrf||
 |t||
 j||
 j	dd qK|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).
        c                 s  s    | ]}|j V  qd S r  r   rV  rI   rI   rJ   r$    s    z8Server.find_reachable_changed_modules.<locals>.<genexpr>NTrY  )
rf  r   r   r   addr;   r   dependenciesr   rA  )r   rv  r5  r\  rl  rJ  rm  rn  nxtrI  deprI   rI   rJ   rd    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|d dqS )TrY  )r   r   )r   r~  r5  rI   rJ   r     r   z)Server.direct_imports.<locals>.<listcomp>)r|  )r   r   r5  rI  rI   r  rJ   rg    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 rI   )r   r   r   r  rI   rJ   r    s
    z/Server.find_added_suppressed.<locals>.<setcomp>c                 S  s   h | ]
}| d dd qS ).r2   r   )splitr  rI   rI   rJ   r        r  r2   r   T)	fast_path.pyi)r  r7  suppressed_set%filter_out_missing_top_level_packagesr   r   r'   r  find_moduler   r)   r  endswithr;   r{  )r   r5  r\  r?  all_suppressedrI  packagesfinderfoundr   top_level_pkgrE  rI   r  rJ   r>    s,   

	
zServer.find_added_suppressedr  c                 C  s<   |rdnd}|  |t|||}ddd |D d|dS )Nr2   r   r   c                 s  r"  r#  rI   r   rI   rI   rJ   r$  8  r%  z*Server.increment_output.<locals>.<genexpr>r   )rD  r3  r   )r   r  r   r   r   r   rI   rI   rJ   r  3  s   zServer.increment_output	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 rI   )r   colorize)r   mr   rI   rJ   r   T  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_errorsrO  n_filesrI   r   rJ   rD  :  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   rV  rI   rI   rJ   r   X  r  z)Server.update_sources.<locals>.<listcomp>c                   s   g | ]
} j |r|qS rI   )r   r   )r   r   r   rI   rJ   r   [  r  )r  r   add_watched_paths)r   r   pathsrI   r   rJ   r0  W  s   zServer.update_sourcesr   c                 C  s   | j ||}| ||S r  )r   rR  _find_changed)r   r   r   r   rl  rI   rI   rJ   rR  ^  s   zServer.update_changedc                 C  s   | j  }| ||S r  )r   r=  r  )r   r   rl  rI   rI   rJ   r=  d  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 t||fdd|D  dd	 | j D }|D ](}	|	jsZJ |	j|v r{||	j |	jkr{|||	j |	jf ||	j|	jf qS||fS )
Nc                   s(   g | ]}|j r|j  v r|j|j fqS rI   r   r   rV  )rl  rI   rJ   r   l  s    

z(Server._find_changed.<locals>.<listcomp>c                 S  rU  rI   r   rV  rI   rI   rJ   r  s  rX  z'Server._find_changed.<locals>.<setcomp>c                   r[  rI   r   rV  )modulesrI   rJ   r   t  r]  c                 S  rU  rI   r   rV  rI   rI   rJ   r  ~  rX  c                   s8   g | ]}|j r|jvr|j|j f vr|j|j fqS rI   r  rV  )changed_setprevious_modulesrI   rJ   r     s    

c                 S  s   i | ]}|j |jqS rI   r  r   rI   rI   rJ   
<dictcomp>  s    z(Server._find_changed.<locals>.<dictcomp>)r
  r   r;   r   r  re  )
r   r   rl  rJ  omittedrK  rW  r   lastr   rI   )rl  r  r  r  rJ   r  h  s2   

zServer._find_changedr   showlocation	verbositylimitinclude_spaninclude_kindinclude_object_attrsunion_attrsforce_reloadc
              
   C  s   | j sddiS t| j |||||||	d}
| jj}d| j_z(|dkr'|
|}n|dkr1|
|}n|dkr;|
|}nJ d	W || j_n|| j_w d
|v r_t|d
 tsWJ |d
  d7  < |S )z!Locate and inspect expression(s).rv   zWCommand "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   )	r   r   r'   inspectionsget_type	get_attrsget_definitionr   r)   )r   r  r  r  r  r  r  r  r  r  engineold_inspectionsrE  rI   rI   rJ   cmd_inspect  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.rv   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  r  )r   r  r  r  r  r   r   rI   rI   rJ   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   rI   rI   rJ   cmd_hang  s   
zServer.cmd_hangr  )r'   r   r(   r)   r*   r+   r.   r   )r.   r   )r.   r   )rE   r)   r   r   r.   r   )r   r-   r.   r   )r.   r   )r   r)   r   r   r   rq   r   rq   r   r/   r.   r   )
r   r   r   rq   r   rq   r   r/   r.   r   NN)r   rq   r   r/   r   rq   r   r   r   r   r.   r   )
r   r  r   rq   r   rq   r   r/   r.   r  )r   r  r.   r   )r.   rq   )r   r  r   rq   r   r/   r.   r  )NNF)
r   r  r   r   r   r   r  rq   r.   ro   )F)r   r  r  rq   r.   ro   )
rv  r  r5  rw  r\  rx  rl  ry  r.   rz  )r   r  r5  rw  r.   r  )r5  rw  r\  rx  r?  r   r.   r  )
r  ro   r   r  r   rq   r   r/   r.   r  )FN)
r  ro   r  r/   r   rq   r   r+   r.   ro   )r   r  r.   r   )r   r  r   ro   r   ro   r.   r   )r   r  r.   r   )r   r  rl  ry  r.   r   )r   r   FFFFF)r  r)   r  r)   r  r/   r  r/   r  rq   r  rq   r  rq   r  rq   r  rq   r.   r   )r  r)   r  rq   r  r   r.   r   )__name__
__module____qualname__r   r   rk   r   r   r   r   r   r  r   r  r  r  r  r  r  rd  rg  r>  r  rD  r0  rR  r=  r  r  r  r  rI   rI   rI   rJ   rj      sX    
 

A

	
+
3



[7
y
)

2



1
.rj   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darwinr2   i   )psutilImportErrorProcessmemory_inforssr  vmsr6   r   	peak_wsetresource	getrusageRUSAGE_SELF	ru_maxrss)r   r  processmeminfor  rusagefactorrI   rI   rJ   r     s,   

r   rI   r5  rw  extraSequence[BuildSource]r  c                 C  sF   t |}dd |D }|  D ]\}}||vr |t|j| q|S )Nc                 S  rU  rI   r   rV  rI   rI   rJ   r    rX  z,find_all_sources_in_build.<locals>.<setcomp>)r   rh  r;   r   r   )r5  r  rE  r\  r   rI  rI   rI   rJ   r4    s   r4  r   rJ  r  r   c                   s$   t | | fdd| D  dS )zAdd all (explicit) sources to the list changed files in place.

    Use this when re-processing of unchanged files is needed (e.g. for
    the purpose of exporting types for inspections).
    c                   s.   g | ]}|j r|j|j f vr|j|j fqS rI   r  )r   bsr  rI   rJ   r     s    
z.add_all_sources_to_changed.<locals>.<listcomp>N)r  re  )r   rJ  rI   r  rJ   rS    s   
rS  c                 C  sj   |   D ].}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)r7  r|  
suppressedr;   r  dependencies_setr  )r5  rI  new_suppressednew_dependenciesr~  rI   rI   rJ   rj    s   
rj  r  rx  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.pyNr  z-stubsi)	r  python_path	mypy_pathpackage_pathtypeshed_pathlistdirr   r  r{  )r  r?  r   r  r  r  entriesentryrI   rI   rJ   r  3  s6   



r  r  )
r'   r   r(   r)   r*   r+   r,   r-   r.   r/   r  )rL   rM   r,   r-   r.   r/   )rn   ro   rp   rq   r.   r   )r   r)   r.   rq   )r.   r  )rI   )r5  rw  r  r  r.   r  )r   r  rJ  r  r.   r   )r5  rw  r.   r   )r  rx  r?  r   r   r   r.   rx  )W__doc__
__future__r   r   r<   r   r   rW   r8   rA   r6   r	  r   
contextlibr   r   typingr   r   r   r   r	   r
   r   typing_extensionsr   r   
mypy.buildrx   mypy.errors	mypy.mainmypy.dmypy_utilr   r   r   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&   rK   ri   rm   r   r   r)   r   r   r   rj   r  r   r4  rS  rj  r  rI   rI   rI   rJ   <module>   sv    $
.

      A


