o
    Ohg                     @  s  U d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z
 er3ddlmZ ddlmZmZ d	ed
< zddlmZ W n eyJ   ddlmZ Y nw d"ddZd#ddZedkre  Zed  sgJ ed Zed ZejddZd d! eeD ZeeeZe e!e dS dS )$zhSync Requirements - Automatically upgrade test requirements pinned
versions from pre-commit config file.    )annotationsN)Path)TYPE_CHECKING)load)	Generator)CLoaderLoaderztype[_CLoader | _Loader]r   )r   )r   pre_commit_textstrreturn&Generator[tuple[str, str], None, None]c                 c  s`    t | t}|d D ]#}d|vsd|vrq
|d }|ddd }|d d}||fV  q
dS )	z5Yield (name, rev) tuples from pre-commit config file.reposreporev/   vN)	load_yamlr   rsplitremoveprefix)r	   pre_commit_configr   urlnamer    r   Z/home/air/yokohama/back/venv/lib/python3.10/site-packages/trio/_tools/sync_requirements.pyyield_pre_commit_version_data   s   
r   requirementsr   version_datadict[str, str]boolc              
   C  s&  d}| j ddd}| jdddw}|D ]k}|ds d|vr&|| q|dd\}}| }d	}	d
|v rH|d
d\}}	| }d|	 }	||}
|
du rW|| q| d|
 |	 }||kr{|sld}td t| d| d| d|
  || qW d   |S 1 sw   Y  |S )zeReturn if updated requirements file.

    Update requirements file to match versions in version_data.Futf-8encodingTw#z==r   
;z ;Nz5Changed test requirements version to match pre-commitz -> )		read_text
splitlinesopen
startswithwritesplitstripgetprint)r   r   changed	old_linesfileliner   restold_versionextraversionnew_liner   r   r   update_requirements)   s<   



r:   __main__LICENSEz.pre-commit-config.yamlztest-requirements.txtr!   r"   c                 C  s"   i | ]\}}| d  d|qS )z-mirrorz-pre-commit)removesuffix).0r   r8   r   r   r   
<dictcomp>]   s    r?   )r	   r
   r   r   )r   r   r   r   r   r    )"__doc__
__future__r   syspathlibr   typingr   yamlr   r   collections.abcr   r   _CLoaderr   _Loader__annotations__ImportErrorr   r:   __name__cwdabsolutesource_rootexists
pre_committest_requirementsr(   r	   pre_commit_versionsr1   exitintr   r   r   r   <module>   s:   

(
