[Numpy-svn] r3487 - in branches/distutils-revamp: . command fcompiler

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Dec 14 08:57:16 CST 2006


Author: cookedm
Date: 2006-12-14 08:57:08 -0600 (Thu, 14 Dec 2006)
New Revision: 3487

Modified:
   branches/distutils-revamp/command/build_clib.py
   branches/distutils-revamp/command/build_ext.py
   branches/distutils-revamp/command/config.py
   branches/distutils-revamp/command/config_compiler.py
   branches/distutils-revamp/fcompiler/__init__.py
   branches/distutils-revamp/fcompiler/gnu.py
   branches/distutils-revamp/interactive.py
Log:
[distutils-rework] Fix up how the Fortran compiler is chosen and used.
config_fc sets up an object referencing the compiler, which the other commands
(build_clib, build_ext) use. This object keeps track of whether we need
an F90 compiler at any point.


Modified: branches/distutils-revamp/command/build_clib.py
===================================================================
--- branches/distutils-revamp/command/build_clib.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/command/build_clib.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -32,18 +32,17 @@
         self._languages = None
         self.set_undefined_options('config_fc',
                                    ('fcompiler', 'fcompiler'))
+        # we set this to the appropiate Fortran compiler object
+        # (f77 or f90) in the .run() method
+        self._fcompiler = None
 
-    def get_languages(self):
+    def languages(self):
         """Return a set of language names used in this library.
         Valid language names are 'c', 'f77', and 'f90'.
-
-        Note that this has a side effect of running 'build_src'.
         """
         if self._languages is None:
             languages = set()
             for (lib_name, build_info) in self.libraries:
-                if not all_strings(build_info.get('sources',[])):
-                    self.run_command('build_src')
                 l = build_info.get('language',None)
                 if l:
                     languages.add(l)
@@ -51,20 +50,22 @@
         return self._languages
 
     def have_f_sources(self):
-        l = self.get_languages()
+        l = self.languages()
         return 'f90' in l or 'f77' in l
 
     def have_cxx_sources(self):
-        l = self.get_languages()
-        return 'c' in l
+        l = self.languages()
+        return 'c++' in l
 
     def run(self):
         if not self.libraries:
             return
 
         # Make sure that library sources are complete.
-        languages = self.get_languages()
+        self.run_command('build_src')
 
