o
    Ye                     @  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ZdddZd ddZedkrTeejdd  dS 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warningZnotice)r   warnZnoteT)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   =usr/lib/python3.10/site-packages/trio/_tools/mypy_annotate.pyr   '   s   
 r   liner   returnResult | Nonec           	   	   C  sz   t |   }r;| \}}}}}}}t|t||d ur!t|nd |d ur*t|nd |d ur3t|nd t| |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_line4   s   
r!   resultsdict[Result, list[str]]Nonec                 C  s  |   D ]\}}td|j d|j d|j ddd |jdurjt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 
}n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   exportD   s   &
.$r0   argv	list[str]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 s2w   Y  W n t	tj
fyF   i }Y nw |jdu rRt| dS |j}tjD ](}t|}|durzz	|| | W n tyy   |g||< Y nw tj| qXt|jd}t|| W d   dS 1 sw   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)r4   defaultrbwb)argparseArgumentParserr   add_argument
parse_argsopenZdumpfilepickleloadFileNotFoundErrorZUnpicklingErrorplatformr0   sysstdinr!   appendKeyErrorstdoutwritedump)r1   parserZcmd_linefr"   rA   r   parsedr   r   r   mainT   sB   


"rL   __main__   )r   r   r   r   )r"   r#   r   r$   )r1   r2   r   r$   )r   
__future__r   r9   r>   rerB   attrscompileVERBOSEr   r   frozenr   r!   r0   rL   r   r1   r   r   r   r   <module>   s.    	



&