
    yIff                        d Z ddlZddlZddl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mZmZmZ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mZmZmZ d
dl m!Z!m"Z"m#Z# d
dlm$Z$m%Z% d
dl&m'Z( d
dl&m)Z* d
dl+m,Z,m-Z-m.Z.  G d de          Z/de-dddfde0dee0         de.dee         de1dee1ef         dede0fdZ2dde-ddfde0dee1ef         dee0         de.dee         de1dede1fdZ3de-ddddfd ed!edee0         de.dee         de1dee1ef         d"e1dede1fd#Z4dde-ddfd edee1ef         dee0         de.dee         de1dede1fd$Z5de-dddfd%ee0ef         dee1ef         de.dee         de1dee0         dede1fd&Z6d'e%defd(Z7ej8        dee         fd)            Z9ej8        d%ee0ef         d'e%dee         fd*            Z:de-ddddddfd%ee0ef         dee0         de.dee         de1d+e1dee1ef         d,e1d-ee         dede1fd.Z;e-dddfde0de.dee         d/ee1e/f         d0e1dedeej<                 fd1Z=e-ddddfd ede.dee         d/ee1e/f         d0e1d2eee0                  dedeej<                 fd3Z>e-dddfd%ee0ef         de.dee         d/ee1e/f         d0e1dedeej<                 fd4Z?e-dddfd5eee0ef                  de.dee         d/ee1e/f         d0e1dedeej<                 fd6Z@de-fd7ee         de.dede.fd8ZAdS )9)	ImportKeycheck_code_string
check_filecheck_streamfind_imports_in_codefind_imports_in_filefind_imports_in_pathsfind_imports_in_streamplace_moduleplace_module_with_reasonsort_code_string	sort_filesort_stream    N)EnumStringIO)chain)Path)AnyIteratorOptionalSetTextIOUnioncast)warn)core   )filesidentifyio)ExistingSyntaxErrorsFileSkipCommentFileSkipSettingIntroducedSyntaxErrors)$ask_whether_to_apply_changes_to_filecreate_terminal_printershow_unified_diff)EmptyFile)module)module_with_reason)CYTHON_EXTENSIONSDEFAULT_CONFIGConfigc                   "    e Zd ZdZdZdZdZdZdS )r   a  Defines how to key an individual import, generally for deduping.

    Import keys are defined from less to more specific:

    from x.y import z as a
    ______| |        |    |
       |    |        |    |
    PACKAGE |        |    |
    ________|        |    |
          |          |    |
        MODULE       |    |
    _________________|    |
              |           |
           ATTRIBUTE      |
    ______________________|
                  |
                ALIAS
    r            N)__name__
__module____qualname____doc__PACKAGEMODULE	ATTRIBUTEALIAS     =/var/www/piapp/venv/lib/python3.11/site-packages/isort/api.pyr   r   +   s.         & GFIEEEr=   r   Fcode	extensionconfig	file_pathdisregard_skip	show_diffconfig_kwargsreturnc           	          t          |           }t                      }t          d||d|}t          |||||||           |                    d           |                                S )a  Sorts any imports within the provided code string, returning a new string with them sorted.

    - **code**: The string of code with imports that need to be sorted.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
    - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
    TextIO stream is provided results will be written to it, otherwise no diff will be computed.
    - ****config_kwargs**: Any config modifications.
    pathrA   )r@   rA   rB   rC   rD   r   r<   )r   _configr   seekread)	r?   r@   rA   rB   rC   rD   rE   input_streamoutput_streams	            r>   r   r   E   s    ( D>>LJJMD)FDDmDDF%    qr=   c                 d    t          d||d|}t          t          |           |||||          S )a2  Checks the order, format, and categorization of imports within the provided code string.
    Returns `True` if everything is correct, otherwise `False`.

    - **code**: The string of code with imports that need to be sorted.
    - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
    TextIO stream is provided results will be written to it, otherwise no diff will be computed.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
    - ****config_kwargs**: Any config modifications.
    rH   rD   r@   rA   rB   rC   r<   )rJ   r   r   )r?   rD   r@   rA   rB   rC   rE   s          r>   r   r   i   sM    * D)FDDmDDF%   r=   TrM   rN   raise_on_skipc                    |p|r|j                             d          pd}|rt                      }	t          |                                           }
