[Numpy-svn] r4683 - branches/build_with_scons/numpy/distutils

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Jan 6 05:35:48 EST 2008


Author: cdavid
Date: 2008-01-06 04:35:44 -0600 (Sun, 06 Jan 2008)
New Revision: 4683

Modified:
   branches/build_with_scons/numpy/distutils/misc_util.py
Log:

Add facilities to generate config file for future sconsified modules.



Modified: branches/build_with_scons/numpy/distutils/misc_util.py
===================================================================
--- branches/build_with_scons/numpy/distutils/misc_util.py	2008-01-06 10:34:40 UTC (rev 4682)
+++ branches/build_with_scons/numpy/distutils/misc_util.py	2008-01-06 10:35:44 UTC (rev 4683)
@@ -1472,6 +1472,51 @@
     # else running numpy/core/setup.py
     return include_dirs
 
+def scons_generate_config_py(target):
+    """generate config.py file containing system_info information
+    used during building the package.
+
+    usage:
+        config['py_modules'].append((packagename, '__config__',generate_config_py))
+    """
+    from distutils.dir_util import mkpath
+    import imp
+    d = {}
+    mkpath(os.path.dirname(target))
+    f = open(target, 'w')
+    f.write('# this file is generated by %s\n' % (os.path.abspath(sys.argv[0])))
+    f.write('# it contains system_info results at the time of building this package.\n')
+    f.write('__all__ = ["show"]\n\n')
+    confdir = get_scons_configres_dir()
+    confilename = get_scons_configres_filename()
+    for root, dirs, files in os.walk(confdir):
+        if files:
+            file = os.path.join(root, confilename)
+            assert root.startswith(confdir)
+            pkg_name = '.'.join(root[len(confdir)+1:].split(os.sep))
+            fid = open(file, 'r')
+            try:
+                config_mod = imp.load_module(pkg_name, fid, confilename,
+                                             ('.py', 'U', 1))
+                d[pkg_name] = config_mod.config
+            finally:
+                fid.close()
+    # d is a dictionary whose keys are package names, and values the
+    # corresponding configuration. Each configuration is itself a dictionary
+    # (lib : libinfo)
+    f.write('_config = %s\n' % d)
+    f.write(r'''
+def show():
+    for pkg, config in _config.items():
+        print "package %s configuration:" % pkg
+        for lib, libc in config.items():
+            print '    %s' % lib
+            for line in libc.split('\n'):
+                print '\t%s' % line
+    ''')
+    f.close()
+    return target
+
 #########################
 
 def default_config_dict(name = None, parent_name = None, local_path=None):




More information about the Numpy-svn mailing list