
    e?1iQ                        d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	m
Z
 ddl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  G d d      Zy)zsupport routines for the helpers in tools/.

These aren't imported by the enclosing util package as the are not
needed for normal library use.

    )annotations)ArgumentParser)	NamespaceN)Path)Any)Dict)Iterator)Optional   )compatc                     e Zd ZU ded<   ded<   ded<   ded<   ded	<   ded
<   ddZddZddZddZddZ	 	 	 	 	 	 ddZ		 	 	 	 	 	 ddZ
ddd	 	 	 	 	 	 	 ddZej                  dd       Zej                  dd       Zy) code_writer_cmdr   parserr   argsboolsuppress_outputdiffs_detectedr   source_rootpyproject_toml_pathc                V   t        |      j                  j                  | _        | j                  t        d      z  | _        | j                  j	                         sJ t               | _        | j                  j                  ddd       | j                  j                  dddd	       y )
Nzpyproject.tomlz--stdout
store_truez)Write to stdout instead of saving to file)actionhelp-cz--checkzDon't write the files back, just return the status. Return code 0 means nothing would change. Return code 1 means some files would be reformatted)r   r   )r   parentr   r   existsr   r   add_argument)selftool_scripts     f/home/www/therecruiter.miabetepe.com/venv/lib/python3.12/site-packages/sqlalchemy/util/tool_support.py__init__zcode_writer_cmd.__init__*   s    ,33::#'#3#3d;K6L#L ''..000$&  < 	! 	

 	  B   	! 	
    c                Z    | j                  t        |      dd| j                   d       y )Nzimportsz--toml-config 
entrypointoptions_run_console_scriptstrr   r   tempfiles     r    run_zimportszcode_writer_cmd.run_zimports>   s0      M(+D,D,D+EF	
r"   c                Z    | j                  t        |      dd| j                   d       y )Nblackz	--config r%   r(   r+   s     r    	run_blackzcode_writer_cmd.run_blackG   s0      M%&t'?'?&@A	
r"   c                   t         j                  dk(  }|d   }t        j                  d      D ]  }|j                  |k(  s|} n t	        d|       |j                  dd      }t        j                  ||      |gz   }i }	| j                  rt        j                  x|	d<   |	d	<   t        j                  t        j                  d
d|j                  d|j                  d|j                  dg|z   fdt!        | j"                        i|	 y)zeRun a Python console application from within the process.

        Used for black, zimports

        posixr&   console_scriptsz*Could not find entrypoint console_scripts.r'    )r2   stdoutstderrr   zimport z; .z()cwdN)osnamer   importlib_metadata_get	Exceptiongetshlexsplitr   
subprocessDEVNULLrunsys
executablemoduleattrr*   r   )
r   pathr'   is_posixentrypoint_nameentryimplcmdline_options_strcmdline_options_listkws
             r    r)   z#code_writer_cmd._run_console_scriptP   s    77g%!,/223DE 	Ezz_,	
 <_<MN  &kk)R8${{x 
F   *4*<*<<BxL2h<(,T[[$))L
 ##		
 D$$%		
 		
r"   c                z    | j                   s/t        j                  j                  dj	                  |             y y )N )r   rC   r6   writejoin)r   texts     r    write_statuszcode_writer_cmd.write_statusw   s*    ##JJSXXd^, $r"   c                   | j                   j                  r| j                  ||       y | j                   j                  rt	        |       y | j                  d| d       t        |      j                  |       | j                  d       y )N)sourceWriting ...done
)r   check	_run_diffr5   printrT   r   
write_text)r   rS   destination_paths      r    write_output_file_from_textz+code_writer_cmd.write_output_file_from_text{   so     99??NN+DN9YY$K)9(:#>?!"--d3h'r"   c                   | j                   j                  r)| j                  ||       t        j                  |       y | j                   j
                  rCt        |      5 }t        |j                                d d d        t        j                  |       y | j                  d| d       t        j                  ||       | j                  d       y # 1 sw Y   \xY w)N)source_filerW   rX   rY   )r   rZ   r[   r9   unlinkr5   openr\   readrT   shutilmove)r   r,   r^   tfs       r    write_output_file_from_tempfilez/code_writer_cmd.write_output_file_from_tempfile   s     99??NN+NBIIhYYh !2bggi !IIh)9(:#>?KK"23h'! !s   !CCN)rV   ra   c          	     |   |r t        |      5 }t        |      }d d d        n||j                  d      }nJ d       t        |      5 }t        j                  t        |      |ddd      }t        |      }|r!d| _        t        dj                  |             d d d        y # 1 sw Y   pxY w# 1 sw Y   y xY w)	NT)keependsz!source or source_file is requiredz<proposed changes>   
)fromfiletofilenlinetermr4   )rc   list
splitlinesdifflibunified_diffr   r\   rR   )	r   r^   rV   ra   rg   source_linesdpd	d_as_lists	            r    r[   zcode_writer_cmd._run_diff   s     k" (b#Bx( (!,,d,;L===5"# 	*r$$R)+A QI&*#bggi()	* 	*( (	* 	*s   B&
AB2&B/2B;c              #  (   K   | j                    y w)N)r   r   s    r    add_argumentszcode_writer_cmd.add_arguments   s     kks   c              #    K   | j                   j                         | _        | j                  j                  rd| _        d| _        n%| j                  j                  rd| _        nd| _        d  | j                  j                  r"| j                  rt        j                  d       y t        j                  d       y w)NFTr   r   )	r   
parse_argsr   rZ   r   r   r5   rC   exitrz   s    r    run_programzcode_writer_cmd.run_program   s~     KK**,	99??"'D#'D YY#'D #(D 99??t22HHQKHHQKs   B<B>)r   r*   )r,   r*   returnNone)rG   r*   r'   zDict[str, Any]r   r   )rS   r*   r   r   )rS   r*   r^   r*   r   r   )r,   r*   r^   r*   r   r   )r^   r*   rV   Optional[str]ra   r   r   r   )r   zIterator[ArgumentParser])r   zIterator[None])__name__
__module____qualname____annotations__r!   r-   r0   r)   rT   r_   rh   r[   
contextlibcontextmanagerr{   r    r"   r    r   r   "   s    
O
(

%
N-
(
(+.
(	
(((/2(	(& !%%)** 	*
 #* 
*:    r"   r   )__doc__
__future__r   argparser   r   r   rs   r9   pathlibr   r>   re   r@   rC   typingr   r   r	   r
   r4   r   r   r   r"   r    <module>r      sH    # #    	     
     d dr"   