+        languages = self.languages()
+
         from distutils.ccompiler import new_compiler
         self.compiler = new_compiler(compiler=self.compiler,
                                      dry_run=self.dry_run,
@@ -80,17 +81,17 @@
         self.compiler.show_customization()
 
         if self.have_f_sources():
-            cf = self.get_finalized_command('config_fc')
             if 'f90' in languages:
-                self.fcompiler = cf.get_f90_compiler()
+                fc = self.fcompiler.f90()
             else:
-                self.fcompiler = cf.get_f77_compiler()
+                fc = self.fcompiler.f77()
             libraries = self.libraries
             self.libraries = None
-            self.fcompiler.customize_cmd(self)
+            fc.customize_cmd(self)
             self.libraries = libraries
 
-            self.fcompiler.show_customization()
+            fc.show_customization()
+            self._fcompiler = fc
 
         self.build_libraries(self.libraries)
 
@@ -102,11 +103,10 @@
         return filenames
 
     def build_libraries(self, libraries):
+        fcompiler = self._fcompiler
+        compiler = self.compiler
 
         for (lib_name, build_info) in libraries:
-            # default compilers
-            compiler = self.compiler
-            fcompiler = self.fcompiler
 
             sources = build_info.get('sources')
             if sources is None or not is_sequence(sources):
@@ -132,13 +132,6 @@
                 log.info('using setup script specified config_fc '\
                          'for fortran compiler: %s' \
                          % (config_fc))
-                from numpy.distutils.fcompiler import new_fcompiler
-                requiref90 = build_info.get('language','c')=='f90'
-                fcompiler = new_fcompiler(compiler=self.fcompiler.compiler_type,
-                                          verbose=self.verbose,
-                                          dry_run=self.dry_run,
-                                          force=self.force,
-                                          requiref90=requiref90)
                 fcompiler.customize(config_fc)
 
             macros = build_info.get('macros')

Modified: branches/distutils-revamp/command/build_ext.py
===================================================================
--- branches/distutils-revamp/command/build_ext.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/command/build_ext.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -19,6 +19,9 @@
      get_numpy_include_dirs, is_sequence
 
 
+def ext_language(ext):
+    return getattr(ext, 'language', 'c')
+
 class build_ext (old_build_ext):
 
     description = "build C/C++/F extensions (compile/link to build directory)"
@@ -39,17 +42,54 @@
             self.include_dirs.extend(self.distribution.include_dirs or [])
         self.set_undefined_options('config_fc',
                                    ('fcompiler', 'fcompiler'))
+        self._fcompiler = None
 
+    def initialize_fcompiler(self, build_clib):
+        # Determine if Fortran compiler is needed.
+        requiref77 = requiref90 = False
+        if build_clib:
+            lang = build_clib.languages()
+            requiref77 = 'f77' in lang
+            requiref90 = 'f90' in lang
+        else:
+            for ext in self.extensions:
+                language = ext_language(ext)
+                if language == 'f77':
+                    requiref77 = True
+                elif language == 'f90':
+                    requiref90 = True
+                elif has_f_sources(ext.sources):
+                    # because we don't know any better, assume F77
+                    requiref77 = True
+
+        if not (requiref77 or requiref90):
+            return
+
+        if requiref90:
+            self.fcompiler.need_f90()
+        if requiref77:
+            self.fcompiler.need_f77()
+
+        fc = self.fcompiler.fortran(requiref90)
+        if fc.get_version():
+            fc.customize_cmd(self)
+            fc.show_customization()
+        else:
+            self.warn('fcompiler=%s is not available.' % (
+                fc.compiler_type,))
+        self._fcompiler = fc
+
     def run(self):
         if not self.extensions:
             return
 
         # Make sure that extension sources are complete.
         self.run_command('build_src')
-#        for ext in self.extensions:
-#            if not all_strings(ext.sources):
-#                 self.run_command('build_src')
 
+        # Not including C libraries to the list of
+        # extension libraries automatically to prevent
+        # bogus linking commands. Extensions must
+        # explicitly specify the C libraries that they use.
         if self.distribution.has_c_libraries():
             self.run_command('build_clib')
             build_clib = self.get_finalized_command('build_clib')
@@ -57,31 +97,6 @@
         else:
             build_clib = None
 
-        # Not including C libraries to the list of
-        # extension libraries automatically to prevent
-        # bogus linking commands. Extensions must
-        # explicitly specify the C libraries that they use.
-
-        # Determine if Fortran compiler is needed.
-        if build_clib and build_clib.fcompiler is not None:
-            need_f_compiler = True
-        else:
-            need_f_compiler = False
-            for ext in self.extensions:
-                if has_f_sources(ext.sources):
-                    need_f_compiler = True
-                    break
-                if getattr(ext,'language','c') in ['f77','f90']:
-                    need_f_compiler = True
-                    break
-
-        requiref90 = False
-        if need_f_compiler:
-            for ext in self.extensions:
-                if getattr(ext,'language','c')=='f90':
-                    requiref90 = True
-                    break
-
         # Determine if C++ compiler is needed.
         need_cxx_compiler = False
         for ext in self.extensions:
@@ -101,20 +116,7 @@
         self.compiler.customize_cmd(self)
         self.compiler.show_customization()
 
-        # Initialize Fortran/C++ compilers if needed.
-        if need_f_compiler:
-            cf = self.get_finalized_command('config_fc')
-            if requiref90:
-                self.fcompiler = cf.get_f90_compiler()
-            else:
-                self.fcompiler = cf.get_f77_compiler()
-            if self.fcompiler.get_version():
-                self.fcompiler.customize_cmd(self)
-                self.fcompiler.show_customization()
-            else:
-                self.warn('fcompiler=%s is not available.' % (
-                    self.fcompiler.compiler_type,))
-                self.fcompiler = None
+        self.initialize_fcompiler(build_clib)
 
         # Build extensions
         self.build_extensions()
@@ -123,6 +125,62 @@
         # Do nothing. Swig sources have beed handled in build_src command.
         return sources
 
+    def get_fortran_objects(self, ext, f_sources, fmodule_sources,
+                            macros, include_dirs):
+        if not f_sources and not fmodule_sources:
+            return None, []
+
+        fcompiler = self._fcompiler
+
+        extra_postargs = []
+        module_dirs = ext.module_dirs[:]
+
+        macros = []
+
+        if check_for_f90_modules:
+            module_build_dir = os.path.join(
+                self.build_temp,os.path.dirname(
+                self.get_ext_filename(fullname)))
+
+            self.mkpath(module_build_dir)
+            if fcompiler.module_dir_switch is None:
+                existing_modules = glob('*.mod')
+            extra_postargs += fcompiler.module_options(\
+                module_dirs,module_build_dir)
+
+        f_objects = []
+        if fmodule_sources:
+            log.info("compiling Fortran 90 module sources")
+            f_objects = fcompiler.compile(fmodule_sources,
+                                          output_dir=self.build_temp,
+                                          macros=macros,
+                                          include_dirs=include_dirs,
+                                          debug=self.debug,
+                                          extra_postargs=extra_postargs,
+                                          depends=ext.depends)
+
+        if check_for_f90_modules \
+               and fcompiler.module_dir_switch is None:
+            for f in glob('*.mod'):
+                if f in existing_modules:
+                    continue
+                try:
+                    self.move_file(f, module_build_dir)
+                except DistutilsFileError:  # already exists in destination
+                    os.remove(f)
+
+        if f_sources:
+            log.info("compiling Fortran sources")
+            f_objects += fcompiler.compile(f_sources,
+                                           output_dir=self.build_temp,
+                                           macros=macros,
+                                           include_dirs=include_dirs,
+                                           debug=self.debug,
+                                           extra_postargs=extra_postargs,
+                                           depends=ext.depends)
+
+        return fcompiler, f_objects
+
     def build_extension(self, ext):
         sources = ext.sources
         if sources is None or not is_sequence(sources):
@@ -212,59 +270,11 @@
                                               **kws)
             self.compiler.compiler_so[0] = old_compiler
 
