U
    b                     @   s   d dl mZmZmZmZ d dlmZ ddlmZ ddl	m
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 ddlmZ ddlmZ eeZG dd dZejZejZdd ZdS )    )absolute_importdivisionprint_functionunicode_literals)	getLogger   )do_call   )encode_arguments)generate_parser)SEARCH_PATH)context)CaptureTargetargvcaptured)conda_exception_handler)initialize_std_loggersc                   @   s8   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdS )CommandsZcleanZconfigZcreateinfoZinstalllistremovesearchupdaterunZnoticesN)__name__
__module____qualname__ZCLEANZCONFIGZCREATEINFOZINSTALLZLISTZREMOVEZSEARCHZUPDATEZRUNZNOTICES r   r   3lib/python3.8/site-packages/conda/cli/python_api.pyr      s   r   c              
   O   s  t   |dd}|dt}|dt}|dt}t }t|dkr^t|d tr^|d }t|}|d|  |	|}d|_
tj||d dd	lm}	 td
|	| |d dk}
|
rd}n||f}zxtdgt| 6 t| "}|rtt||}n
t||}W 5 Q R X W 5 Q R X |
r4|j}|j}|j}n|j}|j}W nD tk
r } z$td|| || |_|_|W 5 d}~X Y nX |pd}td||| |||fS )a  Runs a conda command in-process with a given set of command-line interface arguments.

    Differences from the command-line interface:
        Always uses --yes flag, thus does not ask for confirmation.

    Args:
        command: one of the Commands.
        *arguments: instructions you would normally pass to the conda command on the command line
                    see below for examples. Be very careful to delimit arguments exactly as you
                    want them to be delivered. No 'combine then split at spaces' or other
                    information destroying processing gets performed on the arguments.
        **kwargs: special instructions for programmatic overrides

    Keyword Args:
        use_exception_handler: defaults to False. False will let the code calling
          `run_command` handle all exceptions.  True won't raise when an exception
          has occurred, and instead give a non-zero return code
        search_path: an optional non-standard search path for configuration information
          that overrides the default SEARCH_PATH
        stdout: Define capture behavior for stream sys.stdout. Defaults to STRING.
          STRING captures as a string.  None leaves stream untouched.
          Otherwise redirect to file-like object stdout.
        stderr: Define capture behavior for stream sys.stderr. Defaults to STRING.
          STRING captures as a string.  None leaves stream untouched.
          STDOUT redirects to stdout target and returns None as stderr value.
          Otherwise redirect to file-like object stderr.

    Returns:
        a tuple of stdout, stderr, and return_code.
        stdout, stderr are either strings, None or the corresponding file-like function argument.

    Examples:
        >>> run_command(Commands.CREATE, "-n", "newenv", "python=3", "flask",                         use_exception_handler=True)
        >>> run_command(Commands.CREATE, "-n", "newenv", "python=3", "flask")
        >>> run_command(Commands.CREATE, ["-n", "newenv", "python=3", "flask"], search_path=())
    use_exception_handlerFsearch_pathstdoutstderrr   T)r!   Zargparse_args)list2cmdlinezexecuting command >>>  conda %sr   )NNZ
python_apiz
  stdout: %s
  stderr: %sNz,
  stdout: %s
  stderr: %s
  return_code: %s)r   popr   STRINGr   len
isinstancer   insert
parse_argsZyesr   __init__
subprocessr$   logdebugr   r
   r   r   r   r"   r#   Zrc	Exception)ZcommandZ	argumentskwargsr    Zconfiguration_search_pathr"   r#   pargsr$   Zis_runZcap_argscresulteZreturn_coder   r   r   run_command&   sP    &


r6   N)Z
__future__r   r   r   r   Zloggingr   Zconda_argparser   Zcommon.compatr
   mainr   Zbase.constantsr   Zbase.contextr   Z	common.ior   r   r   
exceptionsr   Zgateways.loggingr   r   r-   r   r&   ZSTDOUTr6   r   r   r   r   <module>   s   