
    [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dS )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dS )0code_writer_cmdr   parserr   argsboolsuppress_outputdiffs_detectedr   source_rootpyproject_toml_pathtool_scriptstrc                L   t          |          j        j        | _        | j        t          d          z  | _        | j                                        sJ t                      | _        | j                            ddd           | j                            dddd	           d S )
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)selfr   s     k/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/util/tool_support.py__init__zcode_writer_cmd.__init__+   s    ,,3:#'#3d;K6L6L#L '..00000$&&  < 	! 	
 	
 	

 	  B   	! 	
 	
 	
 	
 	
    tempfilereturnNonec                b    |                      t          |          dd| j         d           d S )Nzimportsz--toml-config 
entrypointoptions_run_console_scriptr   r   r!   r%   s     r"   run_zimportszcode_writer_cmd.run_zimports?   sH      MM(FD,DFF 	
 	
 	
 	
 	
r$   c                b    |                      t          |          dd| j         d           d S )Nblackz	--config r*   r-   r/   s     r"   	run_blackzcode_writer_cmd.run_blackH   sH      MM%At'?AA 	
 	
 	
 	
 	
r$   pathr,   Dict[str, Any]c                   t           j        dk    }|d         }t          j        d          D ]}|j        |k    r|} nt	          d|           |                    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|	 dS )zeRun a Python console application from within the process.

        Used for black, zimports

        posixr+   console_scriptsz*Could not find entrypoint console_scripts.r,    )r7   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!   r4   r,   is_posixentrypoint_nameentryimplcmdline_options_strcmdline_options_listkws
             r"   r.   z#code_writer_cmd._run_console_scriptQ   sJ    7g%!,/23DEE 	 	Ez_,, - N_NN   &kk)R88${x 
  
  
F    	=*4*<<BxL2h<(,T[[[$)))L
 ##		
 		
 D$%%		
 		
 		
 		
 		
 		
r$   textc                |    | j         s4t          j                            d                    |                     d S d S )N )r   rH   r;   writejoin)r!   rS   s     r"   write_statuszcode_writer_cmd.write_statusx   s=    # 	-JSXXd^^,,,,,	- 	-r$   destination_pathUnion[str, Path]c                0   | j         j        r|                     ||           d S | j         j        rt	          |           d S |                     d| d           t          |                              |dd           |                     d           d S )N)sourceWriting ...utf-8
)encodingnewlinedone
)r   check	_run_diffr:   printrX   r   
write_text)r!   rS   rY   s      r"   write_output_file_from_textz+code_writer_cmd.write_output_file_from_text|   s     9? 		(NN+DN99999Y 	($KKKKK>)9>>>???!""--w .    h'''''r$   c                   | j         j        r-|                     ||           t          j        |           d S | j         j        r^t          |          5 }t          |                                           d d d            n# 1 swxY w Y   t          j        |           d S | 	                    d| d           t          j        ||           | 	                    d           d S )N)source_filer]   r^   rc   )r   rd   re   r>   unlinkr:   openrf   readrX   shutilmove)r!   r%   rY   tfs       r"   write_output_file_from_tempfilez/code_writer_cmd.write_output_file_from_tempfile   s"    9? 
	(NN+NBBBIhY 	(h !2bggii   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !Ih>)9>>>???K"2333h'''''s   "BB
BN)r\   rj   r\   Optional[str]rj   c          	        |r9t          |d          5 }t          |          }d d d            n# 1 swxY w Y   n#||                    d          }n
J d            t          |d          5 }t          j        t          |          |t          |                                          ddd	
          }t          |          }|r)d| _        t          d	                    |                     d d d            d S # 1 swxY w Y   d S )Nr_   )ra   T)keependsFz!source or source_file is requiredz<proposed changes>   r`   )fromfiletofilenlinetermr9   )
rl   list
splitlinesdifflibunified_diffr   as_posixr   rf   rW   )	r!   rY   r\   rj   rp   source_linesdpd	d_as_lists	            r"   re   zcode_writer_cmd._run_diff   s     	>kG444 (#Bxx( ( ( ( ( ( ( ( ( ( ( ( ( ( (!,,d,;;LL====="W555 	*$R.//88::+  A QI *&*#bggi(()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   0440BC>>DDIterator[ArgumentParser]c              #     K   | j         V  d S )N)r   r!   s    r"   add_argumentszcode_writer_cmd.add_arguments   s      kr$   Iterator[None]c              #  4  K   | j                                         | _        | j        j        rd| _        d| _        n| j        j        rd| _        nd| _        d V  | j        j        r| j        rt          j        d           d S t          j        d           d S )NFTr   r   )	r   
parse_argsr   rd   r   r   r:   rH   exitr   s    r"   run_programzcode_writer_cmd.run_program   s      K**,,	9? 	)"'D#'D  Y 	)#'D  #(D 9? 	t2 	HQKKKKKHQKKKKKr$   )r   r   )r%   r   r&   r'   )r4   r   r,   r5   r&   r'   )rS   r   r&   r'   )rS   r   rY   rZ   r&   r'   )r%   r   rY   r   r&   r'   )rY   rZ   r\   rr   rj   rr   r&   r'   )r&   r   )r&   r   )__name__
__module____qualname____annotations__r#   r0   r3   r.   rX   rh   rq   re   
contextlibcontextmanagerr   r    r$   r"   r   r   #   sV        OOO
 
 
 
(
 
 
 

 
 
 
%
 %
 %
 %
N- - - -( ( ( (( ( ( (& !%%)* * * * * *:          r$   r   )__doc__
__future__r   argparser   r   r   r|   r>   pathlibr   rC   rn   rE   rH   typingr   r   r	   r
   r   r9   r   r   r   r$   r"   <module>r      sF    # " " " " " # # # # # #            				             



                                    f f f f f f f f f fr$   