
     h.                    R   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr  SSKJrJr  SSKJr  SSKJrJrJrJr  SSKJrJr  SS	KJr  SS
KJr  \" \5      r\R:                  R<                  r " S S5      r     SS jr! " S S5      r"SS jr#SS jr$SS jr%SS jr&g)zExecute files of Python code.    )annotationsN)
ModuleSpec)CodeType
ModuleType)Any)CoverageExceptionNoCodeNoSource_ExceptionDuringRun)canonical_filenamepython_reported_file)isolate_module)get_python_sourcec                  "    \ rS rSrSrSS jrSrg)DummyLoader   zrA shim for the pep302 __loader__, emulating pkgutil.ImpLoader.

Currently only implements the .fullname attribute
c                    Xl         g )Nfullname)selfr   _argss      o/root/racknerd_01/codex-conversation/amazon-q-terraform/.venv/lib/python3.13/site-packages/coverage/execfile.py__init__DummyLoader.__init__$   s         r   N)r   strr   r   returnNone)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r      s    
!r   r   c                    [         R                  R                  U 5      nU(       d  [	        SU < 35      eUR                  nUR                  nUR                  (       aY  U S-   n[         R                  R                  U5      nU(       d  [	        SU S3U < S3-   5      eUR                  nUR                  nUR                  S5      S   nX4U4$ ! [         a  n[	        [        U5      5      UeSnAff = f)z{Find the module named `modulename`.

Returns the file path of the module, the name of the enclosing
package, and the spec.
NzNo module named z	.__main__z; z- is a package and cannot be directly executed.r   )
	importlibutil	find_specImportErrorr
   r   originnamesubmodule_search_locations
rpartition)
modulenamespecerrpathnamepackagenamemod_mains         r   find_moduler6   (   s    *~~''
3 )*899{{H))K&&+~~''1"8*B/N"OPQ  ;;ii((-a0K$&&#  *s3x c)*s   C 
C5C00C5c                  D    \ rS rSrSrS	S
S jjrSS jrSS jrSS jrSr	g)PyRunnerF   zoMulti-stage execution of Python code.

This is meant to emulate real Python execution as closely as possible.

c                v    Xl         X l        US   U l        S U l        S U l        S U l        S U l        S U l        g )Nr   )args	as_modulearg0packager0   r3   loaderr1   )r   r;   r<   s      r   r   PyRunner.__init__M   s:    	"G	#'&*$(*.'+	r   c                b   [        [        R                  SS5      (       a  SnOU R                  (       a  [        R
                  " 5       nO[        R                  R                  U R                  5      (       a  U R                  nOF[        R                  R                  [        R                  R                  U R                  5      5      n[        R                  R                  [        R                  S   5      (       a  [        R                  " 5       S   S   R                  R                  n[        R                  R                  [        R                  S   5      n[        R                  R                  [        R                  R                  U5      5      n[        U5      n[        U5      nX4:w  a  SnOV[        R                  S   [        R                  R                  [        R                  S   5      :X  a  [        R                  S	 Ub  [!        U5      [        R                  S'   gg)zcSet sys.path properly.

This needs to happen before any importing, and without importing anything.
	safe_pathFNr      )getattrsysflagsr<   osgetcwdpathisdirr=   abspathdirnameinspectstackf_codeco_filenamer   r   )r   path0top_filesys_path_0_abstop_file_dir_abss        r   preparePyRunner.prepareX   s\    399k511E^^IIKEWW]]499%% IIEGGOOBGGOODII$>?E77==!%% }}r*1-44@@HWW__SXXa[9N!wwrwwx/HI/?N12BC1
 xx{bggoochhqk::HHQK.u5CHHQK r   c                :   U R                   (       a  U R                  U l        [        U R                  5      u  ol        U l        U R
                  b  U R
                  R                  U l        [        U R                  5      U l        Uc   e[        R                  R                  U5      U l        U R                  =U R                  S'   U l        GO0[        R                  R                  U R                  5      (       a  S H{  n[        R                  R                  U R                  SU 35      n[        R                  R                  U5      n[        R                  R!                  U5      (       d  Mu  X0l          O   [#        SU R                   S35      e[%        U5      n[&        R(                  R+                  SSUS9U l        SU R
                  l        S	U l        [        S5      U l        O[        S5      U l        [%        U R                  5      U l        g)
zDo more preparation to run Python code.

Includes finding the module to run and adjusting sys.argv[0].
This method is allowed to import code.

Nr   )z.py.pyc.pyo__main__z!Can't find '__main__' module in '')r,   T )r<   r=   r0   r6   r>   r1   r-   r   r?   rH   rJ   rL   r3   r;   rK   joinexistsr
   r   r(   	machineryr   has_location)r   r3   exttry_filenames       r   	_prepare2PyRunner._prepare2   s    >>"iiDO0;DOO0L-HlDIyy$"&))..%doo6DK'''GGOOH5DM'+}}4DIIaL49WW]]499%% /!ww||DII#7GH  "ww|<77>>,// ,I / !B499+QOPP 0=L!++66z4P\6]DI%)DII"DL%j1DK%j1DK(3	r   c                   U R                  5         [        S5      nU R                  R                  S5      nU R                  Ul        U(       a  UR                  SS Ul        U R
                  b  U R
                  Ul        U R                  Ul        U R                  b  U R                  Ul
        [        R                  S   Ul        U[        R                  S'   U R                  [        l         U(       a  [!        U R                  5      nO[#        U R                  5      n [,        R.                  " 5       n [1        X1R2                  5        [,        RL                  " U5        g! [$         a    e [&         a:  nSU R                   SUR(                  R*                   SU 3n[%        U5      UeSnAff = f! [4         a    e [&         Ga    [        R6                  " 5       u  pxn	Uc   eUc   eU	c   e[9        US	S5         UR:                  c   eUR:                  R<                  Ul        [        R>                  " XxU	R<                  5        [        R@                  " S
5         GN! [4         a    e [&         a  n[        RB                  RE                  S5        [        R6                  " 5       u  pnU
c   eUc   eUc   eSUl#        UR:                  c   eUR:                  R<                  Ul        [        RH                  " XUR<                  5        [        RB                  RE                  S5        [K        XxU	R<                  5      UeSnAff = ff = f! [,        RL                  " U5        f = f)zRun the Python code!r[   )rY   rZ   NrC   builtinszCouldn't run 'z' as Python code: z: __context__rD   zError in sys.excepthook:
Tz
Original exception was:
)'rd   r   r=   endswith__file__r>   __package__r?   
__loader__r1   __spec__rF   modules__builtins__r;   argvmake_code_from_pycmake_code_from_pyr   	Exception	__class__r   rH   rI   exec__dict__
SystemExitexc_inforE   __traceback__tb_next
excepthookexitstderrwrite__suppress_context____excepthook__r   chdir)r   main_modfrom_pyccodeexcmsgcwdtypr2   tbtyp2err2tb2s                r   runPyRunner.run   s    	 j)99%%&67 II ( 1 1#2 6H<<##'<<H "kk99  $		H #J 7"*J 99
	2)$))4(3 iik/	(()\ HHSMs ! 	 	2"499+-?@V@V?WWYZ]Y^_C#C(c1	2  	  '	 <<>LCb?"??"?>!> C-((444$'$5$5$=$=!s4$ #   I 

  !=>"%,,.C''''''&,0)))555%)%7%7%?%?"""4s{{;

  !>?)#BJJ?SHI1'	R HHSMsc   1E& E& :F7 &F4:5F//F47A	MAI%M"M %M9CMMMM M+)r=   r;   r<   r?   r0   r>   r3   r1   N)F)r;   	list[str]r<   boolr   r   )r   r   )
r   r    r!   r"   r#   r   rV   rd   r   r$   r%   r   r   r8   r8   F   s    	,(6T'4RXr   r8   c                X    [        U SS9nUR                  5         UR                  5         g)zRun a Python module, as though with ``python -m name args...``.

`args` is the argument array to present as sys.argv, including the first
element naming the module being executed.

This is a helper for tests, to encapsulate how to use PyRunner.

Tr<   Nr8   rV   r   r;   runners     r   run_python_moduler     s#     dd+F
NN
JJLr   c                X    [        U SS9nUR                  5         UR                  5         g)a3  Run a Python file as if it were the main program on the command line.

`args` is the argument array to present as sys.argv, including the first
element naming the file being executed.  `package` is the name of the
enclosing package, if any.

This is a helper for tests, to encapsulate how to use PyRunner.

Fr   Nr   r   s     r   run_python_filer     s#     de,F
NN
JJLr   c                     [        U 5      n[        XSSS9nU$ ! [        [        4 a  n[        SU  S35      UeSnAff = f)z8Get source from `filename` and make a code object of it.No file to run: 'r\   Nru   T)modedont_inherit)r   OSErrorr
   compile)filenamesourcer   r   s       r   rr   rr   #  sW    A"8, 6&tDDK	 X A*8*A67S@As    ?:?c                0    [        U S5      nU   UR                  S5      nU[        :w  a  [        SU< S[        < 35      e[
        R                  " SUR                  S5      5      S	   nUS
-  nU(       a  UR                  S5        O"UR                  S5        UR                  S5        [        R                  " U5      n[        U[        5      (       d   e SSS5        U$ ! [         a  n[        SU  S35      UeSnAff = f! , (       d  f       W$ = f)z#Get a code object from a .pyc file.rbr   r\   N   zBad magic number in .pyc file: z != z<Lr   rD      )openr   r	   readPYC_MAGIC_NUMBERstructunpackmarshalload
isinstancer   )r   fpycr   magicrG   
hash_basedr   s          r   rq   rq   .  s    ?Hd# 
 		!$$:5)4HXG[\]]dDIIaL1!4T\
IIaL IIaLIIaL ||D!$))))% 
( K/  ?(
!453>? 
( Ks#   C$ C	D$
D.C>>D
D)r0   r   r   z"tuple[str | None, str, ModuleSpec])r;   r   r   r   )r   r   r   r   )'r#   
__future__r   importlib.machineryr(   importlib.utilrN   r   rH   r   rF   r   typesr   r   typingr   coverage.exceptionsr   r	   r
   r   coverage.filesr   r   coverage.miscr   coverage.pythonr   r)   MAGIC_NUMBERr   r   r6   r8   r   r   rr   rq   r%   r   r   <module>r      s    $ "     	  
 * &  X X C ( -B >>.. ! !''''<} }@r   