U ã€C^[ã@sdZddlmZmZmZddgZddlZddlZddlZe  dej ¡Z e  dej ¡Z e  dej ¡Z d d „Ze  d ¡Ze  d ¡Ze  d ¡Zdd„Zdd„Ze  d¡Zdd„Zdd„Ze  d¡Zdd„Zdd„Ze  dej ¡Zdd„Zdd„ZedƒZd d!„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: where anywhere inside a block '

' 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: , a short form of the named, useful when no

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 '\' then it will be replaced by -th expression. Note that all '<..>' forms in a block must have the same number of comma-separated entries. Predefined named template rules: é)ÚdivisionÚabsolute_importÚprint_functionÚ process_strÚ process_fileNz2(\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ú@/tmp/pip-install-6_kvzl1k/numpy/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_patterns[s  r)cCs"t|ƒ}t td|¡d}||fS)NÚr)r)ÚreÚsubnr)rr$rrrÚfind_and_remove_repl_patternsesr-z\A\\(?P\d+)\ZcCs`| d¡}dd„|Dƒ}tt|ƒƒD]0}t ||¡}|r$t| d¡ƒ}||||<q$d |¡S)Nú,cSsg|] }| ¡‘qSr)r )Ú.0ÚxrrrÚ mszconv..Úindex)ÚsplitÚrangerÚitem_rerÚintÚgroupÚjoin)rÚbÚlrrÚjrrrr#ks r#cCs<t| ¡ƒ}d}d}|s8d|}||kr2|d7}qd}q|S)z( Obtain a unique key given a dictionary.Fr z__l%sT)ÚlistÚkeys)ÚadictZallkeysÚdoneÚnZnewkeyrrrr!us  r!z\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\csjt| d¡ dd¡ƒ}t |¡r(d|Sd}ˆ ¡D]}ˆ||kr4|}q4|dkrbtˆƒ}|ˆ|<d|S)Nr rrz<%s>)r#r7r"Útemplate_name_rerr=r!)Úmobjr(r&Úkey)ÚlnamesrrÚlistreplŠs   zexpand_sub..listreplzNo replicates found for <%s>Ú_cSsg|]}| dd¡‘qS)rr.)r")r/rrrrr1¤szexpand_sub..r.zHMismatch in number of replacements (base <%s=%s>) for <%s=%s>. Ignoring.cs$| d¡}ˆ |ˆd|g¡ˆS)Nr )r7Úget)rBr&)ÚkÚrulesrrÚnamerepl´s zexpand_sub..namereplr*z ú>ú<)r"r)rÚsubÚlist_reÚ template_rerrGÚ ValueErrorÚ startswithr3rÚprintr8r4) Úsubstrr$rEZnumsubsZ base_ruleÚrr(ZruleÚnumrJÚnewstrr)rHrDrIrÚ expand_sub„sH      þ   rWc 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-rW) ÚallstrrVÚwritestrÚstructZoldendr$rMZ cleanedstrZdefsrrrrÀs   z9(\n|\A)\s*include\s*['\"](?P[\w\d./\\]+[.]src)['\"]c Cs tj |¡}t|ƒ‚}g}|D]r}t |¡}|r†| d¡}tj |¡sTtj ||¡}tj  |¡rzt d|ƒ|  t |ƒ¡q|  |¡q|  |¡qW5QRX|S)Nr&zIncluding file)ÚosÚpathÚdirnameÚopenÚinclude_src_rerr7Úisabsr8ÚisfilerRÚextendÚresolve_includesr)ÚsourceÚdÚfidÚlinesÚlinerÚfnrrrreÕs        recCst|ƒ}td |¡ƒS)Nr*)rerr8)rfrirrrrèszÿ <_c=s,d,c,z> <_t=real,double precision,complex,double complex> cCsvztjd}Wn tk r.tj}tj}Yn*Xt|dƒ}tj |¡\}}|}t|dƒ}|  ¡}t |ƒ}|  |¡dS)Nr rTÚw) ÚsysÚargvÚ IndexErrorÚstdinÚstdoutr`r]r^ÚsplitextÚreadrÚwrite)ÚfilerhÚoutfileÚbaseÚextZnewnamerZr[rrrÚmainös   ryÚ__main__) Ú__doc__Ú __future__rrrÚ__all__r]rmr+ÚcompileÚIr rrrrOrrNr)r-r5r#r!rArWrrarerrYryÚ__name__rrrrÚs6.       <