[Numpy-svn] r2946 - in branches/distutils-revamp: . command fcompiler
numpy-svn at scipy.org
numpy-svn at scipy.org
Wed Aug 2 22:42:42 EDT 2006
Author: cookedm
Date: 2006-08-02 21:42:25 -0500 (Wed, 02 Aug 2006)
New Revision: 2946
Added:
branches/distutils-revamp/environment.py
Modified:
branches/distutils-revamp/ccompiler.py
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/exec_command.py
branches/distutils-revamp/fcompiler/__init__.py
branches/distutils-revamp/fcompiler/absoft.py
branches/distutils-revamp/fcompiler/compaq.py
branches/distutils-revamp/fcompiler/g95.py
branches/distutils-revamp/fcompiler/gnu.py
branches/distutils-revamp/fcompiler/hpux.py
branches/distutils-revamp/fcompiler/ibm.py
branches/distutils-revamp/fcompiler/intel.py
branches/distutils-revamp/fcompiler/lahey.py
branches/distutils-revamp/fcompiler/mips.py
branches/distutils-revamp/fcompiler/nag.py
branches/distutils-revamp/fcompiler/none.py
branches/distutils-revamp/fcompiler/pg.py
branches/distutils-revamp/fcompiler/sun.py
branches/distutils-revamp/fcompiler/vast.py
branches/distutils-revamp/intelccompiler.py
branches/distutils-revamp/system_info.py
Log:
[distutils-revamp] Rework building of extensions using Fortran.
* less stuff done in Fortran compiler modules at import time
* list of available compilers built up from modules in
numpy.distutils.fcompiler
* finding executables centralized in one place and made sane. For instance,
setting the Fortran 77 or 90 compilers will also make the right compiler
used for the version command and the linker.
* environment configuration for FCompiler put into one place. The environment
module takes care of environment variables and distutils configs, and
the FCompiler class has everything that's configurable grouped in one
place. Much easier to tell how to customize it now.
* fcompiler only set in config_fc
* build_ext implies build_clib
* some other cleanups
There's still some rough edges here.
Modified: branches/distutils-revamp/ccompiler.py
===================================================================
--- branches/distutils-revamp/ccompiler.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/ccompiler.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -245,6 +245,8 @@
version_cmd = self.version_cmd
except AttributeError:
return None
+ if not version_cmd or not version_cmd[0]:
+ return None
cmd = ' '.join(version_cmd)
try:
matcher = self.version_match
@@ -264,9 +266,7 @@
version = None
if status in ok_status:
version = matcher(output)
- if not version:
- log.warn("Couldn't match compiler version for %r" % (output,))
- else:
+ if version:
version = LooseVersion(version)
self.version = version
return version
Modified: branches/distutils-revamp/command/build_clib.py
===================================================================
--- branches/distutils-revamp/command/build_clib.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/command/build_clib.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -21,13 +21,11 @@
def initialize_options(self):
old_build_clib.initialize_options(self)
self.fcompiler = None
- return
def finalize_options(self):
old_build_clib.finalize_options(self)
self.set_undefined_options('build_ext',
('fcompiler', 'fcompiler'))
- return
def have_f_sources(self):
for (lib_name, build_info) in self.libraries:
@@ -65,13 +63,6 @@
self.compiler.show_customization()
if self.have_f_sources():
- from numpy.distutils.fcompiler import new_fcompiler
- self.fcompiler = new_fcompiler(compiler=self.fcompiler,
- verbose=self.verbose,
- dry_run=self.dry_run,
- force=self.force)
- self.fcompiler.customize(self.distribution)
-
libraries = self.libraries
self.libraries = None
self.fcompiler.customize_cmd(self)
@@ -80,7 +71,6 @@
self.fcompiler.show_customization()
self.build_libraries(self.libraries)
- return
def get_source_files(self):
self.check_library_list(self.libraries)
@@ -91,7 +81,6 @@
def build_libraries(self, libraries):
-
for (lib_name, build_info) in libraries:
# default compilers
compiler = self.compiler
@@ -105,8 +94,6 @@
"a list of source filenames") % lib_name
sources = list(sources)
-
-
lib_file = compiler.library_filename(lib_name,
output_dir=self.build_clib)
@@ -192,5 +179,3 @@
clib_libraries.extend(binfo[1].get('libraries',[]))
if clib_libraries:
build_info['libraries'] = clib_libraries
-
- return
Modified: branches/distutils-revamp/command/build_ext.py
===================================================================
--- branches/distutils-revamp/command/build_ext.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/command/build_ext.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -31,7 +31,6 @@
def initialize_options(self):
old_build_ext.initialize_options(self)
self.fcompiler = None
- return
def finalize_options(self):
incl_dirs = self.include_dirs
@@ -40,18 +39,19 @@
self.include_dirs.extend(self.distribution.include_dirs or [])
self.set_undefined_options('config_fc',
('fcompiler', 'fcompiler'))
- return
def run(self):
if not self.extensions:
return
# Make sure that extension sources are complete.
- for ext in self.extensions:
- if not all_strings(ext.sources):
- self.run_command('build_src')
+ self.run_command('build_src')
+# for ext in self.extensions:
+# if not all_strings(ext.sources):
+# self.run_command('build_src')
if self.distribution.has_c_libraries():
+ self.run_command('build_clib')
build_clib = self.get_finalized_command('build_clib')
self.library_dirs.append(build_clib.build_clib)
else:
@@ -64,25 +64,25 @@
# Determine if Fortran compiler is needed.
if build_clib and build_clib.fcompiler is not None:
- need_f_compiler = 1
+ need_f_compiler = True
else:
- need_f_compiler = 0
+ need_f_compiler = False
for ext in self.extensions:
if has_f_sources(ext.sources):
- need_f_compiler = 1
+ need_f_compiler = True
break
if getattr(ext,'language','c') in ['f77','f90']:
- need_f_compiler = 1
+ need_f_compiler = True
break
# Determine if C++ compiler is needed.
need_cxx_compiler = 0
for ext in self.extensions:
if has_cxx_sources(ext.sources):
- need_cxx_compiler = 1
+ need_cxx_compiler = True
break
- if getattr(ext,'language','c')=='c++':
- need_cxx_compiler = 1
+ if getattr(ext,'language','c') == 'c++':
+ need_cxx_compiler = True
break
from distutils.ccompiler import new_compiler
@@ -96,22 +96,16 @@
# Initialize Fortran/C++ compilers if needed.
if need_f_compiler:
- from numpy.distutils.fcompiler import new_fcompiler
- self.fcompiler = new_fcompiler(compiler=self.fcompiler,
- verbose=self.verbose,
- dry_run=self.dry_run,
- force=self.force)
if self.fcompiler.get_version():
- self.fcompiler.customize(self.distribution)
self.fcompiler.customize_cmd(self)
self.fcompiler.show_customization()
else:
- self.warn('fcompiler=%s is not available.' % (self.fcompiler.compiler_type))
+ self.warn('fcompiler=%s is not available.' % (
+ self.fcompiler.compiler_type,))
self.fcompiler = None
# Build extensions
self.build_extensions()
- return
def swig_sources(self, sources):
# Do nothing. Swig sources have beed handled in build_src command.
Modified: branches/distutils-revamp/command/config.py
===================================================================
--- branches/distutils-revamp/command/config.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/command/config.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -21,15 +21,16 @@
def initialize_options(self):
self.fcompiler = None
old_config.initialize_options(self)
- return
def finalize_options(self):
old_config.finalize_options(self)
f = self.distribution.get_command_obj('config_fc')
self.set_undefined_options('config_fc',
('fcompiler', 'fcompiler'))
- return
+ def run(self):
+ self._check_compiler()
+
def _check_compiler (self):
old_config._check_compiler(self)
from numpy.distutils.fcompiler import FCompiler, new_fcompiler
@@ -39,7 +40,6 @@
self.fcompiler.customize(self.distribution)
self.fcompiler.customize_cmd(self)
self.fcompiler.show_customization()
- return
def _wrap_method(self,mth,lang,args):
from distutils.ccompiler import CompileError
Modified: branches/distutils-revamp/command/config_compiler.py
===================================================================
--- branches/distutils-revamp/command/config_compiler.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/command/config_compiler.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -1,6 +1,9 @@
import sys
+import distutils.core
from distutils.core import Command
+from distutils import log
+from numpy.distutils.fcompiler import show_fcompilers, new_fcompiler
#XXX: Implement confic_cc for enhancing C/C++ compiler options.
#XXX: Linker flags
@@ -10,9 +13,10 @@
if _cache:
return
_cache.append(1)
- from numpy.distutils.fcompiler import show_fcompilers
from numpy.distutils.core import get_distribution
- show_fcompilers(get_distribution())
+ dist = get_distribution()
+ print dist.verbose
+ show_fcompilers(dist)
class config_fc(Command):
""" Distutils command to hold user specified options
@@ -52,12 +56,13 @@
self.debug = None
self.noopt = None
self.noarch = None
- return
def finalize_options(self):
- # Do nothing.
- return
+ fc = new_fcompiler(compiler=self.fcompiler,
+ verbose=self.distribution.verbose)
+ fc.customize(self.distribution)
+ self.fcompiler = fc
+ log.info('%s (%s)' % (fc.description, fc.get_version()))
def run(self):
- # Do nothing.
- return
+ pass
Added: branches/distutils-revamp/environment.py
===================================================================
--- branches/distutils-revamp/environment.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/environment.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -0,0 +1,49 @@
+import os
+from distutils.dist import Distribution
+
+__metaclass__ = type
+
+class EnvironmentConfig:
+ def __init__(self, distutils_section='DEFAULT', **kw):
+ self._distutils_section = distutils_section
+ self._conf_keys = kw
+ self._conf = None
+ self._hook_handler = None
+
+ def __getattr__(self, name):
+ try:
+ conf_desc = self._conf_keys[name]
+ except KeyError:
+ raise AttributeError(name)
+ return self._get_var(name, conf_desc)
+
+ def get(self, name, default=None):
+ try:
+ conf_desc = self._conf_keys[name]
+ except KeyError:
+ return default
+ var = self._get_var(name, conf_desc)
+ if var is None:
+ var = default
+ return var
+
+ def _get_var(self, name, conf_desc):
+ hook, envvar, confvar = conf_desc
+ var = self._hook_handler(name, hook)
+ if envvar is not None:
+ var = os.environ.get(envvar, var)
+ if confvar is not None and self._conf:
+ var = self._conf.get(confvar, (None, var))[1]
+ return var
+
+ def clone(self, hook_handler):
+ ec = self.__class__(distutils_section=self._distutils_section,
+ **self._conf_keys)
+ ec._hook_handler = hook_handler
+ return ec
+
+ def use_distribution(self, dist):
+ if isinstance(dist, Distribution):
+ self._conf = dist.get_option_dict(self._distutils_section)
+ else:
+ self._conf = dist
Modified: branches/distutils-revamp/exec_command.py
===================================================================
--- branches/distutils-revamp/exec_command.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/exec_command.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -123,60 +123,48 @@
############################################################
def find_executable(exe, path=None):
- """ Return full path of a executable.
+ """Return full path of a executable.
+
+ Symbolic links are not followed.
"""
log.debug('find_executable(%r)' % exe)
orig_exe = exe
+
if path is None:
path = os.environ.get('PATH',os.defpath)
if os.name=='posix' and sys.version[:3]>'2.1':
realpath = os.path.realpath
else:
realpath = lambda a:a
- if exe[0]=='"':
+
+ if exe.startswith('"'):
exe = exe[1:-1]
- suffices = ['']
+
+ suffixes = ['']
if os.name in ['nt','dos','os2']:
fn,ext = os.path.splitext(exe)
- extra_suffices = ['.exe','.com','.bat']
- if ext.lower() not in extra_suffices:
- suffices = extra_suffices
+ extra_suffixes = ['.exe','.com','.bat']
+ if ext.lower() not in extra_suffixes:
+ suffixes = extra_suffixes
+
if os.path.isabs(exe):
paths = ['']
else:
- paths = map(os.path.abspath, path.split(os.pathsep))
- if 0 and os.name == 'nt':
- new_paths = []
- cygwin_paths = []
- for path in paths:
- d,p = os.path.splitdrive(path)
- if p.lower().find('cygwin') >= 0:
- cygwin_paths.append(path)
- else:
- new_paths.append(path)
- paths = new_paths + cygwin_paths
+ paths = [ os.path.abspath(p) for p in path.split(os.pathsep) ]
+
for path in paths:
- fn = os.path.join(path,exe)
- for s in suffices:
+ fn = os.path.join(path, exe)
+ for s in suffixes:
f_ext = fn+s
if not os.path.islink(f_ext):
- # see comment below.
f_ext = realpath(f_ext)
- if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):
+ if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK):
log.debug('Found executable %s' % f_ext)
return f_ext
- if os.path.islink(exe):
- # Don't follow symbolic links. E.g. when using colorgcc then
- # gcc -> /usr/bin/colorgcc
- # g77 -> /usr/bin/colorgcc
- pass
- else:
- exe = realpath(exe)
- if not os.path.isfile(exe) or os.access(exe,os.X_OK):
- log.warn('Could not locate executable %s' % orig_exe)
- return orig_exe
- return exe
+ log.warn('Could not locate executable %s' % orig_exe)
+ return None
+
############################################################
def _preserve_environment( names ):
Modified: branches/distutils-revamp/fcompiler/__init__.py
===================================================================
--- branches/distutils-revamp/fcompiler/__init__.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/__init__.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -10,7 +10,11 @@
import os
import sys
import re
-from types import StringType,NoneType
+try:
+ set
+except NameError:
+ from sets import Set as set
+
from distutils.sysconfig import get_config_var
from distutils.fancy_getopt import FancyGetopt
from distutils.errors import DistutilsModuleError,DistutilsArgError,\
@@ -19,11 +23,16 @@
from numpy.distutils.ccompiler import CCompiler, gen_lib_options
from numpy.distutils import log
-from numpy.distutils.command.config_compiler import config_fc
-from numpy.distutils.core import get_distribution
from numpy.distutils.misc_util import is_string, is_sequence
+from numpy.distutils.environment import EnvironmentConfig
+from numpy.distutils.exec_command import find_executable
from distutils.spawn import _nt_quote_args
+__metaclass__ = type
+
+class CompilerNotFound(Exception):
+ pass
+
class FCompiler(CCompiler):
""" Abstract base class to define the interface that must be implemented
by real Fortran compiler classes.
@@ -54,8 +63,52 @@
libraries
library_dirs
"""
+ # for documentation purposes, these are the environment variables
+ # used.
+ # Each configuration descripition is
+ # (<hook name>, <environment variable>, <key in distutils.cfg>)
+ # The hook names are handled by the self._environment_hook method.
+ distutils_vars = EnvironmentConfig(
+ noopt = (None, None, 'noopt'),
+ noarch = (None, None, 'noarch'),
+ debug = (None, None, 'debug'),
+ verbose = (None, None, 'verbose'),
+ )
+ command_vars = EnvironmentConfig(
+ distutils_section='config_fc',
+ compiler_f77 = ('exe.compiler_f77', 'F77', 'f77exec'),
+ compiler_f90 = ('exe.compiler_f90', 'F90', 'f90exec'),
+ compiler_fix = ('exe.compiler_fix', 'F90', 'f90exec'),
+ version_cmd = ('self.get_version_cmd', None, None),
+ linker_so = ('self.get_linker_so', 'LDSHARED', None),
+ linker_exe = ('self.get_linker_exe', 'LD', None),
+ archiver = (None, 'AR', None),
+ ranlib = (None, 'RANLIB', None),
+ )
+ flag_vars = EnvironmentConfig(
+ distutils_section='config_fc',
+ version = ('flags.version', None, None),
+ f77 = ('flags.f77', 'F77FLAGS', 'f77flags'),
+ f90 = ('flags.f90', 'F90FLAGS', 'f90flags'),
+ free = ('flags.free', 'FREEFLAGS', 'freeflags'),
+ fix = ('flags.fix', None, None),
+ opt = ('flags.opt', 'FOPT', 'opt'),
+ opt_f77 = ('flags.opt_f77', None, None),
+ opt_f90 = ('flags.opt_f90', None, None),
+ arch = ('flags.arch', 'FARCH', 'arch'),
+ arch_f77 = ('flags.arch_f77', None, None),
+ arch_f90 = ('flags.arch_f90', None, None),
+ debug = ('flags.debug', 'FDEBUG', None, None),
+ debug_f77 = ('flags.debug_f77', None, None),
+ debug_f90 = ('flags.debug_f90', None, None),
+ flags = ('self.get_flags', 'FFLAGS', None),
+ linker_so = ('flags.linker_so', 'LDFLAGS', None),
+ linker_exe = ('flags.linker_exe', 'LDFLAGS', None),
+ ar = ('flags.ar', 'ARFLAGS', None),
+ )
+
language_map = {'.f':'f77',
'.for':'f77',
'.F':'f77', # XXX: needs preprocessor
@@ -69,14 +122,15 @@
version_pattern = None
+ possible_executables = []
executables = {
- 'version_cmd' : ["f77","-v"],
+ 'version_cmd' : ["f77", "-v"],
'compiler_f77' : ["f77"],
'compiler_f90' : ["f90"],
- 'compiler_fix' : ["f90","-fixed"],
- 'linker_so' : ["f90","-shared"],
+ 'compiler_fix' : ["f90", "-fixed"],
+ 'linker_so' : ["f90", "-shared"],
'linker_exe' : ["f90"],
- 'archiver' : ["ar","-cr"],
+ 'archiver' : ["ar", "-cr"],
'ranlib' : None,
}
@@ -105,64 +159,111 @@
shared_lib_format = "%s%s"
exe_extension = ""
+ def __init__(self, *args, **kw):
+ CCompiler.__init__(self, *args, **kw)
+ self.distutils_vars = self.distutils_vars.clone(self._environment_hook)
+ self.command_vars = self.command_vars.clone(self._environment_hook)
+ self.flag_vars = self.flag_vars.clone(self._environment_hook)
+ self.executables = self.executables.copy()
+ for e in ['version_cmd', 'compiler_f77', 'compiler_f90',
+ 'compiler_fix', 'linker_so', 'linker_exe', 'archiver',
+ 'ranlib']:
+ if e not in self.executables:
+ self.executables[e] = None
+
######################################################################
## Methods that subclasses may redefine. But don't call these methods!
## They are private to FCompiler class and may return unexpected
## results if used elsewhere. So, you have been warned..
+ def find_executables(self):
+ """Go through the self.executables dictionary, and attempt to
+ find and assign appropiate executables.
+
+ Executable names are looked for in the environment (environment
+ variables, the distutils.cfg, and command line), the 0th-element of
+ the command list, and the self.possible_executables list.
+
+ Also, if the 0th element is "<F77>" or "<F90>", the Fortran 77
+ or the Fortran 90 compiler executable is used, unless overridden
+ by an environment setting.
+ """
+ exe_cache = {}
+ def cached_find_executable(exe):
+ if exe in exe_cache:
+ return exe_cache[exe]
+ fc_exe = find_executable(exe)
+ exe_cache[exe] = fc_exe
+ return fc_exe
+ def set_exe(exe_key, f77=None, f90=None):
+ cmd = self.executables.get(exe_key, None)
+ if not cmd:
+ return None
+ # Note that we get cmd[0] here if the environment doesn't
+ # have anything set
+ exe_from_environ = getattr(self.command_vars, exe_key)
+ if not exe_from_environ:
+ possibles = [f90, f77] + self.possible_executables
+ else:
+ possibles = [exe_from_environ] + self.possible_executables
+
+ seen = set()
+ unique_possibles = []
+ for e in possibles:
+ if e == '<F77>':
+ e = f77
+ elif e == '<F90>':
+ e = f90
+ if not e or e in seen:
+ continue
+ seen.add(e)
+ unique_possibles.append(e)
+
+ for exe in unique_possibles:
+ fc_exe = cached_find_executable(exe)
+ if fc_exe:
+ cmd[0] = fc_exe
+ 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')
+ set_exe('compiler_fix', f90=f90)
+
+ set_exe('linker_so', f77=f77, f90=f90)
+ set_exe('linker_exe', f77=f77, f90=f90)
+ set_exe('version_cmd', f77=f77, f90=f90)
+
+ set_exe('archiver')
+ set_exe('ranlib')
+
def get_version_cmd(self):
- """ Compiler command to print out version information. """
- f77 = self.executables['compiler_f77']
- if f77 is not None:
- f77 = f77[0]
+ """Compiler command to print out version information."""
cmd = self.executables['version_cmd']
- if cmd is not None:
- cmd = cmd[0]
- if cmd==f77:
- cmd = self.compiler_f77[0]
- else:
- f90 = self.executables['compiler_f90']
- if f90 is not None:
- f90 = f90[0]
- if cmd==f90:
- cmd = self.compiler_f90[0]
- return cmd
+ if cmd:
+ return cmd[0]
+ else:
+ return None
def get_linker_so(self):
- """ Linker command to build shared libraries. """
- f77 = self.executables['compiler_f77']
- if f77 is not None:
- f77 = f77[0]
- ln = self.executables['linker_so']
- if ln is not None:
- ln = ln[0]
- if ln==f77:
- ln = self.compiler_f77[0]
- else:
- f90 = self.executables['compiler_f90']
- if f90 is not None:
- f90 = f90[0]
- if ln==f90:
- ln = self.compiler_f90[0]
- return ln
+ """Linker command to build shared libraries."""
+ cmd = self.executables['linker_so']
+ if cmd:
+ return cmd[0]
+ else:
+ return None
def get_linker_exe(self):
- """ Linker command to build shared libraries. """
- f77 = self.executables['compiler_f77']
- if f77 is not None:
- f77 = f77[0]
- ln = self.executables.get('linker_exe')
- if ln is not None:
- ln = ln[0]
- if ln==f77:
- ln = self.compiler_f77[0]
- else:
- f90 = self.executables['compiler_f90']
- if f90 is not None:
- f90 = f90[0]
- if ln==f90:
- ln = self.compiler_f90[0]
- return ln
+ """Linker command to build shared libraries."""
+ cmd = self.executables['linker_exe']
+ if cmd:
+ return cmd[0]
+ else:
+ return None
def get_flags(self):
""" List of flags common to all compiler types. """
@@ -242,86 +343,66 @@
instance is needed for (iii) and (iv).
"""
log.info('customize %s' % (self.__class__.__name__))
- from distutils.dist import Distribution
- if dist is None:
- # These hooks are for testing only!
- dist = Distribution()
-# dist.script_name = os.path.basename(sys.argv[0])
-# dist.script_args = ['config_fc'] + sys.argv[1:]
-# dist.cmdclass['config_fc'] = config_fc
-# dist.parse_config_files()
-# dist.parse_command_line()
- if isinstance(dist, Distribution):
- conf = dist.get_option_dict('config_fc')
- else:
- assert isinstance(dist,dict)
- conf = dist
- noopt = conf.get('noopt',[None,0])[1]
+ self.distutils_vars.use_distribution(dist)
+ self.command_vars.use_distribution(dist)
+ self.flag_vars.use_distribution(dist)
+
+ self.find_executables()
+
+ noopt = self.distutils_vars.get('noopt', False)
if 0: # change to `if 1:` when making release.
# Don't use architecture dependent compiler flags:
- noarch = 1
+ noarch = True
else:
- noarch = conf.get('noarch',[None,noopt])[1]
- debug = conf.get('debug',[None,0])[1]
+ noarch = self.distutils_vars.get('noarch', noopt)
+ debug = self.distutils_vars.get('debug', False)
- f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))
- f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))
- # Temporarily setting f77,f90 compilers so that
- # version_cmd can use their executables.
- if f77:
- self.set_executables(compiler_f77=[f77])
- if f90:
- self.set_executables(compiler_f90=[f90])
+ f77 = self.command_vars.compiler_f77
+ f90 = self.command_vars.compiler_f90
# Must set version_cmd before others as self.get_flags*
# methods may call self.get_version.
- vers_cmd = self.__get_cmd(self.get_version_cmd)
+ vers_cmd = self.command_vars.version_cmd
if vers_cmd:
- vflags = self.__get_flags(self.get_flags_version)
+ vflags = self.flag_vars.version
self.set_executables(version_cmd=[vers_cmd]+vflags)
if f77:
- f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',
- (conf,'f77flags'))
+ f77flags = self.flag_vars.f77
if f90:
- f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',
- (conf,'f90flags'))
- freeflags = self.__get_flags(self.get_flags_free,'FREEFLAGS',
- (conf,'freeflags'))
+ f90flags = self.flag_vars.f90
+ freeflags = self.flag_vars.free
# XXX Assuming that free format is default for f90 compiler.
- fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))
+ fix = self.command_vars.compiler_fix
if fix:
- fixflags = self.__get_flags(self.get_flags_fix) + f90flags
+ fixflags = self.flag_vars.fix + f90flags
- oflags,aflags,dflags = [],[],[]
+ oflags, aflags, dflags = [], [], []
+ def to_list(flags):
+ if is_string(flags):
+ return [flags]
+ return flags
+ # examine get_flags_<tag>_<compiler> for extra flags
+ # only add them if the method is different from get_flags_<tag>
+ def get_flags(tag, flags):
+ # note that self.flag_vars.<tag> calls self.get_flags_<tag>()
+ flags.extend(to_list(getattr(self.flag_vars, tag)))
+ this_get = getattr(self, 'get_flags_' + tag)
+ for name, c, flagvar in [('f77', f77, f77flags),
+ ('f90', f90, f90flags),
+ ('f90', fix, fixflags)]:
+ t = '%s_%s' % (tag, name)
+ if c and this_get is not getattr(self, 'get_flags_' + t):
+ flagvar.extend(to_list(getattr(self.flag_vars, t)))
+ return oflags
if not noopt:
- oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))
- if f77 and self.get_flags_opt is not self.get_flags_opt_f77:
- f77flags += self.__get_flags(self.get_flags_opt_f77)
- if f90 and self.get_flags_opt is not self.get_flags_opt_f90:
- f90flags += self.__get_flags(self.get_flags_opt_f90)
- if fix and self.get_flags_opt is not self.get_flags_opt_f90:
- fixflags += self.__get_flags(self.get_flags_opt_f90)
+ get_flags('opt', oflags)
if not noarch:
- aflags = self.__get_flags(self.get_flags_arch,'FARCH',
- (conf,'arch'))
- if f77 and self.get_flags_arch is not self.get_flags_arch_f77:
- f77flags += self.__get_flags(self.get_flags_arch_f77)
- if f90 and self.get_flags_arch is not self.get_flags_arch_f90:
- f90flags += self.__get_flags(self.get_flags_arch_f90)
- if fix and self.get_flags_arch is not self.get_flags_arch_f90:
- fixflags += self.__get_flags(self.get_flags_arch_f90)
+ get_flags('arch', aflags)
if debug:
- dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')
- if f77 and self.get_flags_debug is not self.get_flags_debug_f77:
- f77flags += self.__get_flags(self.get_flags_debug_f77)
- if f90 and self.get_flags_debug is not self.get_flags_debug_f90:
- f90flags += self.__get_flags(self.get_flags_debug_f90)
- if fix and self.get_flags_debug is not self.get_flags_debug_f90:
- fixflags += self.__get_flags(self.get_flags_debug_f90)
+ get_flags('debug', dflags)
- fflags = self.__get_flags(self.get_flags,'FFLAGS') \
- + dflags + oflags + aflags
+ fflags = to_list(self.flag_vars.flags) + dflags + oflags + aflags
if f77:
self.set_executables(compiler_f77=[f77]+f77flags+fflags)
@@ -329,30 +410,31 @@
self.set_executables(compiler_f90=[f90]+freeflags+f90flags+fflags)
if fix:
self.set_executables(compiler_fix=[fix]+fixflags+fflags)
+
#XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS
- linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')
+ linker_so = self.command_vars.linker_so
if linker_so:
- linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')
+ linker_so_flags = to_list(self.flag_vars.linker_so)
self.set_executables(linker_so=[linker_so]+linker_so_flags)
- linker_exe = self.__get_cmd(self.get_linker_exe,'LD')
+ linker_exe = self.command_vars.linker_exe
if linker_exe:
- linker_exe_flags = self.__get_flags(self.get_flags_linker_exe,'LDFLAGS')
+ linker_exe_flags = to_list(self.flag_vars.linker_exe)
self.set_executables(linker_exe=[linker_exe]+linker_exe_flags)
- ar = self.__get_cmd('archiver','AR')
+
+ ar = self.command_vars.archiver
if ar:
- arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')
+ arflags = to_list(self.flag_vars.arflags)
self.set_executables(archiver=[ar]+arflags)
- ranlib = self.__get_cmd('ranlib','RANLIB')
+ ranlib = self.command_vars.ranlib
if ranlib:
self.set_executables(ranlib=[ranlib])
self.set_library_dirs(self.get_library_dirs())
self.set_libraries(self.get_libraries())
-
- verbose = conf.get('verbose',[None,0])[1]
+ verbose = self.distutils_vars.get('verbose', self.verbose)
if verbose:
self.dump_properties()
return
@@ -365,7 +447,7 @@
'object_switch','compile_switch']:
if hasattr(self,key):
v = getattr(self,key)
- props.append((key, None, '= '+`v`))
+ props.append((key, None, '= '+repr(v)))
props.sort()
pretty_printer = FancyGetopt(props)
@@ -412,7 +494,8 @@
if os.name == 'nt':
compiler = _nt_quote_args(compiler)
- command = compiler + cc_args + extra_flags + s_args + o_args + extra_postargs
+ command = compiler + cc_args + extra_flags + s_args + o_args \
+ + extra_postargs
display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,
src)
@@ -495,153 +578,119 @@
log.debug("skipping %s (up-to-date)", output_filename)
return
-
- ## Private methods:
-
- def __get_cmd(self, command, envvar=None, confvar=None):
- if command is None:
- var = None
- elif is_string(command):
- var = self.executables[command]
- if var is not None:
- var = var[0]
+ def _environment_hook(self, name, hook_name):
+ if hook_name is None:
+ return None
+ if is_string(hook_name):
+ if hook_name.startswith('self.'):
+ hook_name = hook_name[5:]
+ hook = getattr(self, hook_name)
+ return hook()
+ elif hook_name.startswith('exe.'):
+ hook_name = hook_name[4:]
+ var = self.executables[hook_name]
+ if var:
+ return var[0]
+ else:
+ return None
+ elif hook_name.startswith('flags.'):
+ hook_name = hook_name[6:]
+ hook = getattr(self, 'get_flags_' + hook_name)
+ return hook()
else:
- var = command()
- if envvar is not None:
- var = os.environ.get(envvar, var)
- if confvar is not None:
- var = confvar[0].get(confvar[1], [None,var])[1]
- return var
+ return hook_name()
- def __get_flags(self, command, envvar=None, confvar=None):
- if command is None:
- var = []
- elif is_string(command):
- var = self.executables[command][1:]
- else:
- var = command()
- if envvar is not None:
- var = os.environ.get(envvar, var)
- if confvar is not None:
- var = confvar[0].get(confvar[1], [None,var])[1]
- if is_string(var):
- var = split_quoted(var)
- return var
-
## class FCompiler
-fcompiler_class = {'gnu':('gnu','GnuFCompiler',
- "GNU Fortran Compiler"),
- 'gnu95':('gnu','Gnu95FCompiler',
- "GNU 95 Fortran Compiler"),
- 'g95':('g95','G95FCompiler',
- "G95 Fortran Compiler"),
- 'pg':('pg','PGroupFCompiler',
- "Portland Group Fortran Compiler"),
- 'absoft':('absoft','AbsoftFCompiler',
- "Absoft Corp Fortran Compiler"),
- 'mips':('mips','MipsFCompiler',
- "MIPSpro Fortran Compiler"),
- 'sun':('sun','SunFCompiler',
- "Sun|Forte Fortran 95 Compiler"),
- 'intel':('intel','IntelFCompiler',
- "Intel Fortran Compiler for 32-bit apps"),
- 'intelv':('intel','IntelVisualFCompiler',
- "Intel Visual Fortran Compiler for 32-bit apps"),
- 'intele':('intel','IntelItaniumFCompiler',
- "Intel Fortran Compiler for Itanium apps"),
- 'intelev':('intel','IntelItaniumVisualFCompiler',
- "Intel Visual Fortran Compiler for Itanium apps"),
- 'intelem':('intel','IntelEM64TFCompiler',
- "Intel Fortran Compiler for EM64T-based apps"),
- 'nag':('nag','NAGFCompiler',
- "NAGWare Fortran 95 Compiler"),
- 'compaq':('compaq','CompaqFCompiler',
- "Compaq Fortran Compiler"),
- 'compaqv':('compaq','CompaqVisualFCompiler',
- "DIGITAL|Compaq Visual Fortran Compiler"),
- 'vast':('vast','VastFCompiler',
- "Pacific-Sierra Research Fortran 90 Compiler"),
- 'hpux':('hpux','HPUXFCompiler',
- "HP Fortran 90 Compiler"),
- 'lahey':('lahey','LaheyFCompiler',
- "Lahey/Fujitsu Fortran 95 Compiler"),
- 'ibm':('ibm','IbmFCompiler',
- "IBM XL Fortran Compiler"),
- 'f':('f','FFCompiler',
- "Fortran Company/NAG F Compiler"),
- 'none':('none','NoneFCompiler',"Fake Fortran compiler")
- }
-
_default_compilers = (
# Platform mappings
- ('win32',('gnu','intelv','absoft','compaqv','intelev','gnu95','g95')),
- ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev','gnu95','g95')),
- ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',
+ ('win32', ('gnu','intelv','absoft','compaqv','intelev','gnu95','g95')),
+ ('cygwin.*', ('gnu','intelv','absoft','compaqv','intelev','gnu95','g95')),
+ ('linux.*', ('gnu','intel','lahey','pg','absoft','nag','vast','compaq',
'intele','intelem','gnu95','g95')),
- ('darwin.*',('nag','absoft','ibm','gnu','gnu95','g95')),
- ('sunos.*',('sun','gnu','gnu95','g95')),
- ('irix.*',('mips','gnu','gnu95',)),
- ('aix.*',('ibm','gnu','gnu95',)),
+ ('darwin.*', ('nag', 'absoft', 'ibm', 'intel', 'gnu', 'gnu95', 'g95')),
+ ('sunos.*', ('sun','gnu','gnu95','g95')),
+ ('irix.*', ('mips','gnu','gnu95',)),
+ ('aix.*', ('ibm','gnu','gnu95',)),
# OS mappings
- ('posix',('gnu','gnu95',)),
- ('nt',('gnu','gnu95',)),
- ('mac',('gnu','gnu95',)),
+ ('posix', ('gnu','gnu95',)),
+ ('nt', ('gnu','gnu95',)),
+ ('mac', ('gnu','gnu95',)),
)
-def _find_existing_fcompiler(compilers, osname=None, platform=None):
+fcompiler_class = None
+
+def load_all_fcompiler_classes():
+ """Cache all the FCompiler classes found in modules in the
+ numpy.distutils.fcompiler package.
+ """
+ from glob import glob
+ global fcompiler_class
+ if fcompiler_class is not None:
+ return
+ pys = os.path.join(os.path.dirname(__file__), '*.py')
+ fcompiler_class = {}
+ for fname in glob(pys):
+ module_name, ext = os.path.splitext(os.path.basename(fname))
+ module_name = 'numpy.distutils.fcompiler.' + module_name
+ __import__ (module_name)
+ module = sys.modules[module_name]
+ if hasattr(module, 'compilers'):
+ for cname in module.compilers:
+ klass = getattr(module, cname)
+ fcompiler_class[klass.compiler_type] = (klass.compiler_type,
+ klass,
+ klass.description)
+
+def _find_existing_fcompiler(compiler_types, osname=None, platform=None):
+ from numpy.distutils.core import get_distribution
dist = get_distribution(always=True)
- for compiler in compilers:
+ for compiler_type in compiler_types:
v = None
try:
- c = new_fcompiler(plat=platform, compiler=compiler)
+ c = new_fcompiler(plat=platform, compiler=compiler_type)
c.customize(dist)
v = c.get_version()
except DistutilsModuleError:
pass
- except Exception, e:
- log.warn(str(e))
+ except CompilerNotFound:
+ pass
if v is not None:
- return compiler
- return
+ return compiler_type
+ return None
def get_default_fcompiler(osname=None, platform=None):
- """ Determine the default Fortran compiler to use for the given platform. """
+ """Determine the default Fortran compiler to use for the given platform."""
if osname is None:
osname = os.name
if platform is None:
platform = sys.platform
- matching_compilers = []
- for pattern, compiler in _default_compilers:
- if re.match(pattern, platform) is not None or \
- re.match(pattern, osname) is not None:
- if is_sequence(compiler):
- matching_compilers.extend(list(compiler))
- else:
- matching_compilers.append(compiler)
- if not matching_compilers:
- matching_compilers.append('gnu')
- compiler = _find_existing_fcompiler(matching_compilers,
- osname=osname,
- platform=platform)
- if compiler is not None:
- return compiler
- return matching_compilers[0]
+ 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))
+ if not matching_compiler_types:
+ matching_compiler_types.append('gnu')
+ compiler_type = _find_existing_fcompiler(matching_compiler_types,
+ osname=osname,
+ platform=platform)
+ return compiler_type
def new_fcompiler(plat=None,
compiler=None,
verbose=0,
dry_run=0,
force=0):
- """ Generate an instance of some FCompiler subclass for the supplied
+ """Generate an instance of some FCompiler subclass for the supplied
platform/compiler combination.
"""
+ load_all_fcompiler_classes()
if plat is None:
plat = os.name
+ if compiler is None:
+ compiler = get_default_fcompiler(plat)
try:
- if compiler is None:
- compiler = get_default_fcompiler(plat)
- (module_name, class_name, long_description) = fcompiler_class[compiler]
+ module_name, klass, long_description = fcompiler_class[compiler]
except KeyError:
msg = "don't know how to compile Fortran code on platform '%s'" % plat
if compiler is not None:
@@ -650,29 +699,16 @@
% (','.join(fcompiler_class.keys()))
raise DistutilsPlatformError, msg
- try:
- module_name = 'numpy.distutils.fcompiler.'+module_name
- __import__ (module_name)
- module = sys.modules[module_name]
- klass = vars(module)[class_name]
- except ImportError:
- raise DistutilsModuleError, \
- "can't compile Fortran code: unable to load module '%s'" % \
- module_name
- except KeyError:
- raise DistutilsModuleError, \
- ("can't compile Fortran code: unable to find class '%s' " +
- "in module '%s'") % (class_name, module_name)
- compiler = klass(None, dry_run, force)
- log.debug('new_fcompiler returns %s' % (klass))
+ compiler = klass(verbose=verbose, dry_run=dry_run, force=force)
return compiler
def show_fcompilers(dist = None):
- """ Print list of available compilers (used by the "--help-fcompiler"
+ """Print list of available compilers (used by the "--help-fcompiler"
option to "config_fc").
"""
if dist is None:
from distutils.dist import Distribution
+ from numpy.distutils.command.config_compiler import config_fc
dist = Distribution()
dist.script_name = os.path.basename(sys.argv[0])
dist.script_args = ['config_fc'] + sys.argv[1:]
@@ -683,20 +719,21 @@
compilers = []
compilers_na = []
compilers_ni = []
+ if not fcompiler_class:
+ load_all_fcompiler_classes()
+ not_available = object()
for compiler in fcompiler_class.keys():
- v = 'N/A'
+ v = not_available
try:
- c = new_fcompiler(compiler=compiler)
+ c = new_fcompiler(compiler=compiler, verbose=dist.verbose)
c.customize(dist)
v = c.get_version()
- except DistutilsModuleError:
- pass
- except Exception, msg:
- log.warn(msg)
+ except (DistutilsModuleError, CompilerNotFound):
+ v = not_available
if v is None:
compilers_na.append(("fcompiler="+compiler, None,
fcompiler_class[compiler][2]))
- elif v=='N/A':
+ elif v is not_available:
compilers_ni.append(("fcompiler="+compiler, None,
fcompiler_class[compiler][2]))
else:
@@ -705,6 +742,7 @@
compilers.sort()
compilers_na.sort()
+ compilers_ni.sort()
pretty_printer = FancyGetopt(compilers)
pretty_printer.print_help("List of available Fortran compilers:")
pretty_printer = FancyGetopt(compilers_na)
Modified: branches/distutils-revamp/fcompiler/absoft.py
===================================================================
--- branches/distutils-revamp/fcompiler/absoft.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/absoft.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -13,9 +13,12 @@
from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
from numpy.distutils.misc_util import cyg2win32
+compilers = ['AbsoftFCompiler']
+
class AbsoftFCompiler(FCompiler):
compiler_type = 'absoft'
+ description = 'Absoft Corp Fortran Compiler'
#version_pattern = r'FORTRAN 77 Compiler (?P<version>[^\s*,]*).*?Absoft Corp'
version_pattern = r'(f90:.*?(Absoft Pro FORTRAN Version|FORTRAN 77 Compiler|Absoft Fortran Compiler Version|Copyright Absoft Corporation.*?Version))'+\
r' (?P<version>[^\s*,]*)(.*?Absoft Corp|)'
@@ -28,12 +31,12 @@
# Note that fink installs g77 as f77, so need to use f90 for detection.
executables = {
- 'version_cmd' : ["f90", "-V -c %(fname)s.f -o %(fname)s.o" \
+ 'version_cmd' : ["<F90>", "-V -c %(fname)s.f -o %(fname)s.o" \
% {'fname':cyg2win32(dummy_fortran_file())}],
'compiler_f77' : ["f77"],
'compiler_fix' : ["f90"],
'compiler_f90' : ["f90"],
- 'linker_so' : ["f90"],
+ 'linker_so' : ["<F90>"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
Modified: branches/distutils-revamp/fcompiler/compaq.py
===================================================================
--- branches/distutils-revamp/fcompiler/compaq.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/compaq.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -7,9 +7,17 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
+compilers = ['CompaqFCompiler']
+if os.name != 'posix':
+ # Otherwise we'd get a false positive on posix systems with
+ # case-insensitive filesystems (like darwin), because we'll pick
+ # up /bin/df
+ compilers.append('CompaqVisualFCompiler')
+
class CompaqFCompiler(FCompiler):
compiler_type = 'compaq'
+ description = 'Compaq Fortran Compiler'
version_pattern = r'Compaq Fortran (?P<version>[^\s]*).*'
if sys.platform[:5]=='linux':
@@ -18,11 +26,11 @@
fc_exe = 'f90'
executables = {
- 'version_cmd' : [fc_exe, "-version"],
+ 'version_cmd' : ['<F90>', "-version"],
'compiler_f77' : [fc_exe, "-f77rtl","-fixed"],
'compiler_fix' : [fc_exe, "-fixed"],
'compiler_f90' : [fc_exe],
- 'linker_so' : [fc_exe],
+ 'linker_so' : ['<F90>'],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
@@ -47,6 +55,7 @@
class CompaqVisualFCompiler(FCompiler):
compiler_type = 'compaqv'
+ description = 'DIGITAL or Compaq Visual Fortran Compiler'
version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\
' Version (?P<version>[^\s]*).*'
@@ -68,11 +77,11 @@
ar_exe = m.lib
executables = {
- 'version_cmd' : ['DF', "/what"],
- 'compiler_f77' : ['DF', "/f77rtl","/fixed"],
- 'compiler_fix' : ['DF', "/fixed"],
- 'compiler_f90' : ['DF'],
- 'linker_so' : ['DF'],
+ 'version_cmd' : ['<F90>', "/what"],
+ 'compiler_f77' : [fc_exe, "/f77rtl","/fixed"],
+ 'compiler_fix' : [fc_exe, "/fixed"],
+ 'compiler_f90' : [fc_exe],
+ 'linker_so' : ['<F90>'],
'archiver' : [ar_exe, "/OUT:"],
'ranlib' : None
}
Modified: branches/distutils-revamp/fcompiler/g95.py
===================================================================
--- branches/distutils-revamp/fcompiler/g95.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/g95.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -6,20 +6,23 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
+compilers = ['G95FCompiler']
+
class G95FCompiler(FCompiler):
compiler_type = 'g95'
+ description = 'G95 Fortran Compiler'
version_pattern = r'G95 \((GCC (?P<gccversion>[\d.]+)|.*?) \(g95!\) (?P<version>.*)\).*'
# $ g95 --version
# G95 (GCC 4.0.3 (g95!) May 22 2006)
executables = {
- 'version_cmd' : ["g95", "--version"],
+ 'version_cmd' : ["<F90>", "--version"],
'compiler_f77' : ["g95", "-ffixed-form"],
'compiler_fix' : ["g95", "-ffixed-form"],
'compiler_f90' : ["g95"],
- 'linker_so' : ["g95","-shared"],
+ 'linker_so' : ["<F90>","-shared"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
Modified: branches/distutils-revamp/fcompiler/gnu.py
===================================================================
--- branches/distutils-revamp/fcompiler/gnu.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/gnu.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -7,12 +7,15 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.ccompiler import simple_version_match
from numpy.distutils.fcompiler import FCompiler
-from numpy.distutils.exec_command import exec_command, find_executable
+from numpy.distutils.exec_command import exec_command
from numpy.distutils.misc_util import mingw32, msvc_runtime_library
+compilers = ['GnuFCompiler', 'Gnu95FCompiler']
+
class GnuFCompiler(FCompiler):
compiler_type = 'gnu'
+ description = 'GNU Fortran Compiler'
version_match = simple_version_match(start=r'GNU Fortran (?!95)')
# 'g77 --version' results
@@ -22,25 +25,23 @@
# GNU Fortran 0.5.25 20010319 (prerelease)
# Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
- for fc_exe in map(find_executable,['g77','f77']):
- if os.path.isfile(fc_exe):
- break
+ possible_executables = ['g77', 'f77']
executables = {
- 'version_cmd' : [fc_exe,"--version"],
- 'compiler_f77' : [fc_exe, "-g", "-Wall","-fno-second-underscore"],
+ 'version_cmd' : [None, "--version"],
+ 'compiler_f77' : [None, "-g", "-Wall","-fno-second-underscore"],
'compiler_f90' : None,
'compiler_fix' : None,
- 'linker_so' : [fc_exe, "-g", "-Wall"],
+ 'linker_so' : [None, "-g", "-Wall"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"],
- 'linker_exe' : [fc_exe, "-g", "-Wall"]
+ 'linker_exe' : [None, "-g", "-Wall"]
}
module_dir_switch = None
module_include_switch = None
# Cygwin: f771: warning: -fPIC ignored for target (all code is
# position independent)
- if os.name != 'nt' and sys.platform!='cygwin':
+ if os.name != 'nt' and sys.platform != 'cygwin':
pic_flags = ['-fPIC']
# use -mno-cygwin for g77 when Python is not Cygwin-Python
@@ -59,10 +60,8 @@
def get_flags_linker_so(self):
opt = self.linker_so[1:]
- if sys.platform=='darwin':
- target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)
- if target is None:
- target = '10.3'
+ if sys.platform == 'darwin':
+ target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', '10.3')
major, minor = target.split('.')
if int(minor) < 3:
minor = '3'
@@ -74,7 +73,7 @@
opt.extend(['-undefined', 'dynamic_lookup', '-bundle'])
else:
opt.append("-shared")
- if sys.platform[:5]=='sunos':
+ if sys.platform.startswith('sunos'):
# SunOS often has dynamically loaded symbols defined in the
# static library libg2c.a The linker doesn't like this. To
# ignore the problem, use the -mimpure-text flag. It isn't
@@ -146,13 +145,10 @@
def get_flags_arch(self):
opt = []
- if sys.platform=='darwin':
- if os.name != 'posix':
- # this should presumably correspond to Apple
- if cpu.is_ppc():
- opt.append('-arch ppc')
- elif cpu.is_i386():
- opt.append('-arch i386')
+ if sys.platform == 'darwin':
+ # Since Apple doesn't distribute a GNU Fortran compiler, we
+ # can't add -arch ppc or -arch i386, as only their version
+ # of the GNU compilers accepts those.
for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\
'403 505 801 821 823 860'.split():
if getattr(cpu,'is_ppc%s'%a)():
@@ -238,6 +234,7 @@
class Gnu95FCompiler(GnuFCompiler):
compiler_type = 'gnu95'
+ description = 'GNU 95 Fortran Compiler'
version_match = simple_version_match(start='GNU Fortran 95')
# 'gfortran --version' results:
@@ -245,18 +242,16 @@
# OS X: GNU Fortran 95 (GCC) 4.1.0
# GNU Fortran 95 (GCC) 4.2.0 20060218 (experimental)
- for fc_exe in map(find_executable,['gfortran','f95']):
- if os.path.isfile(fc_exe):
- break
+ possible_executables = ['gfortran', 'f95']
executables = {
- 'version_cmd' : [fc_exe,"--version"],
- 'compiler_f77' : [fc_exe,"-Wall","-ffixed-form","-fno-second-underscore"],
- 'compiler_f90' : [fc_exe,"-Wall","-fno-second-underscore"],
- 'compiler_fix' : [fc_exe,"-Wall","-ffixed-form","-fno-second-underscore"],
- 'linker_so' : [fc_exe,"-Wall"],
+ 'version_cmd' : ["<F90>", "--version"],
+ 'compiler_f77' : [None, "-Wall", "-ffixed-form", "-fno-second-underscore"],
+ 'compiler_f90' : [None, "-Wall", "-fno-second-underscore"],
+ 'compiler_fix' : [None, "-Wall", "-ffixed-form", "-fno-second-underscore"],
+ 'linker_so' : ["<F90>", "-Wall"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"],
- 'linker_exe' : [fc_exe,"-Wall"]
+ 'linker_exe' : [None,"-Wall"]
}
# use -mno-cygwin flag for g77 when Python is not Cygwin-Python
@@ -273,7 +268,7 @@
def get_libraries(self):
opt = GnuFCompiler.get_libraries(self)
if sys.platform == 'darwin':
- opt.remove('cc_dynamic')
+ opt.remove('cc_dynamic')
return opt
if __name__ == '__main__':
Modified: branches/distutils-revamp/fcompiler/hpux.py
===================================================================
--- branches/distutils-revamp/fcompiler/hpux.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/hpux.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -4,13 +4,16 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
+compilers = ['HPUXFCompiler']
+
class HPUXFCompiler(FCompiler):
compiler_type = 'hpux'
+ description = 'HP Fortran 90 Compiler'
version_pattern = r'HP F90 (?P<version>[^\s*,]*)'
executables = {
- 'version_cmd' : ["f90", "+version"],
+ 'version_cmd' : ["<F90>", "+version"],
'compiler_f77' : ["f90"],
'compiler_fix' : ["f90"],
'compiler_f90' : ["f90"],
Modified: branches/distutils-revamp/fcompiler/ibm.py
===================================================================
--- branches/distutils-revamp/fcompiler/ibm.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/ibm.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -5,13 +5,16 @@
from numpy.distutils.fcompiler import FCompiler
from distutils import log
-class IbmFCompiler(FCompiler):
+compilers = ['IBMFCompiler']
+class IBMFCompiler(FCompiler):
+
compiler_type = 'ibm'
+ description = 'IBM XL Fortran Compiler'
version_pattern = r'xlf\(1\)\s*IBM XL Fortran (Advanced Edition |)Version (?P<version>[^\s*]*)'
executables = {
- 'version_cmd' : ["xlf"],
+ 'version_cmd' : ["<F77>"],
'compiler_f77' : ["xlf"],
'compiler_fix' : ["xlf90", "-qfixed"],
'compiler_f90' : ["xlf90"],
Modified: branches/distutils-revamp/fcompiler/intel.py
===================================================================
--- branches/distutils-revamp/fcompiler/intel.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/intel.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -5,25 +5,28 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
-from numpy.distutils.exec_command import find_executable
+compilers = ['IntelFCompiler', 'IntelVisualFCompiler',
+ 'IntelItaniumFCompiler', 'IntelItaniumVisualFCompiler',
+ 'IntelEM64TFCompiler']
+
class IntelFCompiler(FCompiler):
compiler_type = 'intel'
+ description = 'Intel Fortran Compiler for 32-bit apps'
version_pattern = r'Intel\(R\) Fortran Compiler for 32-bit '\
'applications, Version (?P<version>[^\s*]*)'
- for fc_exe in map(find_executable,['ifort','ifc']):
- if os.path.isfile(fc_exe):
- break
+ possible_executables = ['ifort', 'ifc']
+
executables = {
- 'version_cmd' : [fc_exe, "-FI -V -c %(fname)s.f -o %(fname)s.o" \
+ 'version_cmd' : ["<F77>", "-FI -V -c %(fname)s.f -o %(fname)s.o" \
% {'fname':dummy_fortran_file()}],
- 'compiler_f77' : [fc_exe,"-72","-w90","-w95"],
- 'compiler_fix' : [fc_exe,"-FI"],
- 'compiler_f90' : [fc_exe],
- 'linker_so' : [fc_exe,"-shared"],
+ 'compiler_f77' : [None,"-72","-w90","-w95"],
+ 'compiler_f90' : [None],
+ 'compiler_fix' : [None,"-FI"],
+ 'linker_so' : ["<F90>","-shared"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
@@ -74,42 +77,40 @@
class IntelItaniumFCompiler(IntelFCompiler):
compiler_type = 'intele'
+ description = 'Intel Fortran Compiler for Itanium apps'
version_pattern = r'Intel\(R\) Fortran 90 Compiler Itanium\(TM\) Compiler'\
' for the Itanium\(TM\)-based applications,'\
' Version (?P<version>[^\s*]*)'
- for fc_exe in map(find_executable,['ifort','efort','efc']):
- if os.path.isfile(fc_exe):
- break
+ possible_executables = ['ifort', 'efort', 'efc']
executables = {
- 'version_cmd' : [fc_exe, "-FI -V -c %(fname)s.f -o %(fname)s.o" \
+ 'version_cmd' : ['<F77>', "-FI -V -c %(fname)s.f -o %(fname)s.o" \
% {'fname':dummy_fortran_file()}],
- 'compiler_f77' : [fc_exe,"-FI","-w90","-w95"],
- 'compiler_fix' : [fc_exe,"-FI"],
- 'compiler_f90' : [fc_exe],
- 'linker_so' : [fc_exe,"-shared"],
+ 'compiler_f77' : [None,"-FI","-w90","-w95"],
+ 'compiler_fix' : [None,"-FI"],
+ 'compiler_f90' : [None],
+ 'linker_so' : ['<F90>', "-shared"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
class IntelEM64TFCompiler(IntelFCompiler):
compiler_type = 'intelem'
+ description = 'Intel Fortran Compiler for EM64T-based apps'
version_pattern = r'Intel\(R\) Fortran Compiler for Intel\(R\) EM64T-based '\
'applications, Version (?P<version>[^\s*]*)'
- for fc_exe in map(find_executable,['ifort','efort','efc']):
- if os.path.isfile(fc_exe):
- break
+ possible_executables = ['ifort', 'efort', 'efc']
executables = {
- 'version_cmd' : [fc_exe, "-FI -V -c %(fname)s.f -o %(fname)s.o" \
+ 'version_cmd' : ['<F77>', "-FI -V -c %(fname)s.f -o %(fname)s.o" \
% {'fname':dummy_fortran_file()}],
- 'compiler_f77' : [fc_exe,"-FI","-w90","-w95"],
- 'compiler_fix' : [fc_exe,"-FI"],
- 'compiler_f90' : [fc_exe],
- 'linker_so' : [fc_exe,"-shared"],
+ 'compiler_f77' : [None, "-FI", "-w90", "-w95"],
+ 'compiler_fix' : [None, "-FI"],
+ 'compiler_f90' : [None],
+ 'linker_so' : ['<F90>', "-shared"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
@@ -123,6 +124,7 @@
class IntelVisualFCompiler(FCompiler):
compiler_type = 'intelv'
+ description = 'Intel Visual Fortran Compiler for 32-bit apps'
version_pattern = r'Intel\(R\) Fortran Compiler for 32-bit applications, '\
'Version (?P<version>[^\s*]*)'
@@ -133,12 +135,12 @@
ar_exe = MSVCCompiler().lib
executables = {
- 'version_cmd' : [fc_exe, "-FI -V -c %(fname)s.f -o %(fname)s.o" \
+ 'version_cmd' : ['<F77>', "-FI -V -c %(fname)s.f -o %(fname)s.o" \
% {'fname':dummy_fortran_file()}],
'compiler_f77' : [fc_exe,"-FI","-w90","-w95"],
'compiler_fix' : [fc_exe,"-FI","-4L72","-w"],
'compiler_f90' : [fc_exe],
- 'linker_so' : [fc_exe,"-shared"],
+ 'linker_so' : ['<F90>', "-shared"],
'archiver' : [ar_exe, "/verbose", "/OUT:"],
'ranlib' : None
}
@@ -179,6 +181,7 @@
class IntelItaniumVisualFCompiler(IntelVisualFCompiler):
compiler_type = 'intelev'
+ description = 'Intel Visual Fortran Compiler for Itanium apps'
version_pattern = r'Intel\(R\) Fortran 90 Compiler Itanium\(TM\) Compiler'\
' for the Itanium\(TM\)-based applications,'\
' Version (?P<version>[^\s*]*)'
@@ -187,12 +190,12 @@
ar_exe = IntelVisualFCompiler.ar_exe
executables = {
- 'version_cmd' : [fc_exe, "-FI -V -c %(fname)s.f -o %(fname)s.o" \
+ 'version_cmd' : ['<F77>', "-FI -V -c %(fname)s.f -o %(fname)s.o" \
% {'fname':dummy_fortran_file()}],
'compiler_f77' : [fc_exe,"-FI","-w90","-w95"],
'compiler_fix' : [fc_exe,"-FI","-4L72","-w"],
'compiler_f90' : [fc_exe],
- 'linker_so' : [fc_exe,"-shared"],
+ 'linker_so' : ['<F90>',"-shared"],
'archiver' : [ar_exe, "/verbose", "/OUT:"],
'ranlib' : None
}
Modified: branches/distutils-revamp/fcompiler/lahey.py
===================================================================
--- branches/distutils-revamp/fcompiler/lahey.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/lahey.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -4,13 +4,16 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
+compilers = ['LaheyFCompiler']
+
class LaheyFCompiler(FCompiler):
compiler_type = 'lahey'
+ description = 'Lahey/Fujitsu Fortran 95 Compiler'
version_pattern = r'Lahey/Fujitsu Fortran 95 Compiler Release (?P<version>[^\s*]*)'
executables = {
- 'version_cmd' : ["lf95", "--version"],
+ 'version_cmd' : ["<F90>", "--version"],
'compiler_f77' : ["lf95", "--fix"],
'compiler_fix' : ["lf95", "--fix"],
'compiler_f90' : ["lf95"],
Modified: branches/distutils-revamp/fcompiler/mips.py
===================================================================
--- branches/distutils-revamp/fcompiler/mips.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/mips.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -4,13 +4,16 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
-class MipsFCompiler(FCompiler):
+compilers = ['MIPSFCompiler']
+class MIPSFCompiler(FCompiler):
+
compiler_type = 'mips'
+ description = 'MIPSpro Fortran Compiler'
version_pattern = r'MIPSpro Compilers: Version (?P<version>[^\s*,]*)'
executables = {
- 'version_cmd' : ["f90", "-version"],
+ 'version_cmd' : ["<F90>", "-version"],
'compiler_f77' : ["f77", "-f77"],
'compiler_fix' : ["f90", "-fixedform"],
'compiler_f90' : ["f90"],
Modified: branches/distutils-revamp/fcompiler/nag.py
===================================================================
--- branches/distutils-revamp/fcompiler/nag.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/nag.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -4,17 +4,20 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
+compilers = ['NAGFCompiler']
+
class NAGFCompiler(FCompiler):
compiler_type = 'nag'
+ description = 'NAGWare Fortran 95 Compiler'
version_pattern = r'NAGWare Fortran 95 compiler Release (?P<version>[^\s]*)'
executables = {
- 'version_cmd' : ["f95", "-V"],
+ 'version_cmd' : ["<F90>", "-V"],
'compiler_f77' : ["f95", "-fixed"],
'compiler_fix' : ["f95", "-fixed"],
'compiler_f90' : ["f95"],
- 'linker_so' : ["f95"],
+ 'linker_so' : ["<F90>"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
Modified: branches/distutils-revamp/fcompiler/none.py
===================================================================
--- branches/distutils-revamp/fcompiler/none.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/none.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -1,20 +1,27 @@
from numpy.distutils.fcompiler import FCompiler
+compilers = ['NoneFCompiler']
+
class NoneFCompiler(FCompiler):
compiler_type = 'none'
+ description = 'Fake Fortran compiler'
- executables = {'compiler_f77':['/path/to/nowhere/none'],
- 'compiler_f90':['/path/to/nowhere/none'],
- 'compiler_fix':['/path/to/nowhere/none'],
- 'linker_so':['/path/to/nowhere/none'],
- 'archiver':['/path/to/nowhere/none'],
- 'ranlib':['/path/to/nowhere/none'],
- 'version_cmd':['/path/to/nowhere/none'],
+ executables = {'compiler_f77' : None,
+ 'compiler_f90' : None,
+ 'compiler_fix' : None,
+ 'linker_so' : None,
+ 'linker_exe' : None,
+ 'archiver' : None,
+ 'ranlib' : None,
+ 'version_cmd' : None,
}
+ def find_executables(self):
+ pass
+
if __name__ == '__main__':
from distutils import log
log.set_verbosity(2)
Modified: branches/distutils-revamp/fcompiler/pg.py
===================================================================
--- branches/distutils-revamp/fcompiler/pg.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/pg.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -7,13 +7,16 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler import FCompiler
+compilers = ['PGroupFCompiler']
+
class PGroupFCompiler(FCompiler):
compiler_type = 'pg'
+ description = 'Portland Group Fortran Compiler'
version_pattern = r'\s*pg(f77|f90|hpf) (?P<version>[\d.-]+).*'
executables = {
- 'version_cmd' : ["pgf77", "-V 2>/dev/null"],
+ 'version_cmd' : ["<F77>", "-V 2>/dev/null"],
'compiler_f77' : ["pgf77"],
'compiler_fix' : ["pgf90", "-Mfixed"],
'compiler_f90' : ["pgf90"],
Modified: branches/distutils-revamp/fcompiler/sun.py
===================================================================
--- branches/distutils-revamp/fcompiler/sun.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/sun.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -5,20 +5,23 @@
from numpy.distutils.ccompiler import simple_version_match
from numpy.distutils.fcompiler import FCompiler
+compilers = ['SunFCompiler']
+
class SunFCompiler(FCompiler):
compiler_type = 'sun'
+ description = 'Sun or Forte Fortran 95 Compiler'
# ex:
# f90: Sun WorkShop 6 update 2 Fortran 95 6.2 Patch 111690-10 2003/08/28
version_match = simple_version_match(
start=r'f9[05]: (Sun|Forte|WorkShop).*Fortran 95')
executables = {
- 'version_cmd' : ["f90", "-V"],
+ 'version_cmd' : ["<F90>", "-V"],
'compiler_f77' : ["f90"],
'compiler_fix' : ["f90", "-fixed"],
'compiler_f90' : ["f90"],
- 'linker_so' : ["f90","-Bdynamic","-G"],
+ 'linker_so' : ["<F90>","-Bdynamic","-G"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
Modified: branches/distutils-revamp/fcompiler/vast.py
===================================================================
--- branches/distutils-revamp/fcompiler/vast.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/fcompiler/vast.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -4,9 +4,12 @@
from numpy.distutils.cpuinfo import cpu
from numpy.distutils.fcompiler.gnu import GnuFCompiler
+compilers = ['VastFCompiler']
+
class VastFCompiler(GnuFCompiler):
compiler_type = 'vast'
+ description = 'Pacific-Sierra Research Fortran 90 Compiler'
version_pattern = r'\s*Pacific-Sierra Research vf90 '\
'(Personal|Professional)\s+(?P<version>[^\s]*)'
@@ -19,7 +22,7 @@
'compiler_f77' : ["g77"],
'compiler_fix' : ["f90", "-Wv,-ya"],
'compiler_f90' : ["f90"],
- 'linker_so' : ["f90"],
+ 'linker_so' : ["<F90>"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"]
}
@@ -28,8 +31,8 @@
def get_version_cmd(self):
f90 = self.compiler_f90[0]
- d,b = os.path.split(f90)
- vf90 = os.path.join(d,'v'+b)
+ d, b = os.path.split(f90)
+ vf90 = os.path.join(d, 'v'+b)
return vf90
def get_flags_arch(self):
Modified: branches/distutils-revamp/intelccompiler.py
===================================================================
--- branches/distutils-revamp/intelccompiler.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/intelccompiler.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -26,5 +26,5 @@
# On Itanium, the Intel Compiler used to be called ecc, let's search for
# it (now it's also icc, so ecc is last in the search).
for cc_exe in map(find_executable,['icc','ecc']):
- if os.path.isfile(cc_exe):
+ if cc_exe:
break
Modified: branches/distutils-revamp/system_info.py
===================================================================
--- branches/distutils-revamp/system_info.py 2006-08-02 20:44:43 UTC (rev 2945)
+++ branches/distutils-revamp/system_info.py 2006-08-03 02:42:25 UTC (rev 2946)
@@ -1621,7 +1621,7 @@
def calc_info(self):
config_exe = find_executable(self.get_config_exe())
- if not os.path.isfile(config_exe):
+ if not config_exe:
log.warn('File not found: %s. Cannot determine %s info.' \
% (config_exe, self.section))
return
More information about the Numpy-svn
mailing list