o
    (c                  	   @   sB   d dl Z dddde jdededefdd	Zd
edefddZdS )    NT)include_stdoutinclude_stderrer   r   returnc                C   sh   d dd | jD }d| d| j }|r#| jdur#|d| j 7 }|r2| jdur2|d| j 7 }|S )	a  Helper to convert a CalledProcessError to an error message.

    If `include_stdout` or `include_stderr` are True (the default), the
    respective output stream will be added to the error message (if
    present in the exception).

    >>> format_called_process_error(subprocess.CalledProcessError(
    ...     777, ['ls', '-la'], None, None
    ... ))
    '`ls -la` failed with code 777'
    >>> format_called_process_error(subprocess.CalledProcessError(
    ...     1, ['cargo', 'foo bar'], 'message', None
    ... ))
    "`cargo 'foo bar'` failed with code 1\n-- Output captured from stdout:\nmessage"
    >>> format_called_process_error(subprocess.CalledProcessError(
    ...     1, ['cargo', 'foo bar'], 'message', None
    ... ), include_stdout=False)
    "`cargo 'foo bar'` failed with code 1"
    >>> format_called_process_error(subprocess.CalledProcessError(
    ...    -1, ['cargo'], 'stdout', 'stderr'
    ... ))
    '`cargo` failed with code -1\n-- Output captured from stdout:\nstdout\n-- Output captured from stderr:\nstderr'
     c                 s   s    | ]}t |V  qd S )N)_quote_whitespace).0arg r
   :usr/lib/python3.10/site-packages/setuptools_rust/_utils.py	<genexpr>!   s    z.format_called_process_error.<locals>.<genexpr>`z` failed with code Nz!
-- Output captured from stdout:
z!
-- Output captured from stderr:
)joincmd
returncodestdoutstderr)r   r   r   commandmessager
   r
   r   format_called_process_error   s   r   stringc                 C   s   d| v r
d|  dS | S )Nr   'r
   )r   r
   r
   r   r   0   s   r   )
subprocessCalledProcessErrorboolstrr   r   r
   r
   r
   r   <module>   s    
,