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

numpy-svn@scip... numpy-svn@scip...
Sat Nov 24 01:17:51 CST 2007


Author: cdavid
Date: 2007-11-24 01:15:35 -0600 (Sat, 24 Nov 2007)
New Revision: 4502

Modified:
   branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
   branches/numpy.scons/numpy/distutils/scons/core/template_generators.py
   branches/numpy.scons/numpy/distutils/scons/tools/npyftpl.py
Log:
Add a scons scanner to handle dependencies in template (.src) files

Modified: branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py	2007-11-24 03:28:27 UTC (rev 4501)
+++ branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py	2007-11-24 07:15:35 UTC (rev 4502)
@@ -196,6 +196,7 @@
     from SCons.Script import BuildDir, Help
     from SCons.Errors import EnvironmentError
     from SCons.Builder import Builder
+    from SCons.Scanner import Scanner
 
     # XXX: I would prefer subclassing Environment, because we really expect
     # some different behaviour than just Environment instances...
@@ -324,15 +325,20 @@
 
     from template_generators import generate_from_c_template, \
                                     generate_from_f_template, \
-                                    generate_from_template_emitter
+                                    generate_from_template_emitter, \
+                                    generate_from_template_scanner
 
+    tpl_scanner = Scanner(function = generate_from_template_scanner, 
+                          skeys = ['.src'])
     env['BUILDERS']['FromCTemplate'] = Builder(
                 action = generate_from_c_template, 
-                emitter = generate_from_template_emitter)
+                emitter = generate_from_template_emitter,
+                source_scanner = tpl_scanner)
 
     env['BUILDERS']['FromFTemplate'] = Builder(
                 action = generate_from_f_template, 
-                emitter = generate_from_template_emitter)
+                emitter = generate_from_template_emitter,
+                source_scanner = tpl_scanner)
 
     from custom_builders import NumpyFromCTemplate, NumpyFromFTemplate
     env['BUILDERS']['NumpyFromCTemplate'] = NumpyFromCTemplate

Modified: branches/numpy.scons/numpy/distutils/scons/core/template_generators.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/core/template_generators.py	2007-11-24 03:28:27 UTC (rev 4501)
+++ branches/numpy.scons/numpy/distutils/scons/core/template_generators.py	2007-11-24 07:15:35 UTC (rev 4502)
@@ -1,24 +1,19 @@
+import re
 from os.path import basename as pbasename, splitext, join as pjoin, dirname as pdirname
 
-from numpy.distutils.conv_template import process_str as c_process_str
-from numpy.distutils.from_template import process_str as f_process_str
+from numpy.distutils.conv_template import process_file as process_c_file
+from numpy.distutils.from_template import process_file as process_f_file
 
 def do_generate_from_c_template(targetfile, sourcefile, env):
     t = open(targetfile, 'w')
-    s = open(sourcefile, 'r')
-    allstr = s.read()
-    s.close()
-    writestr = c_process_str(allstr)
+    writestr = process_c_file(sourcefile)
     t.write(writestr)
     t.close()
     return 0
 
 def do_generate_from_f_template(targetfile, sourcefile, env):
     t = open(targetfile, 'w')
-    s = open(sourcefile, 'r')
-    allstr = s.read()
-    s.close()
-    writestr = f_process_str(allstr)
+    writestr = process_f_file(sourcefile)
     t.write(writestr)
     t.close()
     return 0
@@ -38,3 +33,9 @@
     t = pjoin(pdirname(str(target[0])), base)
     return ([t], source)
     
+_INCLUDE_RE = re.compile(r"include\s*['\"](\S+)['\"]", re.M)
+
+def generate_from_template_scanner(node, env, path, arg):
+    print "SCANNING, YO !"
+    cnt = node.get_contents()
+    return _INCLUDE_RE.findall(cnt)

Modified: branches/numpy.scons/numpy/distutils/scons/tools/npyftpl.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/tools/npyftpl.py	2007-11-24 03:28:27 UTC (rev 4501)
+++ branches/numpy.scons/numpy/distutils/scons/tools/npyftpl.py	2007-11-24 07:15:35 UTC (rev 4502)
@@ -17,7 +17,7 @@
 import SCons.Scanner
 import SCons.Tool
 
-from numpy.distutils.from_template import process_str
+from numpy.distutils.from_template import process_file
 
 # XXX: this is general and can be used outside numpy.core.
 def _do_generate_from_template(targetfile, sourcefile, env):
@@ -25,7 +25,7 @@
     s = open(sourcefile, 'r')
     allstr = s.read()
     s.close()
-    writestr = process_str(allstr)
+    writestr = process_file(allstr)
     t.write(writestr)
     t.close()
     return 0



More information about the Numpy-svn mailing list