HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/util/__pycache__/tool_support.cpython-310.pyc
o

���g��@s�dZddlmZddlmZddlmZddlZddlZddlZddl	m
Z
ddlZddlZddl
Z
ddlZddlmZddlmZdd	lmZdd
lmZddlmZdd
lmZGdd�d�ZdS)z�support 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@s�eZdZUded<ded<ded<ded<ded	<ded
<d1d
d�Zd2dd�Zd2dd�Zd3dd�Zd4dd�Zd5d d!�Z	d6d"d#�Z
d$d$d%�d7d)d*�Zej
d8d,d-��Zej
d9d/d0��Zd$S):�code_writer_cmdr�parserr�args�bool�suppress_output�diffs_detectedr�source_root�pyproject_toml_path�tool_script�strcCs^t|�jj|_|jtd�|_|j��sJ�t�|_|jjdddd�|jjddddd	�dS)
Nzpyproject.tomlz--stdout�
store_truez)Write to stdout instead of saving to file)�action�help�-cz--checkz�Don'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)rr)r�parentrr�existsrr�add_argument)�selfr�r�G/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/tool_support.py�__init__+s�
�zcode_writer_cmd.__init__�tempfile�return�NonecC�"|�t|�dd|j��d��dS)N�zimportsz--toml-config ��
entrypoint�options��_run_console_scriptrr�rr"rrr �run_zimports?�
��zcode_writer_cmd.run_zimportscCr%)N�blackz	--config r'r*r,rrr �	run_blackHr.zcode_writer_cmd.run_black�pathr)�Dict[str, Any]c
Cs�tjdk}|d}t�d�D]}|j|kr|}nqtd|����|�dd�}tj||d�|g}i}	|jr?t	j
|	d<|	d	<t	jtj
d
d|j|j|jfg|fd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)�)r3�stdout�stderrrzimport %s; %s.%s()�cwdN)�os�namer�importlib_metadata_get�	Exception�get�shlex�splitr�
subprocess�DEVNULL�run�sys�
executable�module�attrrr)
rr1r)�is_posix�entrypoint_name�entry�impl�cmdline_options_str�cmdline_options_list�kwrrr r+Qs>

��������
�z#code_writer_cmd._run_console_script�textcGs |jstj�d�|��dSdS)N� )rrCr7�write�join)rrNrrr �write_statusxs�zcode_writer_cmd.write_status�destination_path�Union[str, Path]cCsb|jjr
|j||d�dS|jjrt|�dS|�d|�d��t|�j|ddd�|�d�dS)N)�source�Writing �...�utf-8�
)�encoding�newline�done
)r�check�	_run_diffr6�printrRr�
write_text)rrNrSrrr �write_output_file_from_text|s�z+code_writer_cmd.write_output_file_from_textcCs�|jjr|j||d�t�|�dS|jjr7t|��}t|���Wd�n1s+wYt�|�dS|�	d|�d��t
�||�|�	d�dS)N)�source_filerVrWr\)rr]r^r9�unlinkr6�openr_�readrR�shutil�move)rr"rS�tfrrr �write_output_file_from_tempfile�s
�z/code_writer_cmd.write_output_file_from_tempfileN)rUrbrU�
Optional[str]rbc		Cs�|rt|dd��}t|�}Wd�n1swYn|dur(|jdd�}nJd��t|dd��2}tjt|�|t|���ddd	d
�}t|�}|r\d|_td�	|��Wd�dSWd�dS1sgwYdS)NrX)rZT)�keependsFz!source or source_file is requiredz<proposed changes>�rY)�fromfile�tofile�n�linetermr5)
rd�list�
splitlines�difflib�unified_diffr�as_posixrr_rQ)	rrSrUrbrh�source_lines�dp�d�	d_as_listrrr r^�s0
��
��
"�zcode_writer_cmd._run_diff�Iterator[ArgumentParser]ccs�|jVdS)N)r�rrrr �
add_arguments�s�zcode_writer_cmd.add_arguments�Iterator[None]ccsj�|j��|_|jjrd|_d|_n|jjrd|_nd|_dV|jjr.|jr.t�d�dSt�d�dS)NFTrr)	r�
parse_argsrr]rrr6rC�exitr{rrr �run_program�s�zcode_writer_cmd.run_program)rr)r"rr#r$)r1rr)r2r#r$)rNrr#r$)rNrrSrTr#r$)r"rrSrr#r$)rSrTrUrjrbrjr#r$)r#rz)r#r})�__name__�
__module__�__qualname__�__annotations__r!r-r0r+rRrarir^�
contextlib�contextmanagerr|r�rrrr r
#s*



	
	
'

�r
)�__doc__�
__future__r�argparserrr�rsr9�pathlibrr>rfr@rC�typingrrrr	r
r5rr
rrrr �<module>s&