[Numpy-svn] r8278 - in trunk/numpy/f2py: . tests

numpy-svn@scip... numpy-svn@scip...
Sat Mar 6 13:39:09 CST 2010


Author: ptvirtan
Date: 2010-03-06 13:39:09 -0600 (Sat, 06 Mar 2010)
New Revision: 8278

Modified:
   trunk/numpy/f2py/auxfuncs.py
   trunk/numpy/f2py/cb_rules.py
   trunk/numpy/f2py/cfuncs.py
   trunk/numpy/f2py/f2py2e.py
   trunk/numpy/f2py/tests/util.py
Log:
3K: f2py: make f2py run far enough to produce output files (they don't compile yet, though, as the C code is not Py3 compatible)

Modified: trunk/numpy/f2py/auxfuncs.py
===================================================================
--- trunk/numpy/f2py/auxfuncs.py	2010-03-06 19:14:47 UTC (rev 8277)
+++ trunk/numpy/f2py/auxfuncs.py	2010-03-06 19:39:09 UTC (rev 8278)
@@ -590,22 +590,22 @@
     if s and s[-1]==',': return s[:-1]
     return s
 
-def replace(str,dict,defaultsep=''):
-    if type(dict)==types.ListType:
-        return map(lambda d,f=replace,sep=defaultsep,s=str:f(s,d,sep),dict)
+def replace(str,d,defaultsep=''):
+    if type(d)==types.ListType:
+        return map(lambda d,f=replace,sep=defaultsep,s=str:f(s,d,sep),d)
     if type(str)==types.ListType:
-        return map(lambda s,f=replace,sep=defaultsep,d=dict:f(s,d,sep),str)
-    for k in 2*dict.keys():
+        return map(lambda s,f=replace,sep=defaultsep,d=d:f(s,d,sep),str)
+    for k in 2*d.keys():
         if k=='separatorsfor':
             continue
-        if 'separatorsfor' in dict and k in dict['separatorsfor']:
-            sep=dict['separatorsfor'][k]
+        if 'separatorsfor' in d and k in d['separatorsfor']:
+            sep=d['separatorsfor'][k]
         else:
             sep=defaultsep
-        if type(dict[k])==types.ListType:
-            str=str.replace('#%s#'%(k),sep.join(flatlist(dict[k])))
+        if type(d[k])==types.ListType:
+            str=str.replace('#%s#'%(k),sep.join(flatlist(d[k])))
         else:
-            str=str.replace('#%s#'%(k),dict[k])
+            str=str.replace('#%s#'%(k),d[k])
     return str
 
 def dictappend(rd,ar):
@@ -617,7 +617,7 @@
         if k[0]=='_':
             continue
         if k in rd:
-            if type(rd[k])==types.StringType:
+            if type(rd[k])==str:
                 rd[k]=[rd[k]]
             if type(rd[k])==types.ListType:
                 if type(ar[k])==types.ListType:
@@ -636,11 +636,11 @@
             rd[k]=ar[k]
     return rd
 
-def applyrules(rules,dict,var={}):
+def applyrules(rules,d,var={}):
     ret={}
     if type(rules)==types.ListType:
         for r in rules:
-            rr=applyrules(r,dict,var)
+            rr=applyrules(r,d,var)
             ret=dictappend(ret,rr)
             if '_break' in rr:
                 break
@@ -648,19 +648,19 @@
     if '_check' in rules and (not rules['_check'](var)):
         return ret
     if 'need' in rules:
-        res = applyrules({'needs':rules['need']},dict,var)
+        res = applyrules({'needs':rules['need']},d,var)
         if 'needs' in res:
             cfuncs.append_needs(res['needs'])
 
     for k in rules.keys():
         if k=='separatorsfor':
             ret[k]=rules[k]; continue
-        if type(rules[k])==types.StringType:
-            ret[k]=replace(rules[k],dict)
+        if type(rules[k])==str:
+            ret[k]=replace(rules[k],d)
         elif type(rules[k])==types.ListType:
             ret[k]=[]
             for i in rules[k]:
-                ar=applyrules({k:i},dict,var)
+                ar=applyrules({k:i},d,var)
                 if k in ar:
                     ret[k].append(ar[k])
         elif k[0]=='_':
@@ -672,19 +672,19 @@
                     if type(rules[k][k1])==types.ListType:
                         for i in rules[k][k1]:
                             if type(i)==types.DictType:
-                                res=applyrules({'supertext':i},dict,var)
+                                res=applyrules({'supertext':i},d,var)
                                 if 'supertext' in res:
                                     i=res['supertext']
                                 else: i=''
-                            ret[k].append(replace(i,dict))
+                            ret[k].append(replace(i,d))
                     else:
                         i=rules[k][k1]
                         if type(i)==types.DictType:
-                            res=applyrules({'supertext':i},dict)
+                            res=applyrules({'supertext':i},d)
                             if 'supertext' in res:
                                 i=res['supertext']
                             else: i=''
-                        ret[k].append(replace(i,dict))
+                        ret[k].append(replace(i,d))
         else:
             errmess('applyrules: ignoring rule %s.\n'%`rules[k]`)
         if type(ret[k])==types.ListType:

Modified: trunk/numpy/f2py/cb_rules.py
===================================================================
--- trunk/numpy/f2py/cb_rules.py	2010-03-06 19:14:47 UTC (rev 8277)
+++ trunk/numpy/f2py/cb_rules.py	2010-03-06 19:39:09 UTC (rev 8278)
@@ -515,7 +515,7 @@
 
     ar=applyrules(cb_routine_rules,rd)
     cfuncs.callbacks[rd['name']]=ar['body']
-    if type(ar['need'])==types.StringType:
+    if type(ar['need'])==str:
         ar['need']=[ar['need']]
 
     if 'need' in rd:

Modified: trunk/numpy/f2py/cfuncs.py
===================================================================
--- trunk/numpy/f2py/cfuncs.py	2010-03-06 19:14:47 UTC (rev 8277)
+++ trunk/numpy/f2py/cfuncs.py	2010-03-06 19:39:09 UTC (rev 8278)
@@ -1075,7 +1075,7 @@
     if type(need)==types.ListType:
         for n in need:
             append_needs(n,flag)
-    elif type(need)==types.StringType:
+    elif type(need)==str:
         if not need: return
         if need in includes0:
             n = 'includes0'

Modified: trunk/numpy/f2py/f2py2e.py
===================================================================
--- trunk/numpy/f2py/f2py2e.py	2010-03-06 19:14:47 UTC (rev 8277)
+++ trunk/numpy/f2py/f2py2e.py	2010-03-06 19:39:09 UTC (rev 8278)
@@ -285,21 +285,21 @@
             f.close()
     return postlist
 
-def buildmodules(list):
+def buildmodules(lst):
     cfuncs.buildcfuncs()
     outmess('Building modules...\n')
     modules,mnames,isusedby=[],[],{}
-    for i in range(len(list)):
-        if '__user__' in list[i]['name']:
-            cb_rules.buildcallbacks(list[i])
+    for i in range(len(lst)):
+        if '__user__' in lst[i]['name']:
+            cb_rules.buildcallbacks(lst[i])
         else:
-            if 'use' in list[i]:
-                for u in list[i]['use'].keys():
+            if 'use' in lst[i]:
+                for u in lst[i]['use'].keys():
                     if u not in isusedby:
                         isusedby[u]=[]
-                    isusedby[u].append(list[i]['name'])
-            modules.append(list[i])
-            mnames.append(list[i]['name'])
+                    isusedby[u].append(lst[i]['name'])
+            modules.append(lst[i])
+            mnames.append(lst[i]['name'])
     ret = {}
     for i in range(len(mnames)):
         if mnames[i] in isusedby:
@@ -329,7 +329,11 @@
     """Run f2py as if string.join(comline_list,' ') is used as a command line.
     In case of using -h flag, return None.
     """
-    reload(crackfortran)
+    if sys.version_info[0] >= 3:
+        import imp
+        imp.reload(crackfortran)
+    else:
+        reload(crackfortran)
     f2pydir=os.path.dirname(os.path.abspath(cfuncs.__file__))
     fobjhsrc = os.path.join(f2pydir,'src','fortranobject.h')
     fobjcsrc = os.path.join(f2pydir,'src','fortranobject.c')

Modified: trunk/numpy/f2py/tests/util.py
===================================================================
--- trunk/numpy/f2py/tests/util.py	2010-03-06 19:14:47 UTC (rev 8277)
+++ trunk/numpy/f2py/tests/util.py	2010-03-06 19:39:09 UTC (rev 8278)
@@ -18,7 +18,7 @@
 
 import nose
 
-from numpy.compat import asbytes
+from numpy.compat import asbytes, asstr
 import numpy.f2py
 
 try:
@@ -125,7 +125,7 @@
         out, err = p.communicate()
         if p.returncode != 0:
             raise RuntimeError("Running f2py failed: %s\n%s"
-                               % (cmd[4:], out))
+                               % (cmd[4:], asstr(out)))
     finally:
         os.chdir(cwd)
 
@@ -203,7 +203,7 @@
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
         out, err = p.communicate()
-        m = re.search(r'COMPILERS:(\d+),(\d+),(\d+)', out)
+        m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
         if m:
             _compiler_status = (bool(m.group(1)), bool(m.group(2)),
                                 bool(m.group(3)))
@@ -281,7 +281,7 @@
         out, err = p.communicate()
         if p.returncode != 0:
             raise RuntimeError("Running distutils build failed: %s\n%s"
-                               % (cmd[4:], out))
+                               % (cmd[4:], asstr(out)))
     finally:
         os.chdir(cwd)
 



More information about the Numpy-svn mailing list