U
    g                     @  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re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   warnZ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   =/tmp/pip-unpacked-wheel-ks04xdmi/trio/_tools/mypy_annotate.pyr   (   s   
r   r   zResult | None)linereturnc           	   	   C  s~   t |   }rv| \}}}}}}}t|t||d k	rBt|nd |d k	rTt|nd |d k	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k	rtd|j ddd |jdk	r|jdk	rtd	|j d
|j ddd d|j d|j d|j d|j d|j 
}qd|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 5 Q R X W n t	tj
fk
rz   i }Y nX |jdkrt| n|j}tjD ]R}t|}|dk	rz|| | W n tk
r   |g||< Y nX tj| qt|jd}t|| W 5 Q R X 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)r1   defaultrbwb)argparseArgumentParserr   add_argument
parse_argsopenZdumpfilepickleloadFileNotFoundErrorUnpicklingErrorplatformr.   sysstdinr    appendKeyErrorstdoutwritedump)r/   parserZcmd_linefr"   r?   r   parsedr   r   r   mainU   s<    




rJ   __main__   )r   
__future__r   r6   r;   rer@   attrscompileVERBOSEr   r   frozenr   r    r.   rJ   r   r/   r   r   r   r   <module>   s*   		
(