[Numpy-svn] r4637 - branches/distutils_scons_command/numpy/distutils

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Dec 22 04:19:32 EST 2007


Author: cdavid
Date: 2007-12-22 03:19:25 -0600 (Sat, 22 Dec 2007)
New Revision: 4637

Modified:
   branches/distutils_scons_command/numpy/distutils/misc_util.py
Log:
Add facilities to generate config file for future sconsified modules

Modified: branches/distutils_scons_command/numpy/distutils/misc_util.py
===================================================================
--- branches/distutils_scons_command/numpy/distutils/misc_util.py	2007-12-22 09:17:25 UTC (rev 4636)
+++ branches/distutils_scons_command/numpy/distutils/misc_util.py	2007-12-22 09:19:25 UTC (rev 4637)
@@ -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