-        check_for_f90_modules = not not fmodule_sources
+        fcompiler, f_objects = self.get_fortran_objects(ext,
+                                                        f_sources,
+                                                        fmodule_sources,
+                                                        macros, include_dirs)
 
-        if f_sources or fmodule_sources:
-            extra_postargs = []
-            module_dirs = ext.module_dirs[:]
-
-            #if self.fcompiler.compiler_type=='ibm':
-            macros = []
-
-            if check_for_f90_modules:
-                module_build_dir = os.path.join(\
-                    self.build_temp,os.path.dirname(\
-                    self.get_ext_filename(fullname)))
-
-                self.mkpath(module_build_dir)
-                if self.fcompiler.module_dir_switch is None:
-                    existing_modules = glob('*.mod')
-                extra_postargs += self.fcompiler.module_options(\
-                    module_dirs,module_build_dir)
-
-            f_objects = []
-            if fmodule_sources:
-                log.info("compiling Fortran 90 module sources")
-                f_objects = self.fcompiler.compile(fmodule_sources,
-                                                   output_dir=self.build_temp,
-                                                   macros=macros,
-                                                   include_dirs=include_dirs,
-                                                   debug=self.debug,
-                                                   extra_postargs=extra_postargs,
-                                                   depends=ext.depends)
-
-            if check_for_f90_modules \
-                   and self.fcompiler.module_dir_switch is None:
-                for f in glob('*.mod'):
-                    if f in existing_modules:
-                        continue
-                    try:
-                        self.move_file(f, module_build_dir)
-                    except DistutilsFileError:  # already exists in destination
-                        os.remove(f)
-
-            if f_sources:
-                log.info("compiling Fortran sources")
-                f_objects += self.fcompiler.compile(f_sources,
-                                                    output_dir=self.build_temp,
-                                                    macros=macros,
-                                                    include_dirs=include_dirs,
-                                                    debug=self.debug,
-                                                    extra_postargs=extra_postargs,
-                                                    depends=ext.depends)
-        else:
-            f_objects = []
-
         objects = c_objects + f_objects
 
         if ext.extra_objects:
@@ -276,13 +286,10 @@
         except:
             pass
 
-        use_fortran_linker = getattr(ext,'language','c') in ['f77','f90'] \
-                             and self.fcompiler is not None
+        use_fortran_linker = getattr(ext,'language','c') in ['f77','f90']
         c_libraries = []
         c_library_dirs = []