t	          d|
|	|||||d|}|	                    d           |
                    d           t          |
                                |	                                ||du r|n||j                   |S t          d||d|}t          |pd          }|s&|r$|
                    |          rt          |          |}|j        r	 |                                 }t          ||d	dd
           nA# t          $ r4 |t          vrt!          |          |j        rt%          | d           Y nw xY wt          |          } |                                st                      }	 t)          j        | ||||          }n# t,          $ r t-          |          w xY w|j        r|                    d           	 t          |                                |d	dd
           |                    d           nA# t          $ r4 |t          vrt/          |          |j        rt%          | d           Y nw xY w||k    r'|                    |                                           |S )a  Sorts any imports within the provided code stream, outputs to the provided output stream.
     Returns `True` if anything is modified from the original input stream, otherwise `False`.

    - **input_stream**: The stream of code with imports that need to be sorted.
    - **output_stream**: The stream where sorted imports should be written to.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
    - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
    TextIO stream is provided results will be written to it, otherwise no diff will be computed.
    - ****config_kwargs**: Any config modifications.
    .py)rM   rN   r@   rA   rB   rC   rQ   r   T
file_inputfile_outputrB   outputcolor_outputrH   zPassed in contentexecr   z< Python AST errors found but ignored due to Cython extension)r@   rA   rQ   r<   )suffixlstripr   rL   r   rK   r(   rY   rJ   str
is_skippedr$   atomiccompileSyntaxErrorr-   r"   verboser   readabler   processr#   r%   write)rM   rN   r@   rA   rB   rC   rD   rQ   rE   _output_stream_input_streamchangedcontent_source_internal_outputfile_contents                  r>   r   r      s}   0 QiHI,<,C,CC,H,HQTI ! !2!2!4!455 	
&()'	
 	
 	
 	
 	A1$))++&++--$-$5$5==9,	
 	
 	
 	
 D)FDDmDDF9&9::N .i .F,=,=i,H,H .n---$} *		',,..LL.&!Q???? 	 	 	 111*>:::~ %ccc  		  --%%'' 	*'zz	.,'
 
 
  . . .n---. } 9a   		$))++^VQJJJ!!!$$$$ 	 	 	 111,^<<<~ %ccc  		 },, 0 5 5 7 7888Ns0   ''E ;FFG G6:I ;JJc                    t          d||d|}|r!t          |                                           } t          | t          ||||          }t          |j        |j        |j                  }|s*|j	        r!|j
        s|                    |pd d           dS |                    |pd d           |rt                      }	|                     d           |                                 }
t          t          |
          |	||||           |	                    d           t          |
|	                                ||du rd	n||j        
           dS )aE  Checks any imports within the provided code stream, returning `False` if any unsorted or
    incorrectly imports are found or `True` if no problems are identified.

    - **input_stream**: The stream of code with imports that need to be sorted.
    - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
    TextIO stream is provided results will be written to it, otherwise no diff will be computed.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
    - ****config_kwargs**: Any config modifications.
    rH   )rM   rN   r@   rA   rB   rC   )colorerrorsuccess z Everything Looks Good!Tz1 Imports are incorrectly sorted and/or formatted.r   NrU   Fr<   )rJ   r   rL   r   r)   r'   rY   format_errorformat_successrb   only_modifiedro   rn   rK   r(   )rM   rD   r@   rA   rB   rC   rE   rh   printerrN   file_contentss              r>   r   r      s   * D)FDDmDDF 5 1 1 3 344!%  G &!)<fF[  G  > 	I&"6 	IOOyBGGGHHHtMMY_"WWWXXX 
 

