ó
    pyüi¾  ã                   óF  • S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJr  \" \5      r\S
\\	SS4   4S j5       r  SS\\\   -  S\\-  S-  S
\R*                  4S jjr\ SS\\\   -  S\\-  S-  S
\\\\   \\   4   SS4   4S jj5       rg)zFContains utilities to easily handle subprocesses in `huggingface_hub`.é    N)Ú	Generator)Úcontextmanager)ÚStringIO)ÚPath)ÚIOé   )Ú
get_loggerÚreturnc               #   ó–   #   • [        5       n [        R                  nU [        l         U v •  U[        l        g! U[        l        f = f7f)a  Capture output that is printed to terminal.

    Taken from https://stackoverflow.com/a/34738440

    Example:
    ```py
    >>> with capture_output() as output:
    ...     print("hello world")
    >>> assert output.getvalue() == "hello world
"
    ```
    N)r   ÚsysÚstdout)ÚoutputÚprevious_outputs     Ú^/home/mande/repo/quber/.venv/lib/python3.13/site-packages/huggingface_hub/utils/_subprocess.pyÚcapture_outputr      s6   é € ô ‹Z€FÜ—j‘j€OØ„C„Jð%ØŠà$Œ�
ø�_Œ�
üs   ‚&A	©9 ­A	¹AÁA	ÚcommandÚfolderc           	      óþ   • [        U [        5      (       a  U R                  5       n [        U[        5      (       a  [        U5      n[        R
                  " U 4SUSSU=(       d    [        R                  " 5       S.UD6$ )a  
Method to run subprocesses. Calling this will capture the `stderr` and `stdout`,
please call `subprocess.run` manually in case you would like for them not to
be captured.

Args:
    command (`str` or `list[str]`):
        The command to execute as a string or list of strings.
    folder (`str`, *optional*):
        The folder in which to run the command. Defaults to current working
        directory (from `os.getcwd()`).
    check (`bool`, *optional*, defaults to `True`):
        Setting `check` to `True` will raise a `subprocess.CalledProcessError`
        when the subprocess has a non-zero exit code.
    kwargs (`dict[str]`):
        Keyword arguments to be passed to the `subprocess.run` underlying command.

Returns:
    `subprocess.CompletedProcess`: The completed process.
Túutf-8Úreplace)r   ÚcheckÚencodingÚerrorsÚcwd)Ú
isinstanceÚstrÚsplitr   Ú
subprocessÚrunÚosÚgetcwd)r   r   r   Úkwargss       r   Úrun_subprocessr#   5   so   € ô4 �'œ3×ÑØ—-‘-“/ˆä�&œ$×ÑÜ�V“ˆä�>Š>ØðàØØØØ×!”b—i’i“kñð ñð ó    c           
   +   óÖ  #   • [        U [        5      (       a  U R                  5       n [        R                  " U 4[        R
                  [        R
                  [        R                  SSU=(       d    [        R                  " 5       S.UD6 nUR                  c   S5       eUR                  c   S5       eUR                  UR                  4v •  SSS5        g! , (       d  f       g= f7f)a›  Run a subprocess in an interactive mode in a context manager.

    Args:
        command (`str` or `list[str]`):
            The command to execute as a string or list of strings.
        folder (`str`, *optional*):
            The folder in which to run the command. Defaults to current working
            directory (from `os.getcwd()`).
        kwargs (`dict[str]`):
            Keyword arguments to be passed to the `subprocess.run` underlying command.

    Returns:
        `tuple[IO[str], IO[str]]`: A tuple with `stdin` and `stdout` to interact
        with the process (input and output are utf-8 encoded).

    Example:
    ```python
    with _interactive_subprocess("git credential-store get") as (stdin, stdout):
        # Write to stdin
        stdin.write("url=hf.co
username=obama
".encode("utf-8"))
        stdin.flush()

        # Read from stdout
        output = stdout.read().decode("utf-8")
    ```
    r   r   )Ústdinr   Ústderrr   r   r   Nz'subprocess is opened as subprocess.PIPE)r   r   r   r   ÚPopenÚPIPEÚSTDOUTr    r!   r&   r   )r   r   r"   Úprocesss       r   Úrun_interactive_subprocessr,   `   s¾   é € ô@ �'œ3×ÑØ—-‘-“/ˆä	×	Ò	Øð	
ä�o‰oÜ�‰Ü× Ñ ØØØ×!”b—i’i“kñ	
ð ò	
ð 
Ø�}‰}Ñ(ÐSÐ*SÓSÐ(Ø�~‰~Ñ)ÐTÐ+TÓTÐ)Ø�m‰m˜WŸ^™^Ð+Ò+÷	
÷ 	
ö 	
üs   ‚B
C)ÂACÃ	C)Ã
C&Ã"C))NT)N)Ú__doc__r    r   r   Úcollections.abcr   Ú
contextlibr   Úior   Úpathlibr   Útypingr   Úloggingr	   Ú__name__Úloggerr   r   ÚlistÚCompletedProcessr#   Útupler,   © r$   r   Ú<module>r:      sú   ðñ Mã 	Û Û 
Ý %Ý %Ý Ý Ý å ñ 
�HÓ	€ð ð%˜	 (¨D°$Ð"6Ñ7ó %ó ð%ð. !%Ø
ñ(Ø�4˜‘9‰_ð(à�$‰J˜Ñð(ð
 × Ñ õ(ðV ð !%ñ.,Ø�4˜‘9‰_ð.,à�$‰J˜Ñð.,ð ˆu�R˜‘W˜b ™gÐ%Ñ&¨¨dÐ2Ñ3ô	.,ó ñ.,r$   