a
    (ñ»jž  ã                   @  sº   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e dej	¡Z
ddddœZejd	d
�G dd„ dƒƒZdddœdd„Zdddœdd„Zdddœdd„Zedkr¶eejdd… ƒ dS )aˆ  Translates Mypy's output into GitHub's error/warning annotation syntax.

See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

This first is run with Mypy's output piped in, to collect messages in
mypy_annotate.dat. After all platforms run, we run this again, which prints the
messages in GitHub's format but with cross-platform failures deduplicated.
é    )ÚannotationsNa)  
    ([^:]+):  # Filename (anything but ":")
    ([0-9]+):  # Line number (start)
    (?:([0-9]+):  # Optional column number
      (?:([0-9]+):([0-9]+):)?  # then also optionally, 2 more numbers for end columns
    )?
    \s*(error|warn|note):  # Kind, prefixed with space
    (.+)  # Message
    ÚerrorÚwarningÚnotice)r   ÚwarnÚnoteT)Zkw_onlyc                   @  sV   e Zd ZU dZded< ded< ded< ded< dZd	ed
< dZd	ed< dZd	ed< dS )ÚResultz7Accumulated results, used as a dict key to deduplicate.ÚstrÚfilenameÚintÚ
start_lineÚkindÚmessageNz
int | NoneÚ	start_colÚend_lineÚend_col)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   © r   r   ú?E:\soccer\ml_env\Lib\site-packages\trio/_tools/mypy_annotate.pyr   (   s   
r   r	   zResult | None)ÚlineÚreturnc           	   	   C  s~   t  |  ¡ ¡ }rv| ¡ \}}}}}}}t|t|ƒ|d urBt|ƒnd |d urTt|ƒnd |d urft|ƒnd t| |d�S d S d S )N)r
   r   r   r   r   r   r   )Ú	report_reÚ	fullmatchÚrstripÚgroupsr   r   Úmypy_to_github)	r   Úmatchr
   Zst_lineZst_colr   r   r   r   r   r   r   Úprocess_line5   s    ù
r!   zdict[Result, list[str]]ÚNone)Úresultsr   c                 C  s  |   ¡ D �] \}}td|j› d|j› d|j› d�dd� |jdurÖtd|j› d�dd� |jdur¸|jdur¸td	|j› d
|j› d�dd� d|j› d|j› d|j› d|j› d|j› �
}qèd|j› d|j› d|j› �}n|j› d|j› �}tdd 	|¡› d|j› d|› �ƒ qdS )zDisplay the collected results.z::z file=z,line=ú,Ú )ÚendNzcol=zendLine=z,endColumn=ú(ú:z - z):ztitle=Mypy-ú+)
ÚitemsÚprintr   r
   r   r   r   r   r   Újoin)r#   ÚresÚ	platformsr   r   r   r   ÚexportE   s    &
.r/   z	list[str])Úargvr   c              	   C  s>  t jtd�}|jdddd� |jdddd	� | | ¡}z:t|jd
ƒ�}t |¡}W d  ƒ n1 sd0    Y  W n t	tj
fyŒ   i }Y n0 |jdu r¢t|ƒ n˜|j}tjD ]P}t|ƒ}|duròz||  |¡ W n tyð   |g||< Y n0 tj |¡ q®t|jdƒ�}t ||¡ W d  ƒ n1 �s00    Y  dS )z0Look for error messages, and convert the format.)Údescriptionz
--dumpfilez"File to write pickled messages to.T)ÚhelpÚrequiredz
--platformz.OS name, if set Mypy should be piped to stdin.N)r2   ÚdefaultÚrbÚwb)ÚargparseÚArgumentParserr   Úadd_argumentÚ
parse_argsÚopenZdumpfileÚpickleÚloadÚFileNotFoundErrorÚUnpicklingErrorÚplatformr/   ÚsysÚstdinr!   ÚappendÚKeyErrorÚstdoutÚwriteÚdump)r0   ÚparserZcmd_lineÚfr#   r@   r   Úparsedr   r   r   ÚmainU   s<    ýý
,



rK   Ú__main__é   )r   Ú
__future__r   r7   r<   ÚrerA   ÚattrsÚcompileÚVERBOSEr   r   Úfrozenr   r!   r/   rK   r   r0   r   r   r   r   Ú<module>   s*   		öý
(