-        if use_fortran_linker or f_sources:
-            use_fortran_linker = 1
-        elif self.distribution.has_c_libraries():
+        if not use_fortran_linker and self.distribution.has_c_libraries():
             build_clib = self.get_finalized_command('build_clib')
             f_libs = []
             for (lib_name, build_info) in build_clib.libraries:
@@ -295,9 +302,13 @@
                     c_library_dirs.extend(build_info.get('library_dirs',[]))
             for l in ext.libraries:
                 if l in f_libs:
-                    use_fortran_linker = 1
+                    use_fortran_linker = True
+                    fcompiler = self.fcompiler.fortran()
                     break
 
+        if use_fortran_linker and not fcompiler:
+            fcompiler = self.fcompiler.fortran()
+
         # Always use system linker when using MSVC compiler.
         if self.compiler.compiler_type=='msvc' and use_fortran_linker:
             self._libs_with_msvc_and_fortran(c_libraries, c_library_dirs)
@@ -307,8 +318,8 @@
             if cxx_sources:
                 # XXX: Which linker should be used, Fortran or C++?
                 log.warn('mixing Fortran and C++ is untested')
-            link = self.fcompiler.link_shared_object
-            language = ext.language or self.fcompiler.detect_language(f_sources)
+            link = fcompiler.link_shared_object
+            language = ext.language or fcompiler.detect_language(f_sources)
         else:
             link = self.compiler.link_shared_object
             if sys.version[:3]>='2.3':
@@ -342,7 +353,8 @@
     def _libs_with_msvc_and_fortran(self, c_libraries, c_library_dirs):
         # Always use system linker when using MSVC compiler.
         f_lib_dirs = []
-        for dir in self.fcompiler.library_dirs:
+        fcompiler = self.fcompiler.fortran()
+        for dir in fcompiler.library_dirs:
             # correct path when compiling in Cygwin but with normal Win
             # Python
             if dir.startswith('/usr/lib'):
@@ -354,7 +366,7 @@
 
         # make g77-compiled static libs available to MSVC
         lib_added = False
-        for lib in self.fcompiler.libraries:
+        for lib in fcompiler.libraries:
             if not lib.startswith('msvcr'):
                 c_libraries.append(lib)
                 p = combine_paths(f_lib_dirs, 'lib' + lib + '.a')

Modified: branches/distutils-revamp/command/config.py
===================================================================
--- branches/distutils-revamp/command/config.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/command/config.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -3,11 +3,12 @@
 # compilers (they must define linker_exe first).
 # Pearu Peterson
 
-import os, signal
+import os, signal, copy
 from distutils.command.config import config as old_config
 from distutils.command.config import LANG_EXT
 from distutils import log
 from numpy.distutils.exec_command import exec_command
+from numpy.distutils.fcompiler import FCompiler, new_fcompiler
 
 LANG_EXT['f77'] = '.f'
 LANG_EXT['f90'] = '.f90'
@@ -27,26 +28,31 @@
         f = self.distribution.get_command_obj('config_fc')
         self.set_undefined_options('config_fc',
                                    ('fcompiler', 'fcompiler'))
+        self._fcompiler = None
 
     def run(self):
         self._check_compiler()
 
-    def _check_compiler (self):
+    def _check_compiler(self):
         old_config._check_compiler(self)
-        from numpy.distutils.fcompiler import FCompiler, new_fcompiler
-        if not isinstance(self.fcompiler, FCompiler):
-            self.fcompiler = new_fcompiler(compiler=self.fcompiler,
-                                           dry_run=self.dry_run, force=1)
-            self.fcompiler.customize(self.distribution)
-            self.fcompiler.customize_cmd(self)
-            self.fcompiler.show_customization()
 
-    def _wrap_method(self,mth,lang,args):
+    def get_fcompiler(self):
+        if self._fcompiler is None:
+            fc = self.fcompiler.fortran()
+            fc.force = 1
+            fc.dry_run = self.dry_run
+            fc.customize(self.distribution)
+            fc.customize_cmd(self)
+            fc.show_customization()
+            self._fcompiler = fc
+        return self._fcompiler
+
+    def _wrap_method(self, mth, lang, args):
         from distutils.ccompiler import CompileError
         from distutils.errors import DistutilsExecError
         save_compiler = self.compiler
