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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
U
Z±dã@s°dZddlZddlZddlZddlZddlmZddlZddlm    Z    dZ
dZ dZ dZ d    d
„Zd d „Zd d„Zdd„Zeeedœdd„Zdd„Zdd„Zdd„Zedkr¬eƒdS)zG
Code generation script for class methods
to be exported as public API
éN)ÚPath)ÚindentZ
_generatedaT# ***********************************************************
# ******* WARNING: AUTOGENERATED! ALL EDITS WILL BE LOST ******
# *************************************************************
from ._run import GLOBAL_RUN_CONTEXT, _NO_SEND
from ._ki import LOCALS_KEY_KI_PROTECTION_ENABLED
from ._instrumentation import Instrument
 
# fmt: off
z
# fmt: on
z¯locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
try:
    return{}GLOBAL_RUN_CONTEXT.{}.{}
except AttributeError:
    raise RuntimeError("must be called from async context")
cCs t|tjƒst|tjƒrdSdS)zHCheck if the AST node is either a function
    or an async function
    TF)Ú
isinstanceÚastZ FunctionDefÚAsyncFunctionDef)Únode©rúNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_tools/gen_exports.pyÚ is_function'sr
cCs8t|ƒs dS|jD] }t|tjƒr|jdkrdSqdS)z-Check if the AST node has a _public decoratorFZ_publicT)r
Údecorator_listrrÚNameÚid)rÚ    decoratorrrr    Ú    is_public0s 
rccs"t |¡D]}t|ƒr
|Vq
dS)z¢Return a list of methods marked as public.
    The function walks the given tree and extracts
    all objects that are functions which are marked
    public.
    N)rÚwalkr)Útreerrrr    Úget_public_methods:srcCsŠg}|jjD]}| |j¡q |jjr:| d|jjj¡|jjD]}| |jd|j¡qB|jjrz| d|jjj¡d d |¡¡S)aGiven a function definition, create a string that represents taking all
    the arguments from the function, and passing them through to another
    invocation of the same function.
 
    Example input: ast.parse("def f(a, *, b): ...")
    Example output: "(a, b=b)"
    Ú*ú=z**z({})z, )ÚargsÚappendÚargÚvarargÚ
kwonlyargsÚkwargÚformatÚjoin)ZfuncdefZ    call_argsrrrr    Úcreate_passthrough_argsEs  r)Ú source_pathÚ lookup_pathÚreturnc    CsÔtg}tj |¡}t|ƒD]¤}|jjdjdks4t‚|jjd=g|_t    |ƒ}t
  |¡dkrh|j dd…=n |j dd…=tj |dd}t t|t
jƒr–dnd||j|¡}|t|dƒ}| |¡q| t¡d     |¡S)
zZScan the given .py file for @_public decorators, and generate wrapper
    functions.
 
    rÚselfNéz    )Z indent_withz await ú z
 
)ÚHEADERÚastorZ code_to_astZ
parse_filerrrÚAssertionErrorr rrZ get_docstringÚbodyZ    to_sourceÚTEMPLATErrrÚnamerrÚFOOTERr)    rrÚ    generatedÚsourceÚmethodÚnew_argsÚfuncÚtemplateZsnippetrrr    Úgen_public_wrappers_sourceYs(  
 ý 
r1c
CsX| ¡D]J\}}tj |¡s"dSt|ddd}| ¡}W5QRX||krdSqdS)NFÚrúutf-8©ÚencodingT)ÚitemsÚosÚpathÚexistsÚopenÚread)Ú    new_filesÚnew_pathÚ
new_sourceZold_fileZ
old_sourcerrr    Úmatches_disk_files…s r?c
 
Cs¼i}|D]F\}}td|ƒt||ƒ}tj |¡\}}tj |t|¡}|||<q|rzt|ƒsptdƒt     d¡q¸tdƒn>| 
¡D],\}}t |ddd}    |      |¡W5QRXq‚tdƒdS)    Nz    Scanning:z2Generated sources are outdated. Please regenerate.r"z!Generated sources are up to date.Úwr3r4z!Regenerated sources successfully.) Úprintr1r7r8ÚsplitrÚPREFIXr?ÚsysÚexitr6r:Úwrite)
Zsources_and_lookupsÚdo_testr<rrr>ÚdirnameÚbasenamer=Úfrrr    Úprocesss  
 
 
 
rKcCsŽtjdd}|jddddd| ¡}t ¡}|d ¡s>t‚|d    }|d
d f|d d f|ddf|ddf|ddfg}t||j    ddS)Nz,Generate python code for public api wrappers)Ú descriptionz--testz-tÚ
store_truez test if code is still up to date)ÚactionÚhelpÚLICENSEz
trio/_corez_run.pyÚrunnerz_instrumentation.pyzrunner.instrumentsz_io_windows.pyzrunner.io_managerz _io_epoll.pyz _io_kqueue.py)rG)
ÚargparseÚArgumentParserÚ add_argumentÚ
parse_argsrÚcwdr9r&rKÚtest)ÚparserZ parsed_argsZ source_rootÚcoreZto_wraprrr    Úmain§s(ÿÿ
 
 
 
 
ûrZÚ__main__)Ú__doc__rRrr%r7ÚpathlibrrDÚtextwraprrCr$r*r(r
rrrÚstrr1r?rKrZÚ__name__rrrr    Ú<module>s*  
    
 ,