!$))++!-00')	
 	
 	
 	
 	1$%**,,$,,44),	
 	
 	
 	
 5r=   filenamec           
      ~   |}d|v r`|                     dd          }|rH|                    |           }	|j        rt          |	d          d|             t	          di |	d         }t
          j                            |           5 }
t          |
j	        f||||p|
j
        |d|cddd           S # 1 swxY w Y   dS )a)  Checks any imports within the provided file, returning `False` if any unsorted or
    incorrectly imports are found or `True` if no problems are identified.

    - **filename**: The name or Path of the file to check.
    - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
    TextIO stream is provided results will be written to it, otherwise no diff will be computed.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - ****config_kwargs**: Any config modifications.
    config_trieNr    used for file r   rP   r<   )popsearchrb   printr/   r!   r*   rL   r   streamrI   )rv   rD   rA   rB   rC   r@   rE   file_configrx   config_infosource_files              r>   r   r   1  s9   * !K%%#''t<< 	3%,,X66K~ DQBBBBCCC 22;q>22K	h		 	
;
3;#3)
 
 
 
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
s   B22B69B6r   c                 P    | j                             | j         j        dz             S )Nz.isorted)rI   with_suffixr[   )r   s    r>   	_tmp_filer   ]  s$    ''(8(?*(LMMMr=   c               #   .   K   t          d           V  d S )N)newliner   r<   r=   r>    _in_memory_output_stream_contextr   a  s#      
4
 
 
      r=   c              #      K   t          |          }|                    d|j        d          5 }t          j        | |           |V  d d d            d S # 1 swxY w Y   d S )Nzw+rp   )encodingr   )r   openr   shutilcopymode)rv   r   tmp_filerN   s       r>   _file_output_stream_contextr   f  s      %%H	tk&:B	G	G =(+++                 s   AAAask_to_applywrite_to_stdoutrX   c	                 
	   |}
d|	v r`|	                     dd          }|rH|                    |           }|j        rt          |d          d|             t	          di |d         }
t
          j                            |           5 }|p|j        }t          d||