-        if lang in ['f77','f90']:
-            self.compiler = self.fcompiler
+        if lang in ('f77', 'f90'):
+            self.compiler = self.get_fcompiler()
         try:
             ret = mth(*((self,)+args))
         except (DistutilsExecError,CompileError),msg:

Modified: branches/distutils-revamp/command/config_compiler.py
===================================================================
--- branches/distutils-revamp/command/config_compiler.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/command/config_compiler.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -1,5 +1,6 @@
 
 import sys
+import copy
 import distutils.core
 from distutils.core import Command
 from distutils.errors import DistutilsSetupError
@@ -14,11 +15,68 @@
     if _cache:
         return
     _cache.append(1)
-    from numpy.distutils.core import get_distribution
-    dist = get_distribution()
-    print dist.verbose
-    show_fcompilers(dist)
+    show_fcompilers()
 
+class FCompilerProxy(object):
+    """
+    A layer of indirection to simplify choosing the correct Fortran compiler.
+
+    If need_f90(), f90(), or fortran(requiref90=True) is called at any time,
+    a Fortran 90 compiler is found and used for *all* Fortran sources,
+    including Fortran 77 sources.
+    """
+    #XXX The ability to use a separate F77 compiler is likely not
+    # necessary: of all the compilers we support, only the 'gnu'
+    # compiler (g77) doesn't support F90, and everything else supports
+    # both.
+
+    def __init__(self, compiler_type, distribution):
+        self._fcompiler = None
+        self._have_f77 = None
+        self._have_f90 = None
+        self._compiler_type = compiler_type
+        self.distribution = distribution
+
+    def _set_fcompiler(self, requiref90=False):
+        fc = new_fcompiler(compiler=self._compiler_type,
+                           dry_run=self.distribution.dry_run,
+                           verbose=self.distribution.verbose,
+                           requiref90=requiref90)
+        if fc is None:
+            raise DistutilsSetupError("could not find a Fortran compiler")
+        fc.customize(self.distribution)
+        self._fcompiler = fc
+        self._have_f77 = fc.compiler_f77 is not None
+        if requiref90:
+            self._have_f90 = fc.compiler_f90 is not None
+        log.info('%s (%s)' % (fc.description, fc.get_version()))
+
+    def need_f77(self):
+        if self._fcompiler is None:
+            self._set_fcompiler(requiref90=False)
+        if not self._have_f77:
+            raise DistutilsSetupError("could not find a Fortran 77 compiler")
+
+    def need_f90(self):
+        if self._fcompiler is None or self._have_f90 is None:
+            self._set_fcompiler(requiref90=True)
+        if not self._have_f90:
+            raise DistutilsSetupError("could not find a Fortran 90 compiler")
+
+    def f77(self):
+        self.need_f77()
+        return copy.copy(self._fcompiler)
+
+    def f90(self):
+        self.need_f90()
+        return copy.copy(self._fcompiler)
+
+    def fortran(self, requiref90=False):
+        if requiref90:
+            return self.f90()
+        else:
+            return self.f77()
+
 class config_fc(Command):
     """ Distutils command to hold user specified options
     to Fortran compilers.
@@ -73,32 +131,7 @@
         self.arflags = None
 
     def finalize_options(self):
-        fc = new_fcompiler(compiler=self.fcompiler,
-                           verbose=self.distribution.verbose)
-        fc.customize(self.distribution)
-        self.fcompiler = fc
-        if self.fcompiler.compiler_f90 is not None:
-            self.f90compiler = fc
-        else:
-            self.f90compiler = None
-        log.info('%s (%s)' % (fc.description, fc.get_version()))
+        self.fcompiler = FCompilerProxy(self.fcompiler, self.distribution)
 
     def run(self):
         pass
-
-    def get_f77_compiler(self):
-        if self.fcompiler.compiler_f77 is None:
-            raise DistutilsSetupError("could not find a Fortran 77 compiler")
-        return self.fcompiler
-
-    def get_f90_compiler(self):
-        if self.f90compiler is not None:
-            return self.f90compiler
-        if self.fcompiler.compiler_f90 is None:
-            fc = new_fcompiler(compiler=self.fcompiler,
-                               verbose=self.distribution.verbose,
-                               requiref90=True)
-            if fc is None:
-                raise DistutilsSetupError("could not find a Fortran 90 compiler")
-            self.f90compiler = fc
-            return fc

Modified: branches/distutils-revamp/fcompiler/__init__.py
===================================================================
--- branches/distutils-revamp/fcompiler/__init__.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/fcompiler/__init__.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -10,6 +10,7 @@
 import os
 import sys
 import re
+import new
 try:
     set
 except NameError:
@@ -63,11 +64,15 @@
       libraries
       library_dirs
     """
