1- #!/usr/bin/env python3
1+ #!/usr/bin/env python2.7
2+ # WARNING! This a Python 2 script. Read README.rst for rationale.
23"""
34Usage: make_lite.py <wrapped_routines_file> <lapack_dir>
45
2021import fortran
2122import clapack_scrub
2223
23- from shutil import which
24+ try :
25+ from distutils .spawn import find_executable as which # Python 2
26+ except ImportError :
27+ from shutil import which # Python 3
2428
2529# Arguments to pass to f2c. You'll always want -A for ANSI C prototypes
2630# Others of interest: -a to not make variables static by default
@@ -81,7 +85,8 @@ def dependencies(self):
8185 return self ._dependencies
8286
8387 def __repr__ (self ):
84- return f'FortranRoutine({ self .name !r} , filename={ self .filename !r} )'
88+ return "FortranRoutine({!r}, filename={!r})" .format (self .name ,
89+ self .filename )
8590
8691class UnknownFortranRoutine (FortranRoutine ):
8792 """Wrapper for a Fortran routine for which the corresponding file
@@ -193,7 +198,7 @@ def allRoutinesByType(self, typename):
193198def printRoutineNames (desc , routines ):
194199 print (desc )
195200 for r in routines :
196- print (f '\t { r .name } ' )
201+ print ('\t %s' % r .name )
197202
198203def getLapackRoutines (wrapped_routines , ignores , lapack_dir ):
199204 blas_src_dir = os .path .join (lapack_dir , 'BLAS' , 'SRC' )
@@ -243,7 +248,7 @@ def dumpRoutineNames(library, output_dir):
243248 with open (filename , 'w' ) as fo :
244249 for r in routines :
245250 deps = r .dependencies ()
246- fo .write (f" { r .name } : { ' ' .join (deps )} \n " )
251+ fo .write ('%s: %s \n ' % ( r .name , ' ' .join (deps )) )
247252
248253def concatenateRoutines (routines , output_file ):
249254 with open (output_file , 'w' ) as output_fo :
@@ -261,8 +266,8 @@ def runF2C(fortran_filename, output_dir):
261266 subprocess .check_call (
262267 ["f2c" ] + F2C_ARGS + ['-d' , output_dir , fortran_filename ]
263268 )
264- except subprocess .CalledProcessError as e :
265- raise F2CError from e
269+ except subprocess .CalledProcessError :
270+ raise F2CError
266271
267272def scrubF2CSource (c_file ):
268273 with open (c_file ) as fo :
@@ -275,8 +280,8 @@ def scrubF2CSource(c_file):
275280def ensure_executable (name ):
276281 try :
277282 which (name )
278- except Exception as ex :
279- raise SystemExit (name + ' not found' ) from ex
283+ except Exception :
284+ raise SystemExit (name + ' not found' )
280285
281286def create_name_header (output_dir ):
282287 routine_re = re .compile (r'^ (subroutine|.* function)\s+(\w+)\(.*$' ,
@@ -316,13 +321,13 @@ def create_name_header(output_dir):
316321
317322 # Rename BLAS/LAPACK symbols
318323 for name in sorted (symbols ):
319- f .write (f' #define { name } _ BLAS_FUNC({ name } )\n ' )
324+ f .write (" #define %s_ BLAS_FUNC(%s )\n " % ( name , name ) )
320325
321326 # Rename also symbols that f2c exports itself
322327 f .write ("\n "
323328 "/* Symbols exported by f2c.c */\n " )
324329 for name in sorted (f2c_symbols ):
325- f .write (f' #define { name } numpy_lapack_lite_{ name } \n ' )
330+ f .write (" #define %s numpy_lapack_lite_%s \n " % ( name , name ) )
326331
327332def main ():
328333 if len (sys .argv ) != 3 :
@@ -348,21 +353,21 @@ def main():
348353 dumpRoutineNames (library , output_dir )
349354
350355 for typename in types :
351- fortran_file = os .path .join (output_dir , f 'f2c_{ typename } .f' )
356+ fortran_file = os .path .join (output_dir , 'f2c_%s .f' % typename )
352357 c_file = fortran_file [:- 2 ] + '.c'
353- print (f 'creating { c_file } ...' )
358+ print ('creating %s ...' % c_file )
354359 routines = library .allRoutinesByType (typename )
355360 concatenateRoutines (routines , fortran_file )
356361
357362 # apply the patchpatch
358363 patch_file = os .path .basename (fortran_file ) + '.patch'
359364 if os .path .exists (patch_file ):
360365 subprocess .check_call (['patch' , '-u' , fortran_file , patch_file ])
361- print (f' Patched { fortran_file } ' )
366+ print (" Patched {}" . format ( fortran_file ) )
362367 try :
363368 runF2C (fortran_file , output_dir )
364369 except F2CError :
365- print (f 'f2c failed on { fortran_file } ' )
370+ print ('f2c failed on %s' % fortran_file )
366371 break
367372 scrubF2CSource (c_file )
368373
0 commit comments