Ë
    øÿæiD   ã            
       óÚ   — d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ de
eee   f   d	ee   fd
„Z G d„ de«      Zde
eee   f   d	ee   fd„Zddededed	ee   fd„Zy)zöUtilities to parse and adjust Python requirements files.

This module parses requirement lines while preserving inline comments and pip arguments and
supports relaxing version pins based on a chosen unfreeze strategy: "none", "major", or "all".

é    N)ÚIterableÚIterator)ÚPath)ÚAnyÚOptionalÚUnion)ÚRequirement)ÚVersionÚstrsÚreturnc              #   ó¬   K  — t        | t        «      r| j                  «       } | D ]+  }|j                  «       }|sŒ|j	                  d«      rŒ(|–— Œ- y­w)z{Yield non-empty, non-comment lines from a string or iterable of strings.

    Adapted from pkg_resources.yield_lines.

    Ú#N)Ú
isinstanceÚstrÚ
splitlinesÚstripÚ
startswith)r   Úlines     ú}/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning_utilities/install/requirements.pyÚ_yield_linesr      sF   è ø€ ô �$œÔØ�‰Ó ˆÛˆØ�z‰z‹|ˆÚ˜Ÿ™¨Õ,Ø‹Jñ ùs   ‚8A»AÁAc                   óZ   ‡ — e Zd ZdZdZdddœdededee   d	ed
df
ˆ fd„Zded
efd„Z	ˆ xZ
S )Ú_RequirementWithCommenta  Requirement subclass that preserves an inline comment and optional pip argument.

    Attributes:
        comment: The trailing comment captured from the requirement line (including the leading '# ...').
        pip_argument: A preceding pip argument line (e.g., ``"--extra-index-url ..."``) associated
            with this requirement, or ``None`` if not provided.
        strict: Whether the special marker ``"# strict"`` appears in ``comment`` (case-insensitive), in which case
            upper bound adjustments are disabled.

    z# strictÚ N©ÚcommentÚpip_argumentÚargsr   r   Úkwargsr   c                ó¦   •— t        ‰| �  |i |¤Ž || _        |�|st        d|› �«      ‚|| _        | j
                  |j                  «       v | _        y )Nzwrong pip argument: )ÚsuperÚ__init__r   ÚRuntimeErrorr   Ústrict_stringÚlowerÚstrict)Úselfr   r   r   r   Ú	__class__s        €r   r!   z _RequirementWithComment.__init__0   sW   ø€ Ü‰Ñ˜$Ð) &Ò)ØˆŒØÐ$©ÜÐ!5°l°^ÐDÓEÐEØ(ˆÔØ×(Ñ(¨G¯M©M«OÐ;ˆ�ó    Úunfreezec                 ó   — t        | «      }| j                  r|› d| j                  › �S |dk(  r|| j                  D ]k  }|j                  dv sŒt        |j                  «      j                  }|j                  |j                  › |j                  › �dt        |«      dz   › d�«      c S  |S |dk(  r‹| j                  D ]z  }|j                  dv sŒ|j                  › |j                  › �}|j                  |› d�d	«      j                  d|› �d	«      }||v r|j                  |d	«      }|j                  «       c S  |S |d
