o
    jQ                     @  s   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 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   )compatc                   @  s   e Zd ZU ded< ded< ded< ded< ded	< ded
< d0ddZd1ddZd1ddZd2ddZd3ddZd4dd Z	d5d!d"Z
d#d#d$d6d(d)Zejd7d+d,Zejd8d.d/Zd#S )9code_writer_cmdr   parserr   argsboolsuppress_outputdiffs_detectedr   source_rootpyproject_toml_pathtool_scriptstrc                 C  s^   t |jj| _| jt d | _| j sJ t | _| jjdddd | jjd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    r   \/var/www/html/LicenciasMiG/venv/lib/python3.10/site-packages/sqlalchemy/util/tool_support.py__init__*   s   
zcode_writer_cmd.__init__tempfilereturnNonec                 C  "   |  t|dd| j d d S )Nzimportsz--toml-config 
entrypointoptions_run_console_scriptr   r   r   r!   r   r   r   run_zimports>      
zcode_writer_cmd.run_zimportsc                 C  r$   )Nblackz	--config r&   r)   r+   r   r   r   	run_blackG   r-   zcode_writer_cmd.run_blackpathr(   Dict[str, Any]c           
      C  s   t jdk}|d }tdD ]}|j|kr|} nqtd| |dd}tj||d|g }i }	| jr?t	j
 |	d< |	d	< t	jtjd
d|j|j|jf g| 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(    )r2   stdoutstderrr   zimport %s; %s.%s()cwdN)osnamer   importlib_metadata_get	Exceptiongetshlexsplitr   
subprocessDEVNULLrunsys
executablemoduleattrr   r   )
r   r0   r(   is_posixentrypoint_nameentryimplcmdline_options_strcmdline_options_listkwr   r   r   r*   P   s>   


z#code_writer_cmd._run_console_scripttextc                 G  s    | j stjd| d S d S )N )r   rB   r6   writejoin)r   rM   r   r   r   write_statusw   s   zcode_writer_cmd.write_statusdestination_pathc                 C  s\   | j jr| j||d d S | j jrt| d S | d| d t|| | d d S )N)sourceWriting ...done
)r   check	_run_diffr5   printrQ   r   
write_text)r   rM   rR   r   r   r   write_output_file_from_text{   s   z+code_writer_cmd.write_output_file_from_textc                 C  s   | j jr| j||d t| d S | j jr7t|}t|  W d    n1 s+w   Y  t| d S | 	d| d t
|| | 	d d S )N)source_filerT   rU   rV   )r   rW   rX   r8   unlinkr5   openrY   readrQ   shutilmove)r   r!   rR   tfr   r   r   write_output_file_from_tempfile   s   
z/code_writer_cmd.write_output_file_from_tempfileN)rS   r\   rS   Optional[str]r\   c          	   	   C  s   |rt |}t|}W d    n1 sw   Y  n|d ur&|jdd}nJ dt |.}tjt|||dddd}t|}|rTd| _td	| W d    d S W d    d S 1 s_w   Y  d S )
NT)keependsFz!source or source_file is requiredz<proposed changes>   
)fromfiletofilenlinetermr4   )r^   list
splitlinesdifflibunified_diffr   rY   rP   )	r   rR   rS   r\   rb   source_linesdpd	d_as_listr   r   r   rX      s0   



"zcode_writer_cmd._run_diffIterator[ArgumentParser]c                 c  s    | j V  d S )N)r   r   r   r   r   add_arguments   s   zcode_writer_cmd.add_argumentsIterator[None]c                 c  sj    | j  | _| jjrd| _d| _n| jjrd| _nd| _d V  | jjr.| jr.td d S td d S )NFTr
   r   )	r   
parse_argsr   rW   r   r   r5   rB   exitru   r   r   r   run_program   s   zcode_writer_cmd.run_program)r   r   )r!   r   r"   r#   )r0   r   r(   r1   r"   r#   )rM   r   r"   r#   )rM   r   rR   r   r"   r#   )r!   r   rR   r   r"   r#   )rR   r   rS   rd   r\   rd   r"   r#   )r"   rt   )r"   rw   )__name__
__module____qualname____annotations__r    r,   r/   r*   rQ   r[   rc   rX   
contextlibcontextmanagerrv   rz   r   r   r   r   r   "   s*   
 


	
	
'

r   )__doc__
__future__r   argparser   r   r   rn   r8   pathlibr   r=   r`   r?   rB   typingr   r   r   r	   r4   r   r   r   r   r   r   <module>   s$   