Skip to content
Browse files

Introduced run_f2py command; fixed a minor bug in cpuinfo about detec…

…ting i(5|6)86
  • Loading branch information...
1 parent 323b6b4 commit dda06dcb6c3b3b7c21eb5a41518b9a237345bef3 @pearu pearu committed Jan 9, 2002
View
5 scipy_distutils/command/build.py
@@ -8,10 +8,13 @@
class build(old_build):
def has_f_libraries(self):
return self.distribution.has_f_libraries()
+ def has_f2py_sources(self):
+ return self.distribution.has_f2py_sources()
sub_commands = [('build_py', old_build.has_pure_modules),
('build_clib', old_build.has_c_libraries),
- ('build_flib', has_f_libraries), # new feature
+ ('run_f2py', has_f2py_sources), # new feature
+ ('build_flib', has_f_libraries), # new feature
('build_ext', old_build.has_ext_modules),
('build_scripts', old_build.has_scripts),
]
View
8 scipy_distutils/command/build_ext.py
@@ -81,6 +81,8 @@ def build_extension(self, ext):
if linker_so is not None:
self.compiler.linker_so = linker_so
# end of fortran source support
+ return old_build_ext.build_extension(self,ext)
+
# f2py support handled slightly_modified..._extenstion.
return self.slightly_modified_standard_build_extension(ext)
@@ -266,8 +268,10 @@ def f2py_sources (self, sources, ext):
if newer(source,target):
self.announce("f2py-ing %s to %s" % (source, target))
self.announce("f2py-args: %s" % f2py_options)
- f2py2e.run_main(f2py_opts + [source])
-
+ f2py2e.run_main(f2py_opts + [source])
+ #ext.sources.extend(pyf.data[ext.name].get('fsrc') or [])
+ #self.distribution.fortran_sources_to_flib(ext)
+ print new_sources
return new_sources
# f2py_sources ()
View
4 scipy_distutils/command/cpuinfo.py
@@ -107,10 +107,10 @@ def _is_i486(self):
return self.info[0]['cpu']=='i486'
def _is_i586(self):
- return self.is_Intel() and self.info[0]['model'] == '5'
+ return self.is_Intel() and self.info[0]['cpu family'] == '5'
def _is_i686(self):
- return self.is_Intel() and self.info[0]['model'] == '6'
+ return self.is_Intel() and self.info[0]['cpu family'] == '6'
def _is_Celeron(self):
return re.match(r'.*?Celeron',
View
148 scipy_distutils/command/run_f2py.py
@@ -0,0 +1,148 @@
+"""distutils.command.run_f2py
+
+Implements the Distutils 'run_f2py' command.
+"""
+
+# created 2002/01/09, Pearu Peterson
+
+__revision__ = "$Id$"
+
+from distutils.dep_util import newer
+from scipy_distutils.core import Command
+
+import re,os
+
+module_name_re = re.compile(r'\s*python\s*module\s*(?P<name>[\w_]+)',re.I).match
+
+class run_f2py(Command):
+
+ description = "\"run_f2py\" runs f2py that builds Fortran wrapper sources"\
+ "(C and occasionally Fortran)."
+
+ user_options = [('build-dir=', 'b',
+ "directory to build fortran wrappers to"),
+ ('debug-capi', None,
+ "generate C/API extensions with debugging code"),
+ ('force', 'f',
+ "forcibly build everything (ignore file timestamps)"),
+ ]
+
+ def initialize_options (self):
+ self.build_dir = None
+ self.debug_capi = None
+ self.force = None
+ self.f2py_options = []
+ # initialize_options()
+
+
+ def finalize_options (self):
+ self.set_undefined_options('build',
+ ('build_temp', 'build_dir'),
+ ('force', 'force'))
+
+ self.f2py_options.extend(['--build-dir',self.build_dir])
+
+ if self.debug_capi is not None:
+ self.f2py_options.append('--debug-capi')
+
+ # finalize_options()
+
+ def run (self):
+ if self.distribution.has_ext_modules():
+ for ext in self.distribution.ext_modules:
+ ext.sources = self.f2py_sources(ext.sources,ext)
+ self.distribution.fortran_sources_to_flib(ext)
+ # run()
+
+ def f2py_sources (self, sources, ext):
+
+ """Walk the list of source files in 'sources', looking for f2py
+ interface (.pyf) files. Run f2py on all that are found, and
+ return a modified 'sources' list with f2py source files replaced
+ by the generated C (or C++) and Fortran files.
+ """
+
+ import f2py2e
+ # f2py generates the following files for an extension module
+ # with a name <modulename>:
+ # <modulename>module.c
+ # <modulename>-f2pywrappers.f [occasionally]
+ # In addition, <f2py2e-dir>/src/fortranobject.{c,h} are needed
+ # for building f2py generated extension modules.
+ # It is assumed that one pyf file contains defintions for exactly
+ # one extension module.
+
+ new_sources = []
+ f2py_sources = []
+ f2py_targets = {}
+ f2py_fortran_targets = {}
+
+ # XXX this drops generated C/C++ files into the source tree, which
+ # is fine for developers who want to distribute the generated
+ # source -- but there should be an option to put f2py output in
+ # the temp dir.
+
+ target_ext = 'module.c'
+ fortran_target_ext = '-f2pywrappers.f'
+ target_dir = self.build_dir
+ print 'target_dir', target_dir
+
+ for source in sources:
+ (base, source_ext) = os.path.splitext(source)
+ (source_dir, base) = os.path.split(base)
+ if source_ext == ".pyf": # f2py interface file
+ # get extension module name
+ f = open(source)
+ for line in f.xreadlines():
+ m = module_name_re(line)
+ if m:
+ base = m.group('name')
+ break
+ f.close()
+ if base != ext.name:
+ # XXX: Should we do here more than just warn?
+ self.warn('%s provides %s but this extension is %s' \
+ % (source,`base`,`ext`))
+
+ target_file = os.path.join(target_dir,base+target_ext)
+ fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)
+ f2py_sources.append(source)
+ f2py_targets[source] = target_file
+ f2py_fortran_targets[source] = fortran_target_file
+ else:
+ new_sources.append(source)
+
+ if not f2py_sources:
+ return new_sources
+
+ # a bit of a hack, but I think it'll work. Just include one of
+ # the fortranobject.c files that was copied into most
+ d = os.path.dirname(f2py2e.__file__)
+ new_sources.append(os.path.join(d,'src','fortranobject.c'))
+ ext.include_dirs.append(os.path.join(d,'src'))
+
+ f2py_options = []
+ for i in ext.f2py_options:
+ f2py_opts.append('--'+i) # XXX: ???
+ f2py_options = self.f2py_options + f2py_options
+
+ # make sure the target dir exists
+ from distutils.dir_util import mkpath
+ mkpath(target_dir)
+
+ for source in f2py_sources:
+ target = f2py_targets[source]
+ fortran_target = f2py_fortran_targets[source]
+ if newer(source,target) or self.force:
+ self.announce("f2py-ing %s to %s" % (source, target))
+ self.announce("f2py-args: %s" % f2py_options)
+ f2py2e.run_main(f2py_options + [source])
+ new_sources.append(target)
+ if os.path.exists(fortran_target):
+ new_sources.append(fortran_target)
+
+ print new_sources
+ return new_sources
+ # f2py_sources ()
+
+# class x
View
2 scipy_distutils/core.py
@@ -12,6 +12,7 @@
from scipy_distutils.command import build_ext
from scipy_distutils.command import build_clib
from scipy_distutils.command import build_flib
+from scipy_distutils.command import run_f2py
from scipy_distutils.command import sdist
from scipy_distutils.command import install_data
from scipy_distutils.command import install
@@ -24,6 +25,7 @@ def setup(**attr):
'build_ext': build_ext.build_ext,
'build_py': build_py.build_py,
'build_clib': build_clib.build_clib,
+ 'run_f2py': run_f2py.run_f2py,
'sdist': sdist.sdist,
'install_data': install_data.install_data,
'install': install.install,
View
11 scipy_distutils/dist.py
@@ -8,10 +8,21 @@ class Distribution (OldDistribution):
def __init__ (self, attrs=None):
self.fortran_libraries = None
OldDistribution.__init__(self, attrs)
+
+ def has_f2py_sources (self):
+ if self.has_ext_modules():
+ for ext in self.ext_modules:
+ for source in ext.sources:
+ (base, file_ext) = os.path.splitext(source)
+ if file_ext == ".pyf": # f2py interface file
+ return 1
+ return 0
def has_f_libraries(self):
if self.fortran_libraries and len(self.fortran_libraries) > 0:
return 1
+ return self.has_f2py_sources() # f2py might generate fortran sources.
+
if hasattr(self,'_been_here_has_f_libraries'):
return 0
if self.has_ext_modules():

0 comments on commit dda06dc

Please sign in to comment.
Something went wrong with that request. Please try again.