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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
U
O±dîã@sødZddgZddlZddlZddlZe dej¡Ze dej¡Ze dej¡Z    dd    „Z
e d
¡Z e d ¡Z e d ¡Z d d„Zdd„Ze d¡Zdd„Zdd„Ze d¡Zdd„Zdd„Ze dej¡Zdd„Zdd„ZedƒZdd „Zed!krôeƒdS)"aÆ
 
process_file(filename)
 
  takes templated file .xxx.src and produces .xxx file where .xxx
  is .pyf .f90 or .f using the following template rules:
 
  '<..>' denotes a template.
 
  All function and subroutine blocks in a source file with names that
  contain '<..>' will be replicated according to the rules in '<..>'.
 
  The number of comma-separated words in '<..>' will determine the number of
  replicates.
 
  '<..>' may have two different forms, named and short. For example,
 
  named:
   <p=d,s,z,c> where anywhere inside a block '<p>' will be replaced with
   'd', 's', 'z', and 'c' for each replicate of the block.
 
   <_c>  is already defined: <_c=s,d,c,z>
   <_t>  is already defined: <_t=real,double precision,complex,double complex>
 
  short:
   <s,d,c,z>, a short form of the named, useful when no <p> appears inside
   a block.
 
  In general, '<..>' contains a comma separated list of arbitrary
  expressions. If these expression must contain a comma|leftarrow|rightarrow,
  then prepend the comma|leftarrow|rightarrow with a backslash.
 
  If an expression matches '\<index>' then it will be replaced
  by <index>-th expression.
 
  Note that all '<..>' forms in a block must have the same number of
  comma-separated entries.
 
 Predefined named template rules:
  <prefix=s,d,c,z>
  <ftype=real,double precision,complex,double complex>
  <ftypereal=real,double precision,\0,\1>
  <ctype=float,double,complex_float,complex_double>
  <ctypereal=float,double,\0,\1>
 
Ú process_strÚ process_fileéNz2(\n|\A)((     (\$|\*))|)\s*(subroutine|function)\bz+\n\s*end\s*(subroutine|function)\b.*(\n|\Z)z\n     (\$|\*)\s*function\bcCs´g}d}t ||¡}|dkrq°| ¡}t ||| ¡¡rl| d||¡}|dkrPql|}|||d…dkr8qlq8|d7}t || ¡¡}|r”| ¡dpšt|ƒ}}|     ||f¡q|S)z‘ Return a list of tuples for each function or subroutine each
    tuple is the start and end of a subroutine or function to be
    expanded.
    rNÚ
éÿÿÿÿéz
     $é)
Úroutine_start_reÚsearchÚstartÚfunction_start_reÚmatchÚendÚrfindÚroutine_end_reÚlenÚappend)ÚastrZspanlistÚindÚmr
Úir ©rúTd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/distutils/from_template.pyÚparse_structure:s$ rz<\s*(\w[\w\d]*)\s*>z<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>z<\s*((.*?))\s*>cCsPt |¡}i}|D]8}|d ¡p(t|ƒ}|d dd¡}t|ƒ}|||<q|S)Nrrú\,ú@comma@)Únamed_reÚfindallÚstripÚ
unique_keyÚreplaceÚconv)rZrepsÚnamesÚrepÚnameÚreplÚthelistrrrÚfind_repl_patternsYs
 
r&cCs"t|ƒ}t td|¡d}||fS)NÚr)r&ÚreÚsubnr)rr!rrrÚfind_and_remove_repl_patternscsr*z\A\\(?P<index>\d+)\ZcCs`| d¡}dd„|Dƒ}tt|ƒƒD]0}t ||¡}|r$t| d¡ƒ}||||<q$d |¡S)Nú,cSsg|] }| ¡‘qSr)r)Ú.0ÚxrrrÚ
<listcomp>kszconv.<locals>.<listcomp>Úindex)ÚsplitÚrangerÚitem_rer ÚintÚgroupÚjoin)rÚbÚlrrÚjrrrr is
r cCs<t| ¡ƒ}d}d}|s8d|}||kr2|d7}qd}q|S)z( Obtain a unique key given a dictionary.Frz__l%sT)ÚlistÚkeys)ÚadictZallkeysÚdoneÚnZnewkeyrrrrss 
rz\A\s*(\w[\w\d]*)\s*\Zc sl| dd¡}| dd¡}t|ƒ‰t d|¡}‡fdd„}t ||¡}d}d}i‰t |¡D]´}|ˆkrZˆ || |d¡¡}|dkrŽtd|ƒ‚||kr¨|     d    ¡s¨|||<d
d „| 
d ¡Dƒ}t |ƒ}|dkrÞ|}|ˆ|<|}qZ||krð|ˆ|<qZt d |d   ˆ|¡||fƒqZˆs|S‡‡fdd„}    d}
t|ƒD]‰|
t |    |¡d7}
q4|
 dd¡}
