[Numpy-svn] r4158 - in branches/numpy.scons: . numpy/distutils/scons

numpy-svn@scip... numpy-svn@scip...
Tue Oct 9 04:43:35 CDT 2007


Author: cdavid
Date: 2007-10-09 04:43:24 -0500 (Tue, 09 Oct 2007)
New Revision: 4158

Added:
   branches/numpy.scons/numpy/distutils/scons/extension.py
   branches/numpy.scons/numpy/distutils/scons/extension_scons.py
   branches/numpy.scons/numpy/distutils/scons/libinfo.py
   branches/numpy.scons/numpy/distutils/scons/libinfo_scons.py
   branches/numpy.scons/numpy/distutils/scons/utils.py
Modified:
   branches/numpy.scons/
Log:
Importing files from separate bzr branch (not used yet)


Property changes on: branches/numpy.scons
___________________________________________________________________
Name: bzr:revision-info
   - timestamp: 2007-10-09 17:49:06.331000090 +0900
committer: David Cournapeau <david@ar.media.kyoto-u.ac.jp>
properties: 
	branch-nick: numpy.scons

   + timestamp: 2007-10-09 18:33:39.446000099 +0900
committer: David Cournapeau <david@ar.media.kyoto-u.ac.jp>
properties: 
	branch-nick: numpy.scons

Name: bzr:file-ids
   - 
   + numpy/distutils/scons/libinfo.py	libinfo.py-20071009093303-550dnrlqoermhxvl-1
numpy/distutils/scons/extension_scons.py	extension_scons.py-20071009093253-tzixdx7w5zen0j57-2
numpy/distutils/scons/libinfo_scons.py	libinfo_scons.py-20071009093303-550dnrlqoermhxvl-2
numpy/distutils/scons/utils.py	utils.py-20071009093305-fhqfd6xjru0te58v-1
numpy/distutils/scons/extension.py	extension.py-20071009093253-tzixdx7w5zen0j57-1

Name: bzr:revision-id:v3-trunk0
   - 3737 david@david-laptop-20070920080908-n8pj8vmszdir3zoa
3738 david@david-laptop-20070920081509-58kkojgmml3t7jxs
3739 david@david-laptop-20070920081910-phlk1ujthksgpm0z
3740 david@david-laptop-20070920082641-bdhrt6eafeoli50i
3741 david@ar.media.kyoto-u.ac.jp-20070920130730-satdeppbh1k0bq2p
3743 david@ar.media.kyoto-u.ac.jp-20070921073742-vpv8pwv0j8fbd93m
3744 david@david-laptop-20070922101656-61kfi2faucemr2rl
3745 david@david-laptop-20070922113708-ror18thshang1cpu
3747 david@david-laptop-20070922140534-n9xsl096tjrzmct1
3749 david@david-laptop-20070922154007-usit009fr6vp377j
3750 david@david-laptop-20070923070011-leu2ozc2fy1q5cht
3751 david@david-laptop-20070924015925-dhsiao40jp7zsfp9
3752 david@ar.media.kyoto-u.ac.jp-20070924070657-nbw23j0ayan30cli
3753 david@ar.media.kyoto-u.ac.jp-20070924082918-i1lc1zikywi8czj4
3754 david@ar.media.kyoto-u.ac.jp-20070924083008-c0edtt8zs31yeh1q
3755 david@ar.media.kyoto-u.ac.jp-20070924112351-pnnho638cohz6lj1
3756 david@david-laptop-20070924153247-yftud00bynilxv69
3757 david@david-laptop-20070924163545-pish34x9fq2h66aj
3758 david@david-laptop-20070924164633-iiyygcaw81ji3n34
3759 david@david-laptop-20070924170201-y14v2yzikdpvamfp
3760 david@david-laptop-20070924171208-5bmitorzf49d1aa2
3761 david@david-laptop-20070925014444-ns9v90gotnxt39mq
3769 david@david-laptop-20070925145952-4osi81tvch7v6luj
3773 david@ar.media.kyoto-u.ac.jp-20070926073429-2kdc6yf1o210aer0
3774 david@ar.media.kyoto-u.ac.jp-20070926084356-938djoytjap90rmo
3775 david@ar.media.kyoto-u.ac.jp-20070926085329-3gquq3gu2k8rgzb0
3776 david@ar.media.kyoto-u.ac.jp-20071009084906-9kradhwpu7su633x

   + 3737 david@david-laptop-20070920080908-n8pj8vmszdir3zoa
