o
    5‘ði„  ã                   @  sÞ   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	 ddl
mZ ddlmZ dd	lmZ d
dlmZ d
dlmZ edƒZeedf Zd(dd„Zd)dd„Zd*dd„Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdS )+aS  Helper code used to generate ``requires.txt`` files in the egg-info directory.

The ``requires.txt`` file has an specific format:
    - Environment markers need to be part of the section headers and
      should not be part of the requirement spec itself.

See https://setuptools.pypa.io/en/latest/deprecated/python_eggs.html#requires-txt
é    )ÚannotationsN)Údefaultdict)ÚMapping)Úfilterfalse)ÚTypeVar)Úyield_lines)ÚRequirementé   )Ú_reqs)Ú
_StrOrIterÚ_TÚinstall_requiresr   Úextras_requireúMapping[str, _StrOrIter]Úreturnú&tuple[list[str], dict[str, list[str]]]c                 C  s   t |ƒ}t| |ƒS )z�Given values for ``install_requires`` and ``extras_require``
    create modified versions in a way that can be written in ``requires.txt``
    )Ú_convert_extras_requirementsÚ"_move_install_requirements_markers)r   r   Úextras© r   ú^/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/command/_requirestxt.pyÚ_prepare   s   
r   ú'defaultdict[str, _Ordered[Requirement]]c                 C  sX   t ttt f tƒ}|  ¡ D ]\}}||  t |¡D ]}||t|ƒ   	|¡ qq|S )z‘
    Convert requirements in `extras_require` of the form
    `"extra": ["barbazquux; {marker}"]` to
    `"extra:{marker}": ["barbazquux"]`.
    )
r   ÚstrÚ_Orderedr   ÚdictÚitemsr
   ÚparseÚ_suffix_forÚ
setdefault)r   ÚoutputÚsectionÚvÚrr   r   r   r   '   s   ÿr   ú#Mapping[str, _Ordered[Requirement]]c                 C  sp   t t | ¡ƒ}tt|ƒ}tt|ƒ}t tt|ƒƒ}|D ]}|dt|jƒ   	|¡ qt
dd„ | ¡ D ƒƒ}||fS )a+  
    The ``requires.txt`` file has an specific format:
        - Environment markers need to be part of the section headers and
          should not be part of the requirement spec itself.

    Move requirements in ``install_requires`` that are using environment
    markers ``extras_require``.
    ú:c              	   s  s6   � | ]\}}|t t d d„ tt|ƒD ƒ¡ƒfV  qdS )c                 s  s   � | ]}t |ƒV  qd S ©N)r   )Ú.0r#   r   r   r   Ú	<genexpr>R   s   € z?_move_install_requirements_markers.<locals>.<genexpr>.<genexpr>N)Úlistr   ÚfromkeysÚmapÚ
_clean_req)r'   Úkr"   r   r   r   r(   P   s
   €  ÿ
þz5_move_install_requirements_markers.<locals>.<genexpr>)r)   r
   r   ÚfilterÚ
_no_markerr   r+   r   Úmarkerr   r   r   )r   r   Ú	inst_reqsÚsimple_reqsÚcomplex_reqsÚsimple_install_requiresr#   Úexpanded_extrasr   r   r   r   9   s   

ýr   c                 C  s   | j r
dt| j ƒ S dS )z;Return the 'extras_require' suffix for a given requirement.r%   Ú )r0   r   ©Úreqr   r   r   r   Y   s   r   c                 C  s   t t| ƒƒ}d|_|S )z=Given a Requirement, remove environment markers and return itN)r   r   r0   )r8   r#   r   r   r   r,   ^   s   r,   c                 C  s   | j  S r&   )r0   r7   r   r   r   r/   e   ó   r/   c                 C  s,   t |pdƒ}dd„ }t||ƒ}|  |¡ d S )Nr   c                 S  s   | d S )NÚ
r   )Úliner   r   r   Ú	append_crl   r9   z&_write_requirements.<locals>.append_cr)r   r+   Ú
writelines)ÚstreamÚreqsÚlinesr<   r   r   r   Ú_write_requirementsi   s   
rA   c                 C  s|   | j }t ¡ }t|jpd|jpi ƒ\}}t||ƒ t|ƒD ]}| dj	di t
ƒ ¤Ž¡ t||| ƒ q|  d|| ¡ ¡ d S )Nr   z
[{extra}]
Úrequirements)ÚdistributionÚioÚStringIOr   r   r   rA   ÚsortedÚwriteÚformatÚvarsÚwrite_or_delete_fileÚgetvalue)ÚcmdÚbasenameÚfilenameÚdistÚdatar   r   Úextrar   r   r   Úwrite_requirementss   s   ÿ
rR   c                 C  s,   t  ¡ }t|| jjƒ |  d|| ¡ ¡ d S )Nzsetup-requirements)rD   rE   rA   rC   Úsetup_requiresrJ   rK   )rL   rM   rN   rP   r   r   r   Úwrite_setup_requirements€   s   rT   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r$   r   r   )Ú__doc__Ú
__future__r   rD   Úcollectionsr   Úcollections.abcr   Ú	itertoolsr   Útypingr   Újaraco.textr   Úpackaging.requirementsr   r6   r
   r   r   r   r   r   r   r   r   r,   r/   rA   rR   rT   r   r   r   r   Ú<module>   s,    	



 
