
    h                        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 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)Union   )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     ED:\EasyAligner\venv\Lib\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_blackH   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(    )r3   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_scriptQ   s    77g%!,/223DEEzz_, F
 <_<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   rD   r7   writejoin)r   texts     r!   write_statuszcode_writer_cmd.write_statusx   s*    ##JJSXXd^, $r#   c                "   | j                   j                  r| j                  ||       y | j                   j                  rt	        |       y | j                  d| d       t        |      j                  |dd       | j                  d       y )N)sourceWriting ...utf-8
)encodingnewlinedone
)r   check	_run_diffr6   printrU   r   
write_text)r   rT   destination_paths      r!   write_output_file_from_textz+code_writer_cmd.write_output_file_from_text|   s}     99??NN+DN9YY$K)9(:#>?!"--w .  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_filerX   rY   r^   )r   r_   r`   r:   unlinkr6   openra   readrU   shutilmove)r   r-   rc   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)rW   rf   c          	        |r"t        |d      5 }t        |      }d d d        n||j                  d      }nJ d       t        |d      5 }t        j                  t        |      t        |      j                         ddd	      }t        |      }|r!d| _        t        d
j                  |             d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrZ   )r\   T)keependsz!source or source_file is requiredz<proposed changes>   r[   )fromfiletofilenlinetermr5   )
rh   list
splitlinesdifflibunified_diffr   as_posixr   ra   rS   )	r   rc   rW   rf   rl   source_linesdpd	d_as_lists	            r!   r`   zcode_writer_cmd._run_diff   s     kG4#Bx 54!,,d,;L===5"W5$$R./88:+A QI&*#bggi() 65 54 65s   CA*CC
C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   r_   r   r   r6   rD   exitr   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)rH   r+   r(   zDict[str, Any]r   r   )rT   r+   r   r   )rT   r+   rc   Union[str, Path]r   r   )r-   r+   rc   r+   r   r   )rc   r   rW   Optional[str]rf   r   r   r   )r   zIterator[ArgumentParser])r   zIterator[None])__name__
__module____qualname____annotations__r"   r.   r1   r*   rU   rd   rm   r`   
contextlibcontextmanagerr   r    r#   r!   r   r   #   s    
O
(

%
N-((+;(	(((/2(	(& !%%)*** 	*
 #* 
*:    r#   r   )__doc__
__future__r   argparser   r   r   rw   r:   pathlibr   r?   rj   rA   rD   typingr   r   r	   r
   r   r5   r   r   r   r#   r!   <module>r      sK    # #    	     
      f fr#   