zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
U
¸ý°dã@sºdZddlmZddlmZddlmZddlZddlZddlZddl    m
Z
ddl Z ddl Z ddl Z ddlZddlmZddlmZdd    lmZdd
lmZd d lmZGd d„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é)Úcompatc@söeZdZUded<ded<ded<ded<ded    <ded
<d d œd d„Zd ddœdd„Zd ddœdd„Zd dddœdd„Zd ddœdd„Zd d ddœdd„Z    d d ddœd d!„Z
d"d"d#œd d$d$dd%œd&d'„Z e j d(d)œd*d+„ƒZe j d,d)œd-d.„ƒZd"S)/Úcode_writer_cmdrÚparserrÚargsÚboolÚsuppress_outputÚdiffs_detectedrÚ source_rootÚpyproject_toml_pathÚstr)Ú tool_scriptcCs^t|ƒjj|_|jtdƒ|_|j ¡s,t‚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ÚexistsÚAssertionErrorrr Ú add_argument)Úselfr©rúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/util/tool_support.pyÚ__init__*sýúzcode_writer_cmd.__init__ÚNone)ÚtempfileÚreturncCs"| t|ƒdd|j›dœ¡dS)NZzimportsz--toml-config ©Ú
entrypointÚoptions©Ú_run_console_scriptrr©rr#rrr Ú run_zimports>s 
þþzcode_writer_cmd.run_zimportscCs"| t|ƒdd|j›dœ¡dS)NZblackz    --config r%r(r*rrr Ú    run_blackGs 
þþzcode_writer_cmd.run_blackzDict[str, Any])Úpathr'r$c
Csºtjdk}|d}t d¡D]}|j|kr|}qBqtd|›ƒ‚| dd¡}tj||d|g}i}    |jr~t    j
|    d<|    d    <t    j t 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'Ú)r.ÚstdoutÚstderrrzimport %s; %s.%s()ÚcwdN)ÚosÚnamer Zimportlib_metadata_getÚ    ExceptionÚgetÚshlexÚsplitrÚ
subprocessÚDEVNULLÚrunÚsysÚ
executableÚmoduleÚattrrr)
rr-r'Zis_posixZentrypoint_nameÚentryÚimplZcmdline_options_strZcmdline_options_listÚkwrrr r)Ps>
 
ÿ ÿþýûÿùøz#code_writer_cmd._run_console_script)Útextr$cGs|jstj d |¡¡dS)Nú )rr=r2ÚwriteÚjoin)rrDrrr Ú write_statuswszcode_writer_cmd.write_status)rDÚdestination_pathr$cCsX|jjr|j||dn<|jjr*t|ƒn*| d|›d¡t|ƒ |¡| d¡dS)N)ÚsourceúWriting ú...údone
)rÚcheckÚ    _run_diffr1ÚprintrHrÚ
write_text)rrDrIrrr Úwrite_output_file_from_text{s
z+code_writer_cmd.write_output_file_from_text)r#rIr$c    Cs‚|jjr"|j||dt |¡n\|jjrVt|ƒ}t| ¡ƒW5QRXt |¡n(|     d|›d¡t
  ||¡|     d¡dS)N)Ú source_filerKrLrM) rrNrOr4Úunlinkr1ÚopenrPÚreadrHÚshutilÚmove)rr#rIÚtfrrr Úwrite_output_file_from_tempfile‡s 
  z/code_writer_cmd.write_output_file_from_tempfileN)rJrSz Optional[str])rIrJrSr$c        Cs–|r"t|ƒ}t|ƒ}W5QRXn"|dk    r8|jdd}n dsDtdƒ‚t|ƒ@}tjt|ƒ||dddd}t|ƒ}|rˆd|_td     |¡ƒW5QRXdS)
NT)ÚkeependsFz!source or source_file is requiredz<proposed changes>éÚ
)ZfromfileZtofileÚnZlinetermr0)    rUÚlistÚ
splitlinesrÚdifflibZ unified_diffrrPrG)    rrIrJrSrYZ source_linesZdpÚdZ    d_as_listrrr rO–s&
 
úzcode_writer_cmd._run_diffzIterator[ArgumentParser])r$ccs |jVdS)N)r ©rrrr Ú add_arguments³szcode_writer_cmd.add_argumentszIterator[None]ccsf|j ¡|_|jjr"d|_d|_n|jjr2d|_nd|_dV|jjrX|jrXt d¡n
t d¡dS)NFTr
r)    r Ú
parse_argsrrNrrr1r=Úexitrcrrr Ú run_program·s  zcode_writer_cmd.run_program)Ú__name__Ú
__module__Ú __qualname__Ú__annotations__r!r+r,r)rHrRrZrOÚ
contextlibÚcontextmanagerrdrgrrrr r "s(
        ' ûr )Ú__doc__Ú
__future__rÚargparserrrlrar4Úpathlibrr8rWr:r=Útypingrrrr    r0r r rrrr Ú<module>s"