<s> import re <EOL> import sys <EOL> import os <EOL> import glob <EOL> from distutils . dep_util import newer <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> def uses_veclib ( info ) : <EOL> if sys . platform != "<STR_LIT>" : <EOL> return False <EOL> r_accelerate = re . compile ( "<STR_LIT>" ) <EOL> extra_link_args = info . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for arg in extra_link_args : <EOL> if r_accelerate . search ( arg ) : <EOL> return True <EOL> return False <EOL> def uses_accelerate ( info ) : <EOL> if sys . platform != "<STR_LIT>" : <EOL> return False <EOL> r_accelerate = re . compile ( "<STR_LIT>" ) <EOL> extra_link_args = info . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for arg in extra_link_args : <EOL> if r_accelerate . search ( arg ) : <EOL> return True <EOL> return False <EOL> def uses_mkl ( info ) : <EOL> r_mkl = re . compile ( "<STR_LIT>" ) <EOL> libraries = info . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for library in libraries : <EOL> if r_mkl . search ( library ) : <EOL> return True <EOL> return False <EOL> def needs_g77_abi_wrapper ( info ) : <EOL> """<STR_LIT>""" <EOL> if uses_accelerate ( info ) or uses_veclib ( info ) : <EOL> return True <EOL> elif uses_mkl ( info ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def get_g77_abi_wrappers ( info ) : <EOL> """<STR_LIT>""" <EOL> wrapper_sources = [ ] <EOL> path = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> if needs_g77_abi_wrapper ( info ) : <EOL> wrapper_sources += [ <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> ] <EOL> if uses_accelerate ( info ) : <EOL> wrapper_sources += [ <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> ] <EOL> elif uses_mkl ( info ) : <EOL> wrapper_sources += [ <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> ] <EOL> else : <EOL> raise NotImplementedError ( "<STR_LIT>" % ( info , ) ) <EOL> else : <EOL> wrapper_sources += [ <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) , <EOL> ] <EOL> return wrapper_sources <EOL> def needs_sgemv_fix ( info ) : <EOL> """<STR_LIT>""" <EOL> if uses_accelerate ( info ) : <EOL> return True <EOL> else : <EOL> return False <EOL> def get_sgemv_fix ( info ) : <EOL> """<STR_LIT>""" <EOL> path = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> if needs_sgemv_fix ( info ) : <EOL> return [ os . path . join ( path , '<STR_LIT:src>' , '<STR_LIT>' ) ] <EOL> else : <EOL> return [ ] <EOL> def split_fortran_files ( source_dir , subroutines = None ) : <EOL> """<STR_LIT>""" <EOL> if subroutines is not None : <EOL> subroutines = [ x . lower ( ) for x in subroutines ] <EOL> def split_file ( fname ) : <EOL> with open ( fname , '<STR_LIT:rb>' ) as f : <EOL> lines = f . readlines ( ) <EOL> subs = [ ] <EOL> need_split_next = True <EOL> for ix , line in enumerate ( lines ) : <EOL> m = re . match ( b'<STR_LIT>' , line , re . I ) <EOL> if m and line [ <NUM_LIT:0> ] not in b'<STR_LIT>' : <EOL> if subroutines is not None : <EOL> subr_name = m . group ( <NUM_LIT:1> ) . decode ( '<STR_LIT:ascii>' ) . lower ( ) <EOL> subr_wanted = ( subr_name in subroutines ) <EOL> else : <EOL> subr_wanted = True <EOL> if subr_wanted or need_split_next : <EOL> need_split_next = subr_wanted <EOL> subs . append ( ix ) <EOL> if len ( subs ) <= <NUM_LIT:1> : <EOL> return [ fname ] <EOL> new_fnames = [ ] <EOL> num_files = len ( subs ) <EOL> for nfile in range ( num_files ) : <EOL> new_fname = fname [ : - <NUM_LIT:2> ] + '<STR_LIT>' + str ( nfile ) + '<STR_LIT>' <EOL> new_fnames . append ( new_fname ) <EOL> if not newer ( fname , new_fname ) : <EOL> continue <EOL> with open ( new_fname , '<STR_LIT:wb>' ) as fn : <EOL> if nfile + <NUM_LIT:1> == num_files : <EOL> fn . writelines ( lines [ subs [ nfile ] : ] ) <EOL> else : <EOL> fn . writelines ( lines [ subs [ nfile ] : subs [ nfile + <NUM_LIT:1> ] ] ) <EOL> return new_fnames <EOL> exclude_pattern = re . compile ( '<STR_LIT>' ) <EOL> source_fnames = [ f for f in glob . glob ( os . path . join ( source_dir , '<STR_LIT>' ) ) <EOL> if not exclude_pattern . search ( os . path . basename ( f ) ) ] <EOL> fnames = [ ] <EOL> for source_fname in source_fnames : <EOL> created_files = split_file ( source_fname ) <EOL> if created_files is not None : <EOL> for cfile in created_files : <EOL> fnames . append ( os . path . basename ( cfile ) ) <EOL> return fnames </s>