d|	}d}	 |r&t          |j        t          j        ||||          }n`|	 |j        rt                      }nt!          | |          }|5 }t          |j        |||||          }|                    d           |ro|s|r|j                            d           t%          |j                                        |                                ||d	u rdnt'          t(          |          |j        
           |s#|rvt-          t/          |j                            sU	 ddd           	 |j        s#t1          |          }|                                 n# t4          $ r Y nw xY wddd           dS |j                                         |j        r\|                    d           |j                            d          5 }t;          j        ||           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |rN|j        s)t1          |          }|                    |j                   |j         st          d|j                    	 |j        s#t1          |          }|                                 n# t4          $ r Y nw xY w# 	 |j        s$t1          |          }|                                 w w # t4          $ r Y w w xY wxY wt          |j        |||||          }|ry|rw|j                            d           |                    d           t%          |j                                        |                                ||d	u rdn||j        
           |j                                         n?# tB          $ r tE          | d           Y n!tF          $ r tE          | d           Y nw xY w|cddd           S # 1 swxY w Y   dS )a:  Sorts and formats any groups of imports imports within the provided file or Path.
     Returns `True` if the file has been changed, otherwise `False`.

    - **filename**: The name or Path of the file to format.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **disregard_skip**: set to `True` if you want to ignore a skip set in config for this file.
    - **ask_to_apply**: If `True`, prompt before applying any changes.
    - **show_diff**: If `True` the changes that need to be done will be printed to stdout, if a
    TextIO stream is provided results will be written to it, otherwise no diff will be computed.
    - **write_to_stdout**: If `True`, write to stdout instead of the input file.
    - **output**: If a TextIO is provided, results will be written there rather than replacing
    the original file content.
    - ****config_kwargs**: Any config modifications.
    rx   Nr   ry   r   rH   F)rM   rN   rA   rB   rC   r@   TrU   wzFixing z- unable to sort due to existing syntax errorsz5 unable to sort as isort introduces new syntax errorsr<   )$rz   r{   rb   r|   r/   r!   r*   rL   rI   rJ   r   r}   sysstdoutoverwrite_in_placer   r   rK   r(   r   r   rY   r&   r]   r   unlinkFileNotFoundErrorcloser   r   copyfileobjreplacequietr"   r   r%   )rv   r@   rA   rB   rC   r   rD   r   rX   rE   r~   rx   r   r   actual_file_pathrh   output_stream_contextrN   r   fss                       r>   r   r   n  s   8 !K%%#''t<< 	3%,,X66K~ DQBBBBCCC 22;q>22K	h		 `;$8(8T.{TTmTTZ	] T/%!,!3"%*!.#1'   >5!!4 4T4V4V114O (+5 51 3 !Nm&1-8-?.;'-*:/=*3' ' 'G *..q111& N#, !5 !5$/$6$;$;A$>$>$>$53>3E3J3J3L3L4A4F4F4H4H2B+4+<+< 04t-1&)-D-D5;5H%& %& %& %& (1 %5(4%50T,/0@,A,A1* 1*%5 059!N !N !N !N !N !NR!#)#< 2+4[+A+A ( 1 1 10 ! ! ! D!I` ` ` ` ` ` ` `h !, 2 8 8 : : :#)#< !N$1$6$6q$9$9$9)4)9)>)>s)C)C %Nr(.(:="(M(M(M%N %N %N %N %N %N %N %N %N %N %N %N %N %N %NA!N !N !N !N !N !N !N !N !N !N !N !N !N !N !ND # D#)#< C+4[+A+A ( 0 01A B B B#)< D %&B0@&B&B C C C!#)#< 2+4[+A+A ( 1 1 10 ! ! ! D!	!#)#< 2+4[+A+A ( 1 1 1 12  1 ! ! ! D! *%0%7&,%"2'5"+  G  	9 	#*//222A)'2'9'>'>'@'@(.&6+4+<+<44))/)<     &,,...# 	U 	U 	U$SSSTTTTT% 	] 	] 	]$[[[\\\\\	] A` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `s  Q8"+P+(L;6CJ$L;*G?>P+?
H	P+HP+AJ$+JJ$JJ$JJ$L;$J(	(L;+J(	,AL; *L+*P++
L85P+7L88P+;M9=*M)'M9)
M6	3M95M6	6M99B1P+*Q8+Q'Q8	Q'$Q8&Q''Q88Q<?Q<uniquetop_onlyc           	   +   T   K   t          dt          |           ||||d|E d{V  dS )a  Finds and returns all imports within the provided code string.

    - **code**: The string of code with imports that need to be sorted.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **unique**: If True, only the first instance of an import is returned.
    - **top_only**: If True, only return imports that occur before the first function or class.
    - ****config_kwargs**: Any config modifications.
    rM   rA   rB   r   r   Nr<   )r	   r   )r?   rA   rB   r   r   rE   s         r>   r   r     sk      " & d^^            r=   _seenc              +     K   t          dd|i|}t          j        | |||          }|s|E d{V  |t                      n|}|D ]}	|dt          j        fv r|	                                }
nj|t          j        k    r|	j         d|	j	         }
nH|t          j
        k    r|	j        }
n0|t          j        k    r |	j                            d          d         }
|
r|
|vr|                    |
           |	V  dS )af  Finds and returns all imports within the provided code stream.

    - **input_stream**: The stream of code with imports that need to be sorted.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **unique**: If True, only the first instance of an import is returned.
    - **top_only**: If True, only return imports that occur before the first function or class.
    - **_seen**: An optional set of imports already seen. Generally meant only for internal use.
    - ****config_kwargs**: Any config modifications.
    rA   )rA   rB   r   NTrS   r   r<   )rJ   r    importssetr   r;   	statementr:   r+   	attributer9   r8   splitadd)rM   rA   rB   r   r   r   rE   identified_importsseenidentified_importkeys              r>   r	   r	     sJ     & 44F4m44F!)Vy8    &%%%%%%%%#mSUUUD/ $ $dIO,,,#--//CCy***&-MM0A0KMMCCy'''#*CCy(((#*0055a8C 	$3d??HHSMMM####$ $r=   c           
   +      K   t           j                            |           5 }t          d|j        ||p|j        ||d|E d{V  ddd           dS # 1 swxY w Y   dS )ac  Finds and returns all imports within the provided source file.

    - **filename**: The name or Path of the file to look for imports in.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **unique**: If True, only the first instance of an import is returned.
    - **top_only**: If True, only return imports that occur before the first function or class.
    - ****config_kwargs**: Any config modifications.
    r   Nr<   )r!   r*   rL   r	   r}   rI   )rv   rA   rB   r   r   rE   r   s          r>   r   r   =  s      $ 