k7  rt        d|›d�«      ‚|S )a`  Adjust version specifiers according to the selected unfreeze strategy.

        The special marker ``"# strict"`` in the captured comment disables any relaxation of upper bounds.

        >>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# anything").adjust("none")
        'arrow<=1.2.2,>=1.2.0'
        >>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# strict").adjust("none")
        'arrow<=1.2.2,>=1.2.0  # strict'
        >>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# my name").adjust("all")
        'arrow>=1.2.0'
        >>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("all")
        'arrow<=1.2.2,>=1.2.0  # strict'
        >>> _RequirementWithComment("arrow").adjust("all")
        'arrow'
        >>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# cool").adjust("major")
        'arrow<2.0,>=1.2.0'
        >>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("major")
        'arrow<=1.2.2,>=1.2.0  # strict'
        >>> _RequirementWithComment("arrow>=1.2.0").adjust("major")
        'arrow>=1.2.0'
        >>> _RequirementWithComment("arrow").adjust("major")
        'arrow'

        Args:
            unfreeze: One of:
                - ``"none"``: Keep all version specifiers unchanged.
                - ``"major"``: Relax the upper bound to the next major version (e.g., ``<2.0``).
                - ``"all"``: Drop any upper bound constraint entirely.

        Returns:
            The adjusted requirement string. If strict, the original string is returned with the strict marker appended.

        z  Úmajor)Ú<z<=r,   é   z.0ÚallÚ,r   ÚnonezUnexpected unfreeze: z value.)r   r%   r#   Ú	specifierÚoperatorr
   Úversionr+   ÚreplaceÚintr   Ú
ValueError)r&   r)   ÚoutÚspecr+   ÚupperÚresults          r   Úadjustz_RequirementWithComment.adjust8   sR  € ôD �$‹iˆØ�;Š;Ø�U˜"˜T×/Ñ/Ð0Ð1Ð1Ø�wÒØŸœ�Ø—=‘= KÒ/Ü# D§L¡LÓ1×7Ñ7�EàŸ;™;¨$¯-©-¨¸¿¹¸Ð'GÈ1ÌSÐQVËZÐZ[É^ÐL\Ð\^ÐI_Ó`Ò`ð	 'ð  ˆ
ð ˜ÒØŸœ�Ø—=‘= KÒ/à#Ÿ}™}˜o¨d¯l©l¨^Ð<�EØ Ÿ[™[¨E¨7°!¨°bÓ9×AÑAÀAÀeÀWÀ+ÈrÓR�FØ ‘Ø!'§¡°°rÓ!:˜Ø!Ÿ<™<›>Ò)ð 'ð ˆ
ð ˜ÒÜÐ4°X°LÀÐHÓIÐIØˆ
r(   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r   r   r   r!   r;   Ú__classcell__)r'   s   @r   r   r   "   sV   ø„ ñ	ð €Mà24ÐTXò <˜cð <¨Cð <ÀHÈSÁMð <Ðdgð <Ðlpõ <ð6˜sð 6 s÷ 6r(   r   c              #   ó¤  K  — t        | «      }d}|D ]ª  }d|v r|j                  d«      }|d| ||d }}nd}|j                  d«      r"|dd j                  «       }	 |t	        |«      z  }|j                  d«      r|}Œl|j                  d«      rŒ~d|v st        j                  d	|«      rŒ™t        |||¬
«      –— d}Œ¬ y# t
        $ r Y  yw xY w­w)a�  Adapted from ``pkg_resources.parse_requirements`` to include comments and pip arguments.

    Parses a sequence or string of requirement lines, preserving trailing comments and associating any
    preceding pip arguments (``--...``) with the subsequent requirement. Lines starting with ``-r`` or
    containing direct URLs are ignored.

    >>> txt = ['# ignored', '', 'this # is an', '--piparg', 'example', 'foo # strict', 'thing', '-r different/file.txt']
    >>> [r.adjust('none') for r in _parse_requirements(txt)]
    ['this', 'example', 'foo  # strict', 'thing']
    >>> txt = '\\n'.join(txt)
    >>> [r.adjust('none') for r in _parse_requirements(txt)]
    ['this', 'example', 'foo  # strict', 'thing']

    Args:
        strs: Either an iterable of requirement lines or a single multi-line string.

    Yields:
        _RequirementWithComment: Parsed requirement objects with preserved comment and pip argument.

    Nz #r   Ú\éÿÿÿÿz--z-r Ú@z	https?://r   )
r   ÚfindÚendswithr   ÚnextÚStopIterationr   ÚreÚsearchr   )r   Úlinesr   r   Úcomment_posr   s         r   Ú_parse_requirementsrM   q   så   è ø€ ô* ˜Ó€EØ€LÛˆà�4‰<ØŸ)™) D›/ˆKØ   +Ð.°°[°\Ð0B�'‰DàˆGà�=‰=˜ÔØ˜˜�9—?‘?Ó$ˆDðØœ˜U›Ñ#�ð �?‰?˜4Ô ØˆLØØ�?‰?˜5Ô!àØ�$‰;œ"Ÿ)™) K°Ô6àÜ% d°GÈ,ÔWÒWØ‰ñ3 øô !ò Úðüs+   ‚ACÁC Á*ACÃ 	CÃ	CÃCÃCÚpath_dirÚ	file_namer)   c                 ó   — |dvrt        d|› d�«      ‚t        | «      |z  }|j                  «       st        d| ||f› �«      ‚|j	                  «       }t        |«      D �cg c]  }|j                  |«      ‘Œ c}S c c}w )aM  Load, parse, and optionally relax requirement specifiers from a file.

    >>> import os
    >>> from lightning_utilities import _PROJECT_ROOT
    >>> path_req = os.path.join(_PROJECT_ROOT, "requirements")
    >>> load_requirements(path_req, "docs.txt", unfreeze="major")  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    ['sphinx<6.0,>=4.0', ...]

    Args:
        path_dir: Directory containing the requirements file.
        file_name: The requirements filename inside ``path_dir``.
        unfreeze: Unfreeze strategy: ``"none"``, ``"major"``, or ``"all"`` (see ``_RequirementWithComment.adjust``).

    Returns:
        A list of requirement strings adjusted according to ``unfreeze``.

    Raises:
        ValueError: If ``unfreeze`` is not one of the supported options.
        FileNotFoundError: If the composed path does not exist.

    >   r.   r0   r+   zunsupported option of "Ú"zmissing file for )r6   r   ÚexistsÚFileNotFoundErrorÚ	read_textrM   r;   )rN   rO   r)   ÚpathÚtextÚreqs         r   Úload_requirementsrX   ¤   sˆ   € ð, Ð/Ñ/ÜÐ2°8°*¸AÐ>Ó?Ð?Ü�‹>˜IÑ%€DØ�;‰;Œ=ÜÐ"3°X¸yÈ$Ð4OÐ3PÐ QÓRÐRØ�>‰>Ó€DÜ,?ÀÔ,EÓFÑ,E SˆC�J‰J�xÕ Ð,EÑFÐFùÒFs   Á A;)zbase.txtr.   )r?   rI   Úcollections.abcr   r   Úpathlibr   Útypingr   r   r   Úpackaging.requirementsr	   Úpackaging.versionr
   r   r   r   rM   ÚlistrX   © r(   r   Ú<module>r`      sª   ðñó 
ß .Ý ß 'Ñ 'å .Ý %ð�u˜S (¨3¡-Ð/Ñ0ð °X¸c±]ó ôL˜kô Lð^0˜e C¨°#©Ð$6Ñ7ð 0¸HÐE\Ñ<]ó 0ñfG ð G°ð GÈCð GÐ\`ÐadÑ\eô Gr(   