3738 david@david-laptop-20070920081509-58kkojgmml3t7jxs
3739 david@david-laptop-20070920081910-phlk1ujthksgpm0z
3740 david@david-laptop-20070920082641-bdhrt6eafeoli50i
3741 david@ar.media.kyoto-u.ac.jp-20070920130730-satdeppbh1k0bq2p
3743 david@ar.media.kyoto-u.ac.jp-20070921073742-vpv8pwv0j8fbd93m
3744 david@david-laptop-20070922101656-61kfi2faucemr2rl
3745 david@david-laptop-20070922113708-ror18thshang1cpu
3747 david@david-laptop-20070922140534-n9xsl096tjrzmct1
3749 david@david-laptop-20070922154007-usit009fr6vp377j
3750 david@david-laptop-20070923070011-leu2ozc2fy1q5cht
3751 david@david-laptop-20070924015925-dhsiao40jp7zsfp9
3752 david@ar.media.kyoto-u.ac.jp-20070924070657-nbw23j0ayan30cli
3753 david@ar.media.kyoto-u.ac.jp-20070924082918-i1lc1zikywi8czj4
3754 david@ar.media.kyoto-u.ac.jp-20070924083008-c0edtt8zs31yeh1q
3755 david@ar.media.kyoto-u.ac.jp-20070924112351-pnnho638cohz6lj1
3756 david@david-laptop-20070924153247-yftud00bynilxv69
3757 david@david-laptop-20070924163545-pish34x9fq2h66aj
3758 david@david-laptop-20070924164633-iiyygcaw81ji3n34
3759 david@david-laptop-20070924170201-y14v2yzikdpvamfp
3760 david@david-laptop-20070924171208-5bmitorzf49d1aa2
3761 david@david-laptop-20070925014444-ns9v90gotnxt39mq
3769 david@david-laptop-20070925145952-4osi81tvch7v6luj
3773 david@ar.media.kyoto-u.ac.jp-20070926073429-2kdc6yf1o210aer0
3774 david@ar.media.kyoto-u.ac.jp-20070926084356-938djoytjap90rmo
3775 david@ar.media.kyoto-u.ac.jp-20070926085329-3gquq3gu2k8rgzb0
3776 david@ar.media.kyoto-u.ac.jp-20071009084906-9kradhwpu7su633x
3777 david@ar.media.kyoto-u.ac.jp-20071009093339-q5nf5me6ikdi48k6


Added: branches/numpy.scons/numpy/distutils/scons/extension.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/extension.py	2007-10-09 09:43:05 UTC (rev 4157)
+++ branches/numpy.scons/numpy/distutils/scons/extension.py	2007-10-09 09:43:24 UTC (rev 4158)
@@ -0,0 +1,25 @@
+#! /usr/bin/env python
+# Last Change: Tue Oct 09 03:00 PM 2007 J
+
+# Module for support to build python extension. KEEP THIS INDEPENDANT OF SCONS
+
+# XXX: we should avoid clashing between distutils and numpy.distutils. Maybe by
+# defining our own functions here, and accessing any info related to python
+# build option and co from here only.
+import sys
+import os
+from os.path import join as pjoin
+
+from distutils.sysconfig import get_python_version, get_python_inc, get_config_vars
+
+def get_pythonlib_dir():
+    """Returns a list of path to look for the python engine library
+    (pythonX.X.lib on win32, libpythonX.X.so on unix, etc...)."""
+    if os.name == 'nt':
+        return [pjoin(sys.exec_prefix, 'libs')]
+    else:
+        return [pjoin(sys.exec_prefix, 'lib')]
+
+if __name__ == '__main__':
+    print "Python version is %s" % get_python_version()
+    print "Python include dir is %s" % get_python_inc()

