[Numpy-svn] r4456 - in branches/numpy.scons: . numpy/distutils/scons/core numpy/distutils/scons/tools

numpy-svn@scip... numpy-svn@scip...
Wed Nov 14 23:58:15 CST 2007


Author: cdavid
Date: 2007-11-14 23:57:42 -0600 (Wed, 14 Nov 2007)
New Revision: 4456

Added:
   branches/numpy.scons/numpy/distutils/scons/tools/f2py.py
Modified:
   branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
   branches/numpy.scons/test.sh
Log:
Add f2py tool for scons, to build source from .pyf files

Modified: branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py	2007-11-14 07:34:10 UTC (rev 4455)
+++ branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py	2007-11-15 05:57:42 UTC (rev 4456)
@@ -14,8 +14,11 @@
 from libinfo import get_config
 from extension_scons import PythonExtension, built_with_mstools
 
+import numpy.distutils.scons.tools
 from numpy.distutils.scons.tools.substinfile import TOOL_SUBST
 
+__all__ = ['GetNumpyEnvironment']
+
 def pyplat2sconsplat():
     # XXX: should see how env['PLATFORM'] is defined, make this a dictionary 
     if sys.platform[:5] == 'linux':
@@ -118,7 +121,7 @@
     # XXX: how to handle tools which are not in standard location ? Is adding
     # the full path of the compiler enough ? (I am sure some compilers also
     # need LD_LIBRARY_SHARED and other variables to be set, too....)
-    from SCons.Tool import Tool
+    from SCons.Tool import Tool, FindTool
 
     if len(env['cc_opt']) > 0:
         try:
@@ -149,14 +152,13 @@
             raise AssertionError("SCONS: Could not initialize tool ? Error is %s" % \
                                  str(e))
     else:
-        t = Tool(FindTool(DEF_C_COMPILERS))
+        t = Tool(FindTool(DEF_C_COMPILERS, env))
         t(env)
         customize_cc(t.name, env)
 
 def initialize_f77(env, path_list):
-    from SCons.Tool import Tool
+    from SCons.Tool import Tool, FindTool
 
-    # F77 compiler
     if len(env['f77_opt']) > 0:
         try:
             if len(env['f77_opt_path']) > 0:
@@ -239,6 +241,9 @@
     for t in FindAllTools(DEF_OTHER_TOOLS, env):
         Tool(t)(env)
 
+    t = Tool('f2py', toolpath = [os.path.dirname(numpy.distutils.scons.tools.__file__)])
+    t(env)
+
     finalize_env(env)
 
     # Add the tool paths in the environment

Added: branches/numpy.scons/numpy/distutils/scons/tools/f2py.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/f2py.py	2007-11-14 07:34:10 UTC (rev 4455)
+++ branches/numpy.scons/numpy/distutils/scons/tools/f2py.py	2007-11-15 05:57:42 UTC (rev 4456)
@@ -0,0 +1,86 @@
+"""f2py Tool
+
+Tool-specific initialization for f2py.
+
+There normally shouldn't be any need to import this module directly.
+It will usually be imported through the generic SCons.Tool.Tool()
+selection method.
+
+"""
+
+import os.path
+import re
+
+import SCons.Action
+import SCons.Defaults
+import SCons.Scanner
+import SCons.Tool
+import SCons.Util
+import SCons.Node
+
+def _f2pySuffixEmitter(env, source):
+    return '$F2PYCFILESUFFIX'
+
+#_reModule = re.compile(r'%module\s+(.+)')
+
+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')))
+    return (target, source)
+
+def _pyf2c(target, source, env):
+    import numpy.f2py
+    import shutil
+
+    # We need filenames from source/target for path handling
+    target_file_names = [str(i) for i in target]
+    source_file_names = [str(i) for i in source]
+
+    # 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"
+
+    # Copy source files for f2py generated modules in the build dir
+    build_dir = os.path.dirname(target_file_names[0])
+    shutil.copy(source_c, build_dir)
+    shutil.copy(source_h, build_dir)
+
+    # Generate the source file from pyf description
+    haha = numpy.f2py.run_main(['--build-dir', build_dir,
+                                source_file_names[0]])
+    return 0
+
+def generate(env):
+    """Add Builders and construction variables for swig to an Environment."""
+    c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
+
+    c_file.suffix['.pyf'] = _f2pySuffixEmitter
+
+    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'
+
+    # XXX: scanner ?
+
+    #expr = '^[ \t]*%[ \t]*(?:include|import|extern)[ \t]*(<|"?)([^>\s"]+)(?:>|"?)'
+    #scanner = SCons.Scanner.ClassicCPP("SWIGScan", ".i", "SWIGPATH", expr)
+    #env.Append(SCANNERS = scanner)
+
+def exists(env):
+    try:
+        import numpy.f2py
+        st = 1
+    except ImportError, e:
+        print "Warning : f2py tool not found, error was %s" % e
+        st = 0
+
+    return st

Modified: branches/numpy.scons/test.sh
===================================================================
--- branches/numpy.scons/test.sh	2007-11-14 07:34:10 UTC (rev 4455)
+++ branches/numpy.scons/test.sh	2007-11-15 05:57:42 UTC (rev 4456)
@@ -1,5 +1,12 @@
+# PREFIX=$PWD
+# rm -rf $PREFIX/build
+# rm -rf $PREFIX/tmp
+# MKL=None python setupscons.py scons --jobs=4 install --prefix=$PREFIX/tmp
+# (cd $PREFIX/tmp && PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python -c "import numpy; print numpy; numpy.test(level = 9999); numpy.show_config()")
+
 PREFIX=$PWD
-rm -rf $PREFIX/build
-rm -rf $PREFIX/tmp
-MKL=None python setup.py scons --jobs=4 install --prefix=$PREFIX/tmp
-(cd $PREFIX/tmp && PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python -c "import numpy; print numpy; numpy.test(level = 9999); numpy.show_config()")
+#rm -rf $PREFIX/build
+#rm -rf $PREFIX/tmp
+MKL=None python setupscons.py scons --jobs=4 --silent=2 install --prefix=$PREFIX/tmp
+(cd $PREFIX/tmp/lib/python2.5/site-packages/numpy/distutils/scons/tests/f2pyext/ && \
+ PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python setup.py scons)



More information about the Numpy-svn mailing list