h		 
;) 
$+3;#3
 
 
 
 	
 	
 	
 	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   %AAApathsc           	   +      K   t          ddi|rt                      ndt          fdt          j        t          t          |           g g           D              E d{V  dS )aj  Finds and returns all imports within the provided source paths.

    - **paths**: A collection of paths to recursively look for imports within.
    - **extension**: The file extension that contains imports. Defaults to filename extension or py.
    - **config**: The config object to use when sorting imports.
    - **file_path**: The disk location where the code string was pulled from.
    - **unique**: If True, only the first instance of an import is returned.
    - **top_only**: If True, only return imports that occur before the first function or class.
    - ****config_kwargs**: Any config modifications.
    rA   Nc              3   @   K   | ]}t          |           V  dS ))r   rA   r   r   N)r   ).0	file_namerA   r   r   r   s     r>   	<genexpr>z(find_imports_in_paths.<locals>.<genexpr>o  sT       

 

  !&(RV  

 

 

 

 

 

r=   r<   )rJ   r   r   r   findmapr]   )r   rA   rB   r   r   rE   r   s    ` `` @r>   r   r   Z  s      $ 44F4m44F(.8suuuDD

 

 

 

 

 

 

 #ZCRHH	

 

 

         r=   rI   c                     | r|t           u rd|vr	d|vr| |d<   |r$|t           urt          d          t          di |}|S )Nsettings_pathsettings_fileziYou can either specify custom configuration options using kwargs or passing in a Config object. Not Both!r<   )r.   
ValueErrorr/   )rI   rA   rE   s      r>   rJ   rJ   x  s{      ..  =00=00)-o& )''8  
 ((-((Mr=   )B__all__
contextlibr   r   enumr   r!   r   	itertoolsr   pathlibr   typingr   r   r   r   r   r   r   warningsr   isortr   rp   r   r    
exceptionsr"   r#   r$   r%   formatr&   r'   r(   r)   r*   placer+   r
   r,   r   settingsr-   r.   r/   r   r]   boolr   r   r   r   r   r   contextmanagerr   r   r   Importr   r	   r   r   rJ   r<   r=   r>   <module>r      s         



                         D D D D D D D D D D D D D D D D D D             ! ! ! ! ! ! ! ! ! !            e d d d d d d d d d         ) ) ) ) ) ) A A A A A A ? ? ? ? ? ? ? ? ? ?       8  $# $ %*!  ! 
! }!  !  ~	! 
 !  T6\"!  !  	!  !  !  ! L &+## $  
T6\" } 	
 ~   
   F  $# $ %*b bbb }b 	b
 ~b b T6\"b b b 
b b b bN &+## $ @ @@T6\"@ }@ 	@
 ~@ @ @ 
@ @ @ @J &+# $#)
 )
CI)
T6\")
 )
 ~	)

 )
 })
 )
 
)
 )
 )
 )
XN4 ND N N N N !(6*: ! ! ! ! %T	*:  RZ[aRb      $# $%*!#G GCIG}G G ~	G
 G G T6\"G G VG G 
G G G GX $ $%* 
 ~ $	/"	
   ho   : $ $%* $'$ '$'$'$ ~'$ $	/"	'$
 '$ CH'$ '$ ho'$ '$ '$ '$X $ $%*
 
CI

 ~
 $	/"	

 
 
 ho
 
 
 
> $ $%* E#t)$% ~ $	/"	
   ho   >  . 
4.)/SV     r=   