[Numpy-svn] r4469 - in branches/numpy.scons/numpy/distutils/scons: core tests/f2pyext tools
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Nov 19 05:31:09 EST 2007
Author: cdavid
Date: 2007-11-19 04:30:54 -0600 (Mon, 19 Nov 2007)
New Revision: 4469
Modified:
branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
branches/numpy.scons/numpy/distutils/scons/tests/f2pyext/SConstruct
branches/numpy.scons/numpy/distutils/scons/tools/f2py.py
Log:
Some improvements for f2py (scanner for include_file)
Modified: branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py 2007-11-19 04:17:36 UTC (rev 4468)
+++ branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py 2007-11-19 10:30:54 UTC (rev 4469)
@@ -243,7 +243,11 @@
Tool(t)(env)
t = Tool('f2py', toolpath = [os.path.dirname(numpy.distutils.scons.tools.__file__)])
- t(env)
+ try:
+ t(env)
+ except Exception, e:
+ pass
+ #print "===== BOOTSTRAPPING, f2py scons tool not available (%s) =====" % e
finalize_env(env)
Modified: branches/numpy.scons/numpy/distutils/scons/tests/f2pyext/SConstruct
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tests/f2pyext/SConstruct 2007-11-19 04:17:36 UTC (rev 4468)
+++ branches/numpy.scons/numpy/distutils/scons/tests/f2pyext/SConstruct 2007-11-19 10:30:54 UTC (rev 4469)
@@ -4,5 +4,5 @@
env = GetNumpyEnvironment(ARGUMENTS)
-env.Append(CPPPATH = get_numpy_include_dirs())
+env.Append(CPPPATH = [get_numpy_include_dirs(), env['F2PYINCLUDEDIR']])
env.NumpyPythonExtension('spam', source = ['spam.pyf'])
Modified: branches/numpy.scons/numpy/distutils/scons/tools/f2py.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/f2py.py 2007-11-19 04:17:36 UTC (rev 4468)
+++ branches/numpy.scons/numpy/distutils/scons/tools/f2py.py 2007-11-19 10:30:54 UTC (rev 4469)
@@ -18,18 +18,31 @@
import SCons.Util
import SCons.Node
+# XXX: this whole thing needs cleaning !
+
def _f2pySuffixEmitter(env, source):
return '$F2PYCFILESUFFIX'
#_reModule = re.compile(r'%module\s+(.+)')
+def _mangle_fortranobject(targetname, filename):
+ basename = os.path.splitext(os.path.basename(targetname))[0]
+ return '%s_%s' % (basename, filename)
+
def _f2pyEmitter(target, source, env):
build_dir = os.path.dirname(str(target[0]))
- target.append(SCons.Node.FS.default_fs.Entry(os.path.join(build_dir, 'fortranobject.c')))
- target.append(SCons.Node.FS.default_fs.Entry(os.path.join(build_dir, 'fortranobject.h')))
+ target.append(SCons.Node.FS.default_fs.Entry(
+ os.path.join(build_dir, _mangle_fortranobject(str(target[0]), 'fortranobject.c'))))
+ basename = os.path.splitext(os.path.basename(str(target[0])))
+ basename = basename[0]
+ basename = basename.split('module')[0]
+ target.append(SCons.Node.FS.default_fs.Entry(
+ os.path.join(build_dir, '%s-f2pywrappers.f' % basename)))
return (target, source)
def _pyf2c(target, source, env):
+ from SCons.Script import Touch
+ from threading import Lock
import numpy.f2py
import shutil
@@ -40,11 +53,10 @@
# Get source files necessary for f2py generated modules
d = os.path.dirname(numpy.f2py.__file__)
source_c = os.path.join(d,'src','fortranobject.c')
- source_h = os.path.join(d,'src','fortranobject.h')
# XXX: scons has a way to force buidler to only use one source file
if len(source_file_names) > 1:
- raise "YATA"
+ raise NotImplementedError("FIXME: multiple source files")
# Copy source files for f2py generated modules in the build dir
build_dir = os.path.dirname(target_file_names[0])
@@ -54,19 +66,42 @@
build_dir = '.'
try:
- shutil.copy(source_c, build_dir)
- shutil.copy(source_h, build_dir)
+ shutil.copy(source_c, os.path.join(build_dir,
+ _mangle_fortranobject(target_file_names[0], 'fortranobject.c')))
except IOError, e:
msg = "Error while copying fortran source files (error was %s)" % str(e)
raise IOError(msg)
+ basename = os.path.basename(str(target[0]).split('module')[0])
+ wrapper = os.path.join(build_dir, '%s-f2pywrappers.f' % basename)
+
# Generate the source file from pyf description
- haha = numpy.f2py.run_main(['--build-dir', build_dir,
- source_file_names[0]])
+ # XXX: lock does not work...
+ #l = Lock()
+ #st = l.acquire()
+ #print "ST is %s" % st
+ try:
+ #print " STARTING %s" % basename
+ st = numpy.f2py.run_main([source_file_names[0], '--build-dir', build_dir])
+ if not os.path.exists(wrapper):
+ #print "++++++++++++++++++++++++++++++++"
+ f = open(wrapper, 'w')
+ f.close()
+ else:
+ pass
+ #print "--------------------------------"
+ #print " FINISHED %s" % basename
+ finally:
+ #l.release()
+ pass
+
return 0
def generate(env):
"""Add Builders and construction variables for swig to an Environment."""
+ import numpy.f2py
+ d = os.path.dirname(numpy.f2py.__file__)
+
c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
c_file.suffix['.pyf'] = _f2pySuffixEmitter
@@ -74,16 +109,31 @@
c_file.add_action('.pyf', SCons.Action.Action(_pyf2c))
c_file.add_emitter('.pyf', _f2pyEmitter)
- env['F2PYOPTIONS'] = SCons.Util.CLVar('')
- env['F2PYBUILDDIR'] = ''
- env['F2PYCFILESUFFIX'] = 'module$CFILESUFFIX'
+ env['F2PYOPTIONS'] = SCons.Util.CLVar('')
+ env['F2PYBUILDDIR'] = ''
+ env['F2PYCFILESUFFIX'] = 'module$CFILESUFFIX'
+ env['F2PYINCLUDEDIR'] = os.path.join(d, 'src')
- # XXX: scanner ?
+ # XXX: adding a scanner using c_file.add_scanner does not work...
+ expr = '(<)include_file=(\S+)>'
+ scanner = SCons.Scanner.ClassicCPP("F2PYScan", ".pyf", "F2PYPATH", expr)
+ env.Append(SCANNERS = scanner)
- #expr = '^[ \t]*%[ \t]*(?:include|import|extern)[ \t]*(<|"?)([^>\s"]+)(?:>|"?)'
- #scanner = SCons.Scanner.ClassicCPP("SWIGScan", ".i", "SWIGPATH", expr)
- #env.Append(SCANNERS = scanner)
+_MINC = re.compile(r'<include_file=(\S+)>')
+def _pyf_scanner(node, env, path):
+ print "================== SCANNING ===================="
+ cnt = node.get_contents()
+ return _parse(cnt)
+def _parse(lines):
+ """Return list of included files in .pyf from include_file directive."""
+ dep = []
+ for line in lines:
+ m = _MINC.search(line)
+ if m:
+ dep.append(m.group(1))
+ return dep
+
def exists(env):
try:
import numpy.f2py
More information about the Numpy-svn
mailing list