
    ]h                         S r SSKrSSKrSSKrSSKJrJrJrJr  SSK	J
r
  SSKJr   S\R                  SS.S\\   S	\\   S
\\   S\\\/S4      SS4
S jjjrS\S\4S jrg)z%
Run commands and handle returncodes
    N)CallableListOptionalTextIO   )pushd)
get_logger)fd_outpbarcmdcwdr
   r   returnc                T   [        5       R                  SSR                  U 5      U5         [        Ub  UOS5         [        R
                  " U S[        R                  [        R                  [        R                  [        R                  SS9nUR                  5       cg  UR                  bG  UR                  R                  5       nUb  UR                  U5        Ub  U" UR                  5       5        UR                  5       c  Mg  UR!                  5       u  pgU(       a<  [#        U5      S:  a-  Ub  UR                  U5        Ub  U" UR                  5       5        UR$                  S:w  aT  S	n [        R&                  " UR$                  5      nS
R-                  U [/        UR$                  5      U5      n	[1        U	5      e SSS5        g! [(        [*        4 a     NMf = f! , (       d  f       g= f! [2         a,  n
SR-                  U [5        U
5      5      n	[1        U	5      U
eSn
A
ff = f)a|  
Run command as subprocess, polls process output pipes and
either streams outputs to supplied output stream or sends
each line (stripped) to the supplied progress bar callback hook.

Raises ``RuntimeError`` on non-zero return code or execption ``OSError``.

:param cmd: command and args.
:param cwd: directory in which to run command, if unspecified,
    run command in the current working directory.
:param fd_out: when supplied, streams to this output stream,
    else writes to sys.stdout.
:param pbar: optional callback hook to tqdm, which takes
   single ``str`` arguent, see:
   https://github.com/tqdm/tqdm#hooks-and-callbacks.

zcmd: %s
cwd: %s N.r   T)bufsizestdinstdoutstderrenvuniversal_newlinesr    zCommand {}
	{} {}z!Command: {}
failed with error {}
)r	   debugjoinr   
subprocessPopenDEVNULLPIPESTDOUTosenvironpollr   readlinewritestripcommunicatelen
returncodestrerrorArithmeticError
ValueErrorformatreturncode_msgRuntimeErrorOSErrorstr)r   r   r
   r   procliner   _serrormsges              jC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\cmdstanpy/utils/command.py
do_commandr8      s   0 L)388C=#>)'#/3s3## ((!!((JJ#'D ))+%;;*;;//1D)T*'TZZ\* ))+% ((*IFv;?)V,'V\\^,!#[[9F ,228& #3'' $7 43> (4 ? 43J  '3::3AG3Q&'s`   G1 C	G A'G / G
1G G1 
GG GG  
G.*G1 .G1 1
H';'H""H'retcodec                 `    U S:  a
  SU -  nSU 3$ U S::  a  gU S:X  a  gU S:X  a  g	U S
-
  nSU 3$ )zinterpret retcoder   zterminated by signal }   zerror during processing~   r      zprogram not found    )r9   sigs     r7   r-   r-   R   sS    {7l&se,,#~(#~#~"
C-C"3%((    )N)__doc__r    r   systypingr   r   r   r   
filesystemr   loggingr	   r   r0   r8   intr-   r@   rB   r7   <module>rI      s    
  
 3 3  
 B'  #zz,0B'	cB'	#B' V	B'
 8SE4K(
)B' 
B'J)C )C )rB   