Skip to content

Commit

Permalink
BUG: fix broken numpy.distutils Fortran handling
Browse files Browse the repository at this point in the history
The `Path` and `COMMON_FIXED_EXTENSIONS` variables were not
defined at all. This code is untested, and SciPy doesn't build
with NumPy `main` before this fix. The issue was introduced
a few days ago in gh-22885.
  • Loading branch information
rgommers committed Jan 22, 2023
1 parent 6ff22e2 commit 5437558
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions numpy/distutils/ccompiler.py
Expand Up @@ -5,6 +5,7 @@
import time
import subprocess
from copy import copy
from pathlib import Path
from distutils import ccompiler
from distutils.ccompiler import (
compiler_class, gen_lib_options, get_default_compiler, new_compiler,
Expand Down Expand Up @@ -279,7 +280,8 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None,

if not sources:
return []
from numpy.distutils.fcompiler import (FCompiler, is_f_file,
from numpy.distutils.fcompiler import (FCompiler,
FORTRAN_COMMON_FIXED_EXTENSIONS,
has_f90_header)
if isinstance(self, FCompiler):
display = []
Expand Down Expand Up @@ -338,7 +340,7 @@ def single_compile(args):
if self.compiler_type=='absoft':
obj = cyg2win32(obj)
src = cyg2win32(src)
if Path(src).suffix.lower() in COMMON_FIXED_EXTENSIONS \
if Path(src).suffix.lower() in FORTRAN_COMMON_FIXED_EXTENSIONS \
and not has_f90_header(src):
f77_objects.append((obj, (src, ext)))
else:
Expand Down
8 changes: 6 additions & 2 deletions numpy/distutils/fcompiler/__init__.py
Expand Up @@ -19,6 +19,7 @@
import os
import sys
import re
from pathlib import Path

from distutils.sysconfig import get_python_lib
from distutils.fancy_getopt import FancyGetopt
Expand All @@ -37,6 +38,10 @@

__metaclass__ = type


FORTRAN_COMMON_FIXED_EXTENSIONS = ['.for', '.ftn', '.f77', '.f']


class CompilerNotFound(Exception):
pass

Expand Down Expand Up @@ -571,7 +576,7 @@ def dump_properties(self):
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 \
if Path(src).suffix.lower() in FORTRAN_COMMON_FIXED_EXTENSIONS \
and not has_f90_header(src):
flavor = ':f77'
compiler = self.compiler_f77
Expand Down Expand Up @@ -971,7 +976,6 @@ def dummy_fortran_file():
return name[:-2]


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
Expand Down

0 comments on commit 5437558

Please sign in to comment.