-    # for documentation purposes, these are the environment variables
-    # used.
+
+    # These are the environment variables and distutils keys used.
     # Each configuration descripition is
     # (<hook name>, <environment variable>, <key in distutils.cfg>)
     # The hook names are handled by the self._environment_hook method.
+    #  - names starting with 'self.' call methods in this class
+    #  - names starting with 'exe.' return the key in the executables dict
+    #  - names like'flags.YYY' return self.get_flag_YYY()
+
     distutils_vars = EnvironmentConfig(
         noopt = (None, None, 'noopt'),
         noarch = (None, None, 'noarch'),
@@ -171,6 +176,14 @@
             if e not in self.executables:
                 self.executables[e] = None
 
+    def __copy__(self):
+        obj = new.instance(self.__class__, self.__dict__)
+        obj.distutils_vars = obj.distutils_vars.clone(obj._environment_hook)
+        obj.command_vars = obj.command_vars.clone(obj._environment_hook)
+        obj.flag_vars = obj.flag_vars.clone(obj._environment_hook)
+        obj.executables = obj.executables.copy()
+        return obj
+
     # If compiler does not support compiling Fortran 90 then it can
     # suggest using another compiler. For example, gnu would suggest
     # gnu95 compiler type when there are F90 sources.
@@ -231,12 +244,12 @@
                     return fc_exe
             return None
 
-        f77 = set_exe('compiler_f77')
-        if not f77:
-            raise CompilerNotFound('f77')
         f90 = set_exe('compiler_f90')
         if not f90:
             raise CompilerNotFound('f90')
+        f77 = set_exe('compiler_f77', f90=f90)
+        if not f77:
+            raise CompilerNotFound('f90')
         set_exe('compiler_fix', f90=f90)
 
         set_exe('linker_so', f77=f77, f90=f90)
@@ -372,6 +385,11 @@
             vflags = self.flag_vars.version
             self.set_executables(version_cmd=[vers_cmd]+vflags)
 
+        f77flags = []
+        f90flags = []
+        freeflags = []
+        fixflags = []
+
         if f77:
             f77flags = self.flag_vars.f77
         if f90:
@@ -439,11 +457,6 @@
         self.set_library_dirs(self.get_library_dirs())
         self.set_libraries(self.get_libraries())
 
-        verbose = self.distutils_vars.get('verbose', self.verbose)
-        if verbose:
-            self.dump_properties()
-        return
-
     def dump_properties(self):
         """ Print out the attributes of a compiler instance. """
         props = []
@@ -680,8 +693,7 @@
             return compiler_type
     return None
 
-def get_default_fcompiler(osname=None, platform=None, requiref90=False):
-    """Determine the default Fortran compiler to use for the given platform."""
+def available_fcompilers_for_platform(osname=None, platform=None):
     if osname is None:
         osname = os.name
     if platform is None:
@@ -689,9 +701,18 @@
     matching_compiler_types = []
     for pattern, compiler_type in _default_compilers:
         if re.match(pattern, platform) or re.match(pattern, osname):
-            matching_compiler_types.extend(list(compiler_type))
+            for ct in compiler_type:
+                if ct not in matching_compiler_types:
+                    matching_compiler_types.append(ct)
     if not matching_compiler_types:
         matching_compiler_types.append('gnu')
+    return matching_compiler_types
+
+def get_default_fcompiler(osname=None, platform=None, requiref90=False):
+    """Determine the default Fortran compiler to use for the given
+    platform."""
+    matching_compiler_types = available_fcompilers_for_platform(osname,
+                                                                platform)
     compiler_type =  _find_existing_fcompiler(matching_compiler_types,
                                               osname=osname,
                                               platform=platform,
@@ -725,7 +746,7 @@
     compiler = klass(verbose=verbose, dry_run=dry_run, force=force)
     return compiler
 
-def show_fcompilers(dist = None):
+def show_fcompilers(dist=None):
     """Print list of available compilers (used by the "--help-fcompiler"
     option to "config_fc").
     """
@@ -735,6 +756,10 @@
         dist = Distribution()
         dist.script_name = os.path.basename(sys.argv[0])
         dist.script_args = ['config_fc'] + sys.argv[1:]
+        try:
+            dist.script_args.remove('--help-fcompiler')
+        except ValueError:
+            pass
         dist.cmdclass['config_fc'] = config_fc
         dist.parse_config_files()
         dist.parse_command_line()
@@ -744,35 +769,38 @@
     compilers_ni = []
     if not fcompiler_class:
         load_all_fcompiler_classes()
-    not_available = object()
-    for compiler in fcompiler_class.keys():
-        v = not_available
+    platform_compilers = available_fcompilers_for_platform()
+    for compiler in platform_compilers:
+        v = None
         try:
             c = new_fcompiler(compiler=compiler, verbose=dist.verbose)
             c.customize(dist)
             v = c.get_version()
         except (DistutilsModuleError, CompilerNotFound):
-            v = not_available
+            pass
         if v is None:
             compilers_na.append(("fcompiler="+compiler, None,
                               fcompiler_class[compiler][2]))
-        elif v is not_available:
-            compilers_ni.append(("fcompiler="+compiler, None,
-                                 fcompiler_class[compiler][2]))
         else:
+            c.dump_properties()
             compilers.append(("fcompiler="+compiler, None,
                               fcompiler_class[compiler][2] + ' (%s)' % v))
 
+    compilers_ni = list(set(fcompiler_class.keys()) - set(platform_compilers))
+    compilers_ni = [("fcompiler="+fc, None, fcompiler_class[fc][2])
+                    for fc in compilers_ni]
+
     compilers.sort()
     compilers_na.sort()
     compilers_ni.sort()
     pretty_printer = FancyGetopt(compilers)
-    pretty_printer.print_help("List of available Fortran compilers:")
+    pretty_printer.print_help("Fortran compilers found:")
     pretty_printer = FancyGetopt(compilers_na)
-    pretty_printer.print_help("List of unavailable Fortran compilers:")
+    pretty_printer.print_help("Compilers available for this "
+                              "platform, but not found:")
     if compilers_ni:
         pretty_printer = FancyGetopt(compilers_ni)
-        pretty_printer.print_help("List of unimplemented Fortran compilers:")
+        pretty_printer.print_help("Compilers not available on this platform:")
     print "For compiler details, run 'config_fc --verbose' setup command."
 
 def dummy_fortran_file():

Modified: branches/distutils-revamp/fcompiler/gnu.py
===================================================================
--- branches/distutils-revamp/fcompiler/gnu.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/fcompiler/gnu.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -15,7 +15,7 @@
 class GnuFCompiler(FCompiler):
 
     compiler_type = 'gnu'
-    description = 'GNU Fortran Compiler'
+    description = 'GNU Fortran 77 compiler'
     version_match = simple_version_match(start=r'GNU Fortran (?!95)')
 
     # 'g77 --version' results
@@ -236,7 +236,7 @@
 class Gnu95FCompiler(GnuFCompiler):
 
     compiler_type = 'gnu95'
-    description = 'GNU 95 Fortran Compiler'
+    description = 'GNU Fortran 95 compiler'
     version_match = simple_version_match(start='GNU Fortran 95')
 
     # 'gfortran --version' results:

Modified: branches/distutils-revamp/interactive.py
===================================================================
--- branches/distutils-revamp/interactive.py	2006-12-14 09:54:03 UTC (rev 3486)
+++ branches/distutils-revamp/interactive.py	2006-12-14 14:57:08 UTC (rev 3487)
@@ -20,7 +20,7 @@
 
 def show_fortran_compilers(*args):
     from fcompiler import show_fcompilers
-    show_fcompilers({})
+    show_fcompilers()
 
 def show_compilers(*args):
     from distutils.ccompiler import show_compilers



More information about the Numpy-svn mailing list