Added: branches/numpy.scons/numpy/distutils/scons/extension_scons.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/extension_scons.py	2007-10-09 09:43:05 UTC (rev 4157)
+++ branches/numpy.scons/numpy/distutils/scons/extension_scons.py	2007-10-09 09:43:24 UTC (rev 4158)
@@ -0,0 +1,41 @@
+#! /usr/bin/env python
+# Last Change: Tue Oct 09 04:00 PM 2007 J
+
+# Module for support to build python extension. scons specific code goes here.
+import sys
+from copy import deepcopy
+
+from extension import get_pythonlib_dir, get_python_inc
+
+def built_with_mstools(env):
+    """Return True if built with MS tools (compiler + linker)."""
+    return env.has_key('MSVS')
+
+def PythonExtension(env, target, source, *args, **kw):
+    # XXX Check args and kw
+    # XXX: Some things should not be set here...
+    if env.has_key('LINKFLAGS'):
+        LINKFLAGS = deepcopy(env['LINKFLAGS'])
+    else:
+        LINKFLAGS = []
+    if env.has_key('CPPPPATH'):
+        CPPPATH = deepcopy(env['CPPPATH'])
+    else:
+        CPPPATH = []
+    CPPPATH.append(get_python_inc())
+    if sys.platform == 'win32': 
+        # XXX: pyext should definitely not be set here
+        pyext = '.pyd'
+        if built_with_mstools(env):
+            # # XXX is the export necessary ? (this seems to work wo)
+            # LINKFLAGS += " /EXPORT:init%s " % target[0]
+
+            # XXX: We add the path where to find python2.5.lib (or any other
+            # version, of course). This seems to be necessary for MS compilers.
+            env.AppendUnique(LIBPATH = get_pythonlib_dir())
+    else:
+        pyext = env['SHLIBSUFFIX']
+    wrap = env.SharedLibrary(target, source, SHLIBPREFIX = '', 
+                             SHLIBSUFFIX = pyext, LINKFLAGS = LINKFLAGS, 
+                             CPPPATH = CPPPATH, *args, **kw)
+    return wrap

Added: branches/numpy.scons/numpy/distutils/scons/libinfo.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/libinfo.py	2007-10-09 09:43:05 UTC (rev 4157)
+++ branches/numpy.scons/numpy/distutils/scons/libinfo.py	2007-10-09 09:43:24 UTC (rev 4158)
@@ -0,0 +1,64 @@
+#! /usr/bin/env python
+# Last Change: Fri Oct 05 02:00 PM 2007 J
+
+# Module for support to look for external code (replacement of
+# numpy.distutils.system_info). KEEP THIS INDEPENDANT OF SCONS !
+import os
+import ConfigParser
+
+from numpy.distutils.system_info import default_lib_dirs, \
+    default_include_dirs, default_src_dirs, get_standard_file
+
+def get_config():
+    """ This tries to read .cfg files in several locations, and merge its
+    information into a ConfigParser object for the first found file.
+    
+    Returns the ConfigParser instance. This copies the logic in system_info
+    from numpy.distutils."""
+    # Below is the feature we are copying from numpy.distutils:
+    # 
+    # The file 'site.cfg' is looked for in
+
+    # 1) Directory of main setup.py file being run.
+    # 2) Home directory of user running the setup.py file as ~/.numpy-site.cfg
+    # 3) System wide directory (location of this file...)
+
+    # The first one found is used to get system configuration options The
+    # format is that used by ConfigParser (i.e., Windows .INI style). The
+    # section DEFAULT has options that are the default for each section. The
+    # available sections are fftw, atlas, and x11. Appropiate defaults are
+    # used if nothing is specified.
+
+    section = 'DEFAULT'
+    defaults = {}
+    defaults['libraries'] = ''
+    defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)
+    defaults['include_dirs'] = os.pathsep.join(default_include_dirs)
+    defaults['src_dirs'] = os.pathsep.join(default_src_dirs)
+    cp = ConfigParser.ConfigParser(defaults)
+    files = []
+    files.extend(get_standard_file('.numpy-site.cfg'))
+    files.extend(get_standard_file('site.cfg'))
+
+    def parse_config_files():
+        cp.read(files)
+        if not cp.has_section(section):
+            cp.add_section(section)
+
+    parse_config_files()
+    return cp, files
+
+def parse_config_param(var):
+    """Given var, the output of ConfirParser.get(section, name), returns a list
+    of each item of its content."""
+    pass
+
+def get_paths(var):
+    """Given var, the output of ConfirParser.get(section, name), returns a list
+    of each item of its content, assuming the content is a list of directoris.
+    
+    Example: if var is foo:bar, it will return ['foo', 'bar'] on posix."""
+    return var.split(os.pathsep)
+
+if __name__ == '__main__':
+    pass