|
 dd¡}
|
S)Nz\>z @rightarrow@z\<z @leftarrow@z<\1>csjt| d¡ dd¡ƒ}t |¡r(d|Sd}ˆ ¡D]}ˆ||kr4|}q4|dkrbtˆƒ}|ˆ|<d|S)Nrrrz<%s>)r r4rÚtemplate_name_rer r:r)Úmobjr%r#Úkey)ÚlnamesrrÚlistreplˆs
  zexpand_sub.<locals>.listreplzNo replicates found for <%s>Ú_cSsg|]}| dd¡‘qS)rr+)r)r,rrrrr.¢szexpand_sub.<locals>.<listcomp>r+zHMismatch in number of replacements (base <%s=%s>) for <%s=%s>. Ignoring.cs$| d¡}ˆ |ˆd|g¡ˆS)Nr)r4Úget)r?r#)ÚkÚrulesrrÚnamerepl²s
zexpand_sub.<locals>.namereplr'z
 
ú>ú<)rr&rÚsubÚlist_reÚ template_rerrDÚ
ValueErrorÚ
startswithr0rÚprintr5r1) Úsubstrr!rBZnumsubsZ    base_ruleÚrr%ZruleÚnumrGÚnewstrr)rErArFrÚ
expand_sub‚sH     
þ   rTc    Cs|}d}t|ƒ}d}i}| t¡|D]T}t|||d…ƒ\}}||7}| |¡|t||d|d…|ƒ7}|d}q&|||d…7}|S)Nr'rr)rÚupdateÚ_special_namesr*rT)    ÚallstrrSÚwritestrÚstructZoldendr!rJZ
cleanedstrZdefsrrrr¾s
 
 
z8(\n|\A)\s*include\s*['\"](?P<name>[\w\d./\\]+\.src)['\"]c    Cs–tj |¡}t|ƒx}g}|D]h}t |¡}|r|| d¡}tj |¡sTtj ||¡}tj     |¡rp| 
t |ƒ¡q†|  |¡q|  |¡qW5QRX|S)Nr#) ÚosÚpathÚdirnameÚopenÚinclude_src_rer r4Úisabsr5ÚisfileÚextendÚresolve_includesr)ÚsourceÚdÚfidÚlinesÚlinerÚfnrrrrbÓs 
 
 
   rbcCst|ƒ}td |¡ƒS)Nr')rbrr5)rcrfrrrråszÿ
<_c=s,d,c,z>
<_t=real,double precision,complex,double complex>
<prefix=s,d,c,z>
<ftype=real,double precision,complex,double complex>
<ctype=float,double,complex_float,complex_double>
<ftypereal=real,double precision,\0,\1>
<ctypereal=float,double,\0,\1>
cCsvztjd}Wn tk
r.tj}tj}Yn*Xt|dƒ}tj |¡\}}|}t|dƒ}|     ¡}t
|ƒ}|  |¡dS)NrrQÚw) ÚsysÚargvÚ
IndexErrorÚstdinÚstdoutr]rZr[ÚsplitextÚreadrÚwrite)ÚfilereÚoutfileÚbaseÚextZnewnamerWrXrrrÚmainós 
 
rvÚ__main__)Ú__doc__Ú__all__rZrjr(ÚcompileÚIrrr rrLrrKr&r*r2r rr>rTrr^rbrrVrvÚ__name__rrrrÚ<module>s4.
 
 
 
 
 
 
<