§
    ’©ºjD   ã            
       ó  — 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dS )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|                      ¦   «         } | D ]1}|                     ¦   «         }|r|                     d¦  «        s|V — Œ2dS )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     úx/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/lightning_utilities/install/requirements.pyÚ_yield_linesr      st   è è € õ �$�ÑÔð !Ø�ŠÑ Ô ˆØð ð ˆØ�zŠz‰|Œ|ˆØð 	˜Ÿš¨Ñ,Ô,ð 	ØˆJˆJˆJøðð ó    c                   ó`   ‡ — 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          ¦   «         j        |i |¤Ž || _        |�|st          d|› �¦  «        ‚|| _        | j        |                     ¦   «         v | _        d S )Nzwrong pip argument: )ÚsuperÚ__init__r   ÚRuntimeErrorr   Ústrict_stringÚlowerÚstrict)Úselfr   r   r   r   Ú	__class__s        €r   r"   z _RequirementWithComment.__init__0   sk   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)ØˆŒØÐ$¨Ð$ÝÐD°lÐDÐDÑEÔEÐEØ(ˆÔØÔ(¨G¯MªM©O¬OÐ;ˆŒˆˆr   Úunfreezec                 ój  — t          | ¦  «        }| j        r|› d| j        › �S |dk    rg| j        D ]^}|j        dv rSt          |j        ¦  «        j        }|                     |j        › |j        › �dt          |¦  «        dz   › d�¦  «        c S Œ_n£|dk    r„| j        D ]{}|j        dv rp|j        › |j        › �}|                     |› d�d	¦  «                             d|› �d	¦  «        }||v r|                     |d	¦  «        }| 
                    ¦   «         c S Œ|n|d
k    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   sŽ  € õD �$‰iŒiˆØŒ;ð 	2ØÐ1Ð1˜TÔ/Ð1Ð1Ð1Ø�wÒÐØœð að a�Ø”= KÐ/Ð/Ý# D¤LÑ1Ô1Ô7�EàŸ;š;¨$¬-Ð'G¸¼Ð'GÐ'GÐI_ÍSÐQVÉZÌZÐZ[É^ÐI_ÐI_ÐI_Ñ`Ô`Ð`Ð`Ð`ð 0ðað
 ˜ÒÐØœð *ð *�Ø”= KÐ/Ð/à#œ}Ð<¨d¬lÐ<Ð<�EØ Ÿ[š[¨E¨¨¨°bÑ9Ô9×AÒAÀ+ÀeÀ+À+ÈrÑRÔR�FØ ��Ø!'§¢°°rÑ!:Ô!:˜Ø!Ÿ<š<™>œ>Ð)Ð)Ð)ð 0ð*ð ˜ÒÐÝÐH°XÐHÐHÐHÑIÔIÐIØˆ
r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r   r   r   r"   r;   Ú__classcell__)r(   s   @r   r   r   "   s©   ø€ € € € € ð	ð 	ð €Mà24ÐTXð <ð <ð <˜cð <¨Cð <ÀHÈSÄMð <Ðdgð <Ðlpð <ð <ð <ð <ð <ð <ð6˜sð 6 sð 6ð 6ð 6ð 6ð 6ð 6ð 6ð 6r   r   c              #   ó   K  — t          | ¦  «        }d}|D ]ç}d|v r*|                     d¦  «        }|d|…         ||d…         }}nd}|                     d¦  «        rB|dd…                              ¦   «         }	 |t	          |¦  «        z  }n# t
          $ r Y  dS w xY w|                     d¦  «        r|}Œ¡|                     d¦  «        rŒ·d|v st          j        d	|¦  «        rŒÑt          |||¬
¦  «        V — d}ŒèdS )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   sF  è è € õ* ˜ÑÔ€EØ€LØð ð ˆà�4ˆ<ˆ<ØŸ)š) D™/œ/ˆKØ   + Ô.°°[°\°\Ô0B�'ˆDˆDàˆGà�=Š=˜ÑÔð 	Ø˜˜˜”9—?’?Ñ$Ô$ˆDðØ�˜U™œÑ#��øÝ ð ð ð Ø���ðøøøð �?Š?˜4Ñ Ô ð 	ØˆLØØ�?Š?˜5Ñ!Ô!ð 	àØ�$ˆ;ˆ;�"œ) K°Ñ6Ô6ˆ;àÝ% d°GÈ,ÐWÑWÔWÐWÐWÐWØˆˆð3ð s   Á:BÂ
BÂBúbase.txtr.   Úpath_dirÚ	file_namer)   c                 ó  ‡— ‰dvrt          d‰› d�¦  «        ‚t          | ¦  «        |z  }|                     ¦   «         st          d| ||f› �¦  «        ‚|                     ¦   «         }ˆfd„t          |¦  «        D ¦   «         S )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 c                 ó:   •— g | ]}|                      ‰¦  «        ‘ŒS © )r;   )Ú.0Úreqr)   s     €r   ú
<listcomp>z%load_requirements.<locals>.<listcomp>À   s%   ø€ ÐFÐFÐF SˆC�JŠJ�xÑ Ô ÐFÐFÐFr   )r6   r   ÚexistsÚFileNotFoundErrorÚ	read_textrM   )rO   rP   r)   ÚpathÚtexts     `  r   Úload_requirementsr]   ¤   sœ   ø€ ð, Ð/Ð/Ð/ÝÐ>°8Ð>Ð>Ð>Ñ?Ô?Ð?Ý�‰>Œ>˜IÑ%€DØ�;Š;‰=Œ=ð SÝÐ Q°X¸yÈ$Ð4OÐ QÐ QÑRÔRÐRØ�>Š>ÑÔ€DØFÐFÐFÐFÕ,?ÀÑ,EÔ,EÐFÑFÔFÐFr   )rN   r.   )r?   rI   Úcollections.abcr   r   Úpathlibr   Útypingr   r   r   Úpackaging.requirementsr	   Úpackaging.versionr
   r   r   r   rM   Úlistr]   rT   r   r   ú<module>rd      su  ððð ð 
€	€	€	Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à .Ð .Ð .Ð .Ð .Ð .Ø %Ð %Ð %Ð %Ð %Ð %ð�u˜S (¨3¤-Ð/Ô0ð °X¸c´]ð ð ð ð ðLð Lð Lð Lð L˜kñ Lô Lð Lð^0˜e C¨°#¬Ð$6Ô7ð 0¸HÐE\Ô<]ð 0ð 0ð 0ð 0ðfGð G ð G°ð GÈCð GÐ\`ÐadÔ\eð Gð Gð Gð Gð Gð Gr   