§
    ¬˜ºh  ã                   ó¬  — d Z ddlZddl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mZmZmZmZmZ ddlmZ  ee¦  «        Zed	eeddf         fd
„¦   «         Z	 	 ddeeee         f         deeee	f                  d	ej        fd„Ze	 ddeeee         f         deeee	f                  d	eeee         ee         f         ddf         fd„¦   «         ZdS )zFContains utilities to easily handle subprocesses in `huggingface_hub`.é    N)Úcontextmanager)ÚStringIO)ÚPath)ÚIOÚ	GeneratorÚListÚOptionalÚTupleÚUnioné   )Ú
get_loggerÚreturnc               #   óš   K  — t          ¦   «         } t          j        }| t          _        	 | V — |t          _        dS # |t          _        w xY w)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     úi/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/huggingface_hub/utils/_subprocess.pyÚcapture_outputr      sK   è è € õ ‰ZŒZ€FÝ”j€OØ…C„Jð%Øˆˆˆà$�Œ
ˆ
ˆ
ø�_�Œ
Ð$Ð$Ð$Ð$s	   ª< ¼A
TÚcommandÚfolderc           
      ó  — t          | t          ¦  «        r|                      ¦   «         } t          |t          ¦  «        rt          |¦  «        }t	          j        | ft          j        t          j        |dd|pt          j        ¦   «         dœ|¤ŽS )aX  
    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.
    úutf-8Úreplace)Ústderrr   ÚcheckÚencodingÚerrorsÚcwd)	Ú
isinstanceÚstrÚsplitr   Ú
subprocessÚrunÚPIPEÚosÚgetcwd)r   r   r   Úkwargss       r   Úrun_subprocessr)   5   sŒ   € õ4 �'�3ÑÔð "Ø—-’-‘/”/ˆå�&�$ÑÔð Ý�V‘”ˆåŒ>Øð	åŒÝŒØØØØÐ!•b”i‘k”kð	ð 	ð ð	ð 	ð 	ó    c           
   +   ó†  K  — t          | t          ¦  «        r|                      ¦   «         } t          j        | ft          j        t          j        t          j        dd|pt          j        ¦   «         dœ|¤Ž5 }|j	        €
J d¦   «         ‚|j
        €
J d¦   «         ‚|j	        |j
        fV — ddd¦  «         dS # 1 swxY w Y   dS )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   r   r   r   r   Nz'subprocess is opened as subprocess.PIPE)r    r!   r"   r#   ÚPopenr%   ÚSTDOUTr&   r'   r,   r   )r   r   r(   Úprocesss       r   Úrun_interactive_subprocessr0   a   s  è è € õ@ �'�3ÑÔð "Ø—-’-‘/”/ˆå	Ô	Øð	
åŒoÝŒÝÔ ØØØÐ!•b”i‘k”kð	
ð 	
ð ð	
ð 	
ð ,ð 
ØŒ}Ð(Ð(Ð*SÑ(Ô(Ð(ØŒ~Ð)Ð)Ð+TÑ)Ô)Ð)ØŒm˜Wœ^Ð+Ð+Ð+Ð+ð,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,ð ,ð ,s   Á63B6Â6B:Â=B:)NT)N)Ú__doc__r&   r#   r   Ú
contextlibr   Úior   Úpathlibr   Útypingr   r   r   r	   r
   r   Úloggingr   Ú__name__Úloggerr   r!   ÚCompletedProcessr)   r0   © r*   r   ú<module>r;      sÉ  ðð MÐ Là 	€	€	€	Ø Ð Ð Ð Ø 
€
€
€
Ø %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >à Ð Ð Ð Ð Ð ð 
ˆ�HÑ	Ô	€ð ð%˜	 (¨D°$Ð"6Ô7ð %ð %ð %ñ „ð%ð. *.Ø
ð)ð )Ø�3˜˜Sœ	�>Ô"ð)à�U˜3 ˜9Ô%Ô&ð)ð
 Ô ð)ð )ð )ð )ðX ð *.ð.,ð .,Ø�3˜˜Sœ	�>Ô"ð.,à�U˜3 ˜9Ô%Ô&ð.,ð ˆu�R˜”W˜b œgÐ%Ô&¨¨dÐ2Ô3ð	.,ð .,ð .,ñ „ð.,ð .,ð .,r*   