diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/distutils/ccompiler.py | 3 | ||||
-rw-r--r-- | numpy/distutils/fcompiler/__init__.py | 3 | ||||
-rwxr-xr-x | numpy/f2py/crackfortran.py | 34 |
3 files changed, 21 insertions, 19 deletions
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py index 86201174d..f0487cb64 100644 --- a/numpy/distutils/ccompiler.py +++ b/numpy/distutils/ccompiler.py @@ -338,8 +338,7 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None, if self.compiler_type=='absoft': obj = cyg2win32(obj) src = cyg2win32(src) - if Path(src).suffix.lower() in COMMON_FIXED_EXTENSIONS \ - and not has_f90_header(src): + if is_f_file(src) and not has_f90_header(src): f77_objects.append((obj, (src, ext))) else: other_objects.append((obj, (src, ext))) diff --git a/numpy/distutils/fcompiler/__init__.py b/numpy/distutils/fcompiler/__init__.py index 793f0bccf..ecba3e5d5 100644 --- a/numpy/distutils/fcompiler/__init__.py +++ b/numpy/distutils/fcompiler/__init__.py @@ -571,8 +571,7 @@ class FCompiler(CCompiler): def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): """Compile 'src' to product 'obj'.""" src_flags = {} - if Path(src).suffix.lower() in COMMON_FIXED_EXTENSIONS \ - and not has_f90_header(src): + if is_f_file(src) and not has_f90_header(src): flavor = ':f77' compiler = self.compiler_f77 src_flags = get_f77flags(src) diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index b831697d8..84579fdcc 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -147,7 +147,6 @@ import os import copy import platform import codecs -from pathlib import Path try: import charset_normalizer except ImportError: @@ -290,15 +289,22 @@ def undo_rmbadname(names): return [undo_rmbadname1(_m) for _m in names] +def getextension(name): + i = name.rfind('.') + if i == -1: + return '' + if '\\' in name[i:]: + return '' + if '/' in name[i:]: + return '' + return name[i + 1:] + +is_f_file = re.compile(r'.*\.(for|ftn|f77|f)\Z', re.I).match _has_f_header = re.compile(r'-\*-\s*fortran\s*-\*-', re.I).search _has_f90_header = re.compile(r'-\*-\s*f90\s*-\*-', re.I).search _has_fix_header = re.compile(r'-\*-\s*fix\s*-\*-', re.I).search _free_f90_start = re.compile(r'[^c*]\s*[^\s\d\t]', re.I).match -# Extensions -COMMON_FREE_EXTENSIONS = ['.f90', '.f95', '.f03', '.f08'] -COMMON_FIXED_EXTENSIONS = ['.for', '.ftn', '.f77', '.f'] - def openhook(filename, mode): """Ensures that filename is opened with correct encoding parameter. @@ -331,28 +337,26 @@ def openhook(filename, mode): return open(filename, mode, encoding=encoding) -def is_free_format(fname): +def is_free_format(file): """Check if file is in free format Fortran.""" # f90 allows both fixed and free format, assuming fixed unless # signs of free format are detected. - result = False - if Path(fname).suffix.lower() in COMMON_FREE_EXTENSIONS: - result = True - with openhook(fname, 'r') as fhandle: - line = fhandle.readline() + result = 0 + with openhook(file, 'r') as f: + line = f.readline() n = 15 # the number of non-comment lines to scan for hints if _has_f_header(line): n = 0 elif _has_f90_header(line): n = 0 - result = True + result = 1 while n > 0 and line: if line[0] != '!' and line.strip(): n -= 1 if (line[0] != '\t' and _free_f90_start(line[:5])) or line[-2:-1] == '&': - result = True + result = 1 break - line = fhandle.readline() + line = f.readline() return result @@ -408,7 +412,7 @@ def readfortrancode(ffile, dowithline=show, istop=1): strictf77 = 0 sourcecodeform = 'fix' ext = os.path.splitext(currentfilename)[1] - if Path(currentfilename).suffix.lower() in COMMON_FIXED_EXTENSIONS and \ + if is_f_file(currentfilename) and \ not (_has_f90_header(l) or _has_fix_header(l)): strictf77 = 1 elif is_free_format(currentfilename) and not _has_fix_header(l): |