Added: branches/numpy.scons/numpy/distutils/scons/libinfo_scons.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/libinfo_scons.py	2007-10-09 09:43:05 UTC (rev 4157)
+++ branches/numpy.scons/numpy/distutils/scons/libinfo_scons.py	2007-10-09 09:43:24 UTC (rev 4158)
@@ -0,0 +1,189 @@
+#! /usr/bin/env python
+# Last Change: Tue Oct 09 04:00 PM 2007 J
+
+# Module for support to look for external code (replacement of
+# numpy.distutils.system_info). scons dependant code.
+import ConfigParser
+from copy import deepcopy
+
+from SCons.Util import is_List
+
+from libinfo import get_config, get_paths
+from utils import get_empty
+
+_SYMBOL_DEF_STR = """
+#ifdef __cplusplus
+extern "C"
+#endif
+char %s();\n"""
+
+_MAIN_CALL_CENTER = """
+int main(int argc, char** argv)
+{
+    %s
+    return 0;
+}\n """
+
+def _CheckLib(context, libs, symbols, header, language, section, siteconfig, 
+              libpath, cpppath):
+    """Implementation for checking a list of symbols, with libs.
+    
+    Assumes that libs, symbol, header, libpath and cpppath are sequences (list
+    or tuples). DO NOT USE DIRECTLY IN SCONSCRIPT !!!"""
+    # XXX: sanitize API for section/siteconfig option: if sectionis not given,
+    # can we just say to ignore the sitecfg ?
+    if not siteconfig:
+        siteconfig, cfgfiles = get_config()
+
+    def get_descr():
+        descr = siteconfig.items(section)
+        sdescr = ""
+        for i in descr:
+            sdescr += str(i) + '\n'
+        return sdescr
+        
+    # Generate the source string of the conftest
+    src = ""
+    callstr = ""
+
+    if symbols:
+        for s in symbols:
+            # XXX: should put undef here (ala autoconf)
+            src += _SYMBOL_DEF_STR % s
+            callstr += "%s();" % s
+
+    src += _MAIN_CALL_CENTER % callstr
+    # HUGE HACK: we want this test to depend on site.cfg files obviously, since
+    # a change in them can change the libraries tested. But Depends does not
+    # seem to work in configuration context, and I don't see any simple way to
+    # have the same functionality. So I put the configuration we got from
+    # get_config into the source code, such as a change in site.cfg will change
+    # the source file, and thus taken into account to decide whether to rebuild
+    # from tjhe SconfTaskMaster point of view.
+
+    # XXX: I put the content between #if 0 / #endif, which is the most portable
+    # way I am aware of for multilines comments in C and C++ (this is also
+    # recommended in C++ portability guide of mozilla for nested comments,
+    # which may happen here). This is also the most robust, since it seems
+    # unlikely to have any #endif somewhere in the return value of get_descr.
+    #src += "#if 0\n"
+    #src += get_descr()
+    #src += "\n#endif\n"
+
+    # XXX: handle autoadd
+    # XXX: handle extension 
+    extension = '.c'
+
+    if section and siteconfig:
+        #print "Checking %s from section %s" % (libs[0], section)
+        res = _check_lib_section(context, siteconfig, section, src, libs,
+                                 libpath, cpppath)
+    else:
+        oldLIBS = context.env.has_key('LIBS') and deepcopy(context.env['LIBS'])
+        context.env.Append(LIBS = libs)
+        res = context.TryLink(src, '.c')
+        if not res:
+            context.env.Replace(LIBS = oldLIBS) 
+
+    return res
+
+
+def NumpyCheckLib(context, libs, symbols = None, header = None, 
+                  language = None, section = None, siteconfig = None, name = None):
+    """Check for symbol in libs. 
+    
+    This is the general purpose replacement for numpy.distutils.system_info. It
+    uses the options in siteconfig so that search path can be overwritten in
+    *.cfg files (using section given by section argument). If siteconfig is
+    None, it does uses get_config function to get the configuration, which
+    gives the old numpy.distutils behaviour to get options.
+
+    
+    Convention: if the section has *dirs parameters, it will use them all in
+    one pass, e.g if library_dirs is ['/usr/local/lib', '/usr/local/mylib'], it
+    will try to link the given libraries by appending both directories to the
+    LIBPATH."""
+    #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    # This is really preliminary, and needs a lot of love before being in good
+    # shape !!!!!
+    #
+    # Biggest problem: how to show information about found libraries ? Since
+    # they are found implicitely through build tools (compiler and linker), we
+    # can not give explicit information. IMHO (David Cournapeau), it is better
+    # to find them implicitely because it is much more robust. But for the info...
+    # 
+    # This needs testing, too.
+    #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    env = context.env
+
+    # XXX: would be nice for each extension to add an option to command line.
+    # XXX: handle env var
+    # XXX: handle language
+    if language:
+        raise NotImplementedError("FIXME: language selection not implemented yet !")
+
+    # Make sure libs and symbols are lists
+    if libs and not is_List(libs):
+        libs = [libs]
+    if symbols and not is_List(symbols):
+        symbols = [symbols]
+
+    if not name:
+        name = libs[0]
+
+    # Display message
+    if symbols:
+        sbstr = ', '.join(symbols)
+        context.Message('Checking for symbol(s) %s in %s... ' % (sbstr, name))
+    else:
+        context.Message('Checking for %s... ' % name)
+
+    # Call the implementation
+    libpath = None
+    cpppath = None
+    res = _CheckLib(context, libs, symbols, header, language, section,
+                    siteconfig, libpath, cpppath, )
+    context.Result(res)
+    return res
+
+def _check_lib_section(context, siteconfig, section, src, libs, libpath, cpppath):
+    # Convention: if an option is found in site.cfg for the given section, it
+    # takes precedence on the arguments libs, libpath, cpppath.
+    res = 1
+    try:
+        newLIBPATH = get_paths(siteconfig.get(section, 'library_dirs'))
+    except ConfigParser.NoSectionError, e:
+        if libpath:
+            newLIBPATH = libpath
+        else:
+            newLIBPATH = []
+
+    try:
+        newCPPPATH = get_paths(siteconfig.get(section, 'include_dirs'))
+    except ConfigParser.NoSectionError, e:
+        if cpppath:
+            newCPPPATH = cpppath
+        else:
+            newCPPPATH = []
+
+    try:
+        newLIBS = siteconfig.get(section, 'libraries') 
+    except ConfigParser.NoSectionError, e:
+        if libs:
+            newLIBS = libs
+        else:
+            newLIBS = []
+
+    lastLIBPATH = get_empty(context.env,'LIBPATH')
+    lastLIBS = get_empty(context.env,'LIBS')
+    lastCPPPATH = get_empty(context.env,'CPPPATH')
+    context.env.Append(LIBPATH = newLIBPATH)
+    context.env.Append(LIBS = newLIBS)
+    context.env.Append(CPPPATH = newCPPPATH)
+    res *= context.TryLink(src, '.c')
+    if not res:
+        context.env.Replace(LIBS = lastLIBS, 
+                            LIBPATH = lastLIBPATH, 
+                            CPPPATH = lastCPPPATH)
+
+    return res

Added: branches/numpy.scons/numpy/distutils/scons/utils.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/utils.py	2007-10-09 09:43:05 UTC (rev 4157)
+++ branches/numpy.scons/numpy/distutils/scons/utils.py	2007-10-09 09:43:24 UTC (rev 4158)
@@ -0,0 +1,44 @@
+import os
+import re
+
+from copy import deepcopy
+
+_START_WITH_MINUS = re.compile('^\s*-')
+
+def popen_wrapper(cmd, merge = False):
+    """This works like popen, but it returns both the status and the output.
+
+    If merge is True, then output contains both stdout and stderr. 
+    
+    Returns: (st, out), where st is an integer (the return status of the
+    subprocess, and out the string of the output).
+    
+    NOTE:
+        - it tries to be robust to find non existing command. For example, is
+          cmd starts with a minus, a nonzero status is returned, and no junk is
+          displayed on the interpreter stdout."""
+    if _START_WITH_MINUS.match(cmd):
+        return 1, ''
+    if merge:
+        # XXX: I have a bad feeling about this. Does it really work reliably on
+        # all supported platforms ?
+        cmd += ' 2>& 1 '
+    output = os.popen(cmd)
+    out = output.read()
+    st = output.close()
+    if st:
+        status = st
+    else:
+        status = 0
+
+    return status, out
+
+def get_empty(dict, key):
+    """Assuming dict is a dictionary with lists as values, returns an empty
+    list if key is not found, or a (deep) copy of the existing value if it
+    does."""
+    try:
+        return deepcopy(dict[key])
+    except KeyError, e:
+        return []
+



More information about the Numpy-svn mailing list