bg+(dZddgZddlZddlZddlZddlZddlZddlmZm Z ddl m Z dZ dZ d Zd Zdifd Zd Zd Z ddZddZdZdS)a0 exec_command Implements exec_command function that is (almost) equivalent to commands.getstatusoutput function but on NT, DOS systems the returned status is actually correct (though, the returned status values may be different by a factor). In addition, exec_command takes keyword arguments for (re-)defining environment variables. Provides functions: exec_command --- execute command in a specified directory and in the modified environment. find_executable --- locate a command using info from environment variable PATH. Equivalent to posix `which` command. Author: Pearu Peterson Created: 11 January 2003 Requires: Python 2.x Successfully tested on: ======== ============ ================================================= os.name sys.platform comments ======== ============ ================================================= posix linux2 Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3 PyCrust 0.9.3, Idle 1.0.2 posix linux2 Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2 posix sunos5 SunOS 5.9, Python 2.2, 2.3.2 posix darwin Darwin 7.2.0, Python 2.3 nt win32 Windows Me Python 2.3(EE), Idle 1.0, PyCrust 0.7.2 Python 2.1.1 Idle 0.8 nt win32 Windows 98, Python 2.1.1. Idle 0.8 nt win32 Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests fail i.e. redefining environment variables may not work. FIXED: don't use cygwin echo! Comment: also `cmd /c echo` will not work but redefining environment variables do work. posix cygwin Cygwin 98-4.10, Python 2.3.3(cygming special) nt win32 Windows XP, Python 2.3.3 ======== ============ ================================================= Known bugs: * Tests, that send messages to stderr, fail when executed from MSYS prompt because the messages are lost at some point. exec_commandfind_executableN) is_sequencemake_temp_file)logctjd}|d}||d}|dd}|dddkr |dd}|S) z Convert `bytes` in the encoding used by a subprocess into a filesystem-appropriate `str`. Inherited from `exec_command`, and possibly incorrect. FNasciireplaceerrors  )localegetpreferredencodingdecoder )outputmylocales o/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib64/python3.11/site-packages/numpy/distutils/exec_command.pyfilepath_from_subprocess_outputr?sl *511H ]]8I] 6 6F ^^FD ) )F bcc{d Mcttjdr&tjj|dSttjdrCtj|tjjdStj|dddS)z Forward bytes from a subprocess call to the console, without attempting to decode them. The assumption is that the subprocess call already returned bytes in a suitable encoding. bufferencodingutf8r r N)hasattrsysstdoutrwriterr)vals rforward_bytes_to_stdoutr!Pssz8$$? $$$$$ Z ( (? CJ$78899999 F9==>>>>>rctjdtdt\}}||S)NzLtemp_file_name is deprecated since NumPy v1.17, use tempfile.mkstemp instead stacklevel)warningswarnDeprecationWarningrclose)fonames rtemp_file_namer,csJ M-.@QPPPPHBHHJJJ Krcftj}tjdvrtj|\}}|dd}tj||}tj |s J|d|S)N)ntdosPYTHONWPYTHONz is not a file) r executableosr+pathsplitupperr joinisfile) pythonexefdirfns r get_pythonexer<ksI w-7==++b XXZZ   8 4 4GLLr** w~~i((KK *KKK( rc(||f} ||S#t$rYnwxYwtjd|z|}|*tjdtj}tjdkrtjj }nd}| dr |dd}d g}tjd vr>tj |\}}gd } | | vr| }tj |rd g} n)d |tjD} | D]}tj||}|D]} || z} tj| s || } tj| rAtj| tjr"tjd | z| ||<| ccStjd|zdS)zTReturn full path of a executable or None. Symbolic links are not followed. zfind_executable(%r)NPATHposixc|SN)as rz!find_executable..sAr"r#r)r.r/os2)z.exez.comz.batcLg|]!}tj|"SrB)r3r4abspath).0ps r z#find_executable..s&FFF"'//!$$FFFrzFound executable %szCould not locate executable %s)KeyErrorrdebugr3environgetdefpathr+r4realpath startswithsplitextlowerisabsr5pathsepr7islinkr8accessX_OKinfor') exer4_cachekeyorig_exerRsuffixesr;extextra_suffixespathssf_exts rrrts t)C c{      I#c)***H |z~~fbj11 w7#: ~~c!B$itH w&&&'""3''C111 99;;n , ,%H w}}SGFFdjj.D.DFFF   W\\$ $ $  AqDE7>>%(( ( w~~e$$ 5"')B)B .6777#s   H - 8999 4s  cLtjd|zd|D}|S)Nz_preserve_environment(%r)cNi|]"}|tj|#SrB)r3rOrP)rJr+s r z)_preserve_environment..s( 8 8 8$4%% 8 8 8r)rrN)namesenvs r_preserve_environmentrks0I)U3444 8 8% 8 8 8C Jrc tjd|D]\}}|pdtj|<dS)Nz_update_environment(...)rF)rrNitemsr3rO)rjr+values r_update_environmentrosKI()))yy{{'' e ;B 4''rrFr#c tjdtdtjd|ddd|Dd|tjd k}|tjd k}tj |}tj tj }td dd krBtj tj t}ntj d r tj d }nmtj t jd}tj |rtj |}||kr,tj|tjd|zntjd|zt't)|}t-di| t/|f||d|} ||kr+tj|tjd|zt-di|nB#||kr+tj|tjd|zt-di|wxYw| S)a Return (status,output) of executed command. .. deprecated:: 1.17 Use subprocess.Popen instead Parameters ---------- command : str A concatenated string of executable and arguments. execute_in : str Before running command ``cd execute_in`` and after ``cd -``. use_shell : {bool, None}, optional If True, execute ``sh -c command``. Default None (True) use_tee : {bool, None}, optional If True use tee. Default None (True) Returns ------- res : str Both stdout and stderr messages. Notes ----- On NT, DOS systems the returned status is correct for external commands. Wild cards will not work for non-posix systems or when use_shell=0. zJexec_command is deprecated since NumPy v1.17, use subprocess.Popen insteadr#r$z exec_command(,cg|]}d|zS)z%s=%rrB)rJkvs rrLz exec_command..s444"72:444r)Nr?irzexec_command.py.rz New cwd: %szRetaining cwd: %s) use_shelluse_teezRestored cwd to %srB)r&r'r(rrNr7rmr3r+r4rIgetcwd__name__dirname__file__r8rargvchdirrklistkeysro _exec_command) command execute_inrvrw _with_pythonrjoldcwdexec_diroldenvsts rrrs@ M-.@QPPPPIIwww 44 444 5 5 5 57888'7"GW$ ,,J W__RY[[ ) )F~''7??27??8#<#<== ) * *17??3''7??38A;// 7>>( # # 1wx00H z  -*,---- %./// "D$4$4 6 6F  3    & 7"%.#*""!"" :   HV    I*V3 4 4 4%%f%%%% :   HV    I*V3 4 4 4%%f%%%% Is J--?K,c 4|tjdk}|tjdk}tjdkrR|rPtjdd}t |r|dd|g}n|d|g}d}n>tjdkr.t |rdd |D}|pd} t j|||dt jt j }n#t$rYd SwxYw| \}}tj d}|d }||d }|dd}|dddkr |dd}|r|rt!||j|fS)z0 Internal workhorse for exec_command(). Nr?SHELLz/bin/shz-c Fr.c34K|]}t|VdSrA) _quote_arg)rJargs r z _exec_command..s(>>s:c??>>>>>>r)shellrjtextrstderr)rFr r r r rr)r3r+rOrPrr7 subprocessPopenPIPESTDOUTOSError communicaterrrr print returncode) rrvrwrjshprocrerrrs rrrsGW$ '7" w'i Z^^GY / / w   *4'!2!23GG4)G D[11((>>g>>>>> +C  yc'1'1'8::: ww  ""ID#*511H ;;x ; 2 2D << % %D BCCyDCRCy4 d ?D  s .C99 DDc d|vr d|vrd|zS|S)zB Quote the argument for safe use in a shell command line. rErz"%s"rB)rs rrr1s$  #~~#**| Jr)rFNNr#)NN)__doc____all__r3rrrr&numpy.distutils.misc_utilrrnumpy.distutilsrrr!r,r<rrkrorrrrBrrrs>22f , -  AAAAAAAA"???&#2////f ''' BF !IIIIX1!1!1!1!hr