[Numpy-svn] r4773 - in trunk: . numpy numpy/core numpy/core/code_generators numpy/core/include/numpy numpy/core/src numpy/distutils numpy/distutils/command numpy/f2py numpy/fft numpy/lib numpy/linalg numpy/numarray numpy/oldnumeric numpy/random numpy/testing

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Feb 8 05:13:36 EST 2008


Author: jarrod.millman
Date: 2008-02-08 04:12:16 -0600 (Fri, 08 Feb 2008)
New Revision: 4773

Added:
   trunk/numpy/core/SConstruct
   trunk/numpy/core/code_generators/__init__.py
   trunk/numpy/core/include/numpy/numpyconfig.h.in
   trunk/numpy/core/scons_support.py
   trunk/numpy/core/setupscons.py
   trunk/numpy/distutils/command/scons.py
   trunk/numpy/distutils/numpy_distribution.py
   trunk/numpy/distutils/setupscons.py
   trunk/numpy/f2py/setupscons.py
   trunk/numpy/fft/SConstruct
   trunk/numpy/fft/setupscons.py
   trunk/numpy/lib/SConstruct
   trunk/numpy/lib/setupscons.py
   trunk/numpy/linalg/SConstruct
   trunk/numpy/linalg/setupscons.py
   trunk/numpy/numarray/SConstruct
   trunk/numpy/numarray/setupscons.py
   trunk/numpy/oldnumeric/setupscons.py
   trunk/numpy/random/SConstruct
   trunk/numpy/random/setupscons.py
   trunk/numpy/setupscons.py
   trunk/numpy/testing/setupscons.py
   trunk/setupscons.py
   trunk/test.sh
Modified:
   trunk/
   trunk/numpy/core/code_generators/generate_array_api.py
   trunk/numpy/core/code_generators/generate_ufunc_api.py
   trunk/numpy/core/include/numpy/ndarrayobject.h
   trunk/numpy/core/setup.py
   trunk/numpy/core/src/arraytypes.inc.src
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/src/umathmodule.c.src
   trunk/numpy/distutils/command/build.py
   trunk/numpy/distutils/command/config.py
   trunk/numpy/distutils/core.py
   trunk/numpy/distutils/misc_util.py
Log:
merging David Cournapeau's build_with_scons branch, which adds scons support to numpy.distutils and modifies the configuration of numpy/core



Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
   - /branches/build_with_scons:1-4676 /branches/cleanconfig_rtm:1-4610 /branches/distutils-revamp:1-2752 /branches/distutils_scons_command:1-4619 /branches/multicore:1-3687 /branches/numpy.scons:1-4484 /trunk:1-2871
   + /branches/build_with_scons:1-4676 /branches/cleanconfig_rtm:1-4677 /branches/distutils-revamp:1-2752 /branches/distutils_scons_command:1-4619 /branches/multicore:1-3687 /branches/numpy.scons:1-4484 /trunk:1-2871


Copied: trunk/numpy/core/SConstruct (from rev 4772, branches/build_with_scons/numpy/core/SConstruct)

Copied: trunk/numpy/core/code_generators/__init__.py (from rev 4772, branches/build_with_scons/numpy/core/code_generators/__init__.py)

Modified: trunk/numpy/core/code_generators/generate_array_api.py
===================================================================
--- trunk/numpy/core/code_generators/generate_array_api.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/code_generators/generate_array_api.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -1,9 +1,6 @@
 import os
 import genapi
 
-OBJECT_API_ORDER = 'array_api_order.txt'
-MULTIARRAY_API_ORDER = 'multiarray_api_order.txt'
-
 types = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',
          'Inexact',
          'Floating', 'ComplexFloating', 'Flexible', 'Character',
@@ -122,22 +119,30 @@
 """
 
 def generate_api(output_dir, force=False):
-    header_file = os.path.join(output_dir, '__multiarray_api.h')
-    c_file = os.path.join(output_dir,'__multiarray_api.c')
-    doc_file = os.path.join(output_dir, 'multiarray_api.txt')
+    basename = 'multiarray_api'
 
-    targets = (header_file, c_file, doc_file)
-    if (not force
-            and not genapi.should_rebuild(targets,
-                                          [OBJECT_API_ORDER,
-                                           MULTIARRAY_API_ORDER,
-                                           __file__])):
+    h_file = os.path.join(output_dir, '__%s.h' % basename)
+    c_file = os.path.join(output_dir, '__%s.c' % basename)
+    d_file = os.path.join(output_dir, '%s.txt' % basename)
+    targets = (h_file, c_file, d_file)
+    sources = ['array_api_order.txt',  'multiarray_api_order.txt']
+
+    if (not force and not genapi.should_rebuild(targets, sources + [__file__])):
         return targets
+    else:
+        do_generate_api(targets, sources)
 
+    return targets
+
+def do_generate_api(targets, sources):
+    header_file = targets[0]
+    c_file = targets[1]
+    doc_file = targets[2]
+
     objectapi_list = genapi.get_api_functions('OBJECT_API',
-                                              OBJECT_API_ORDER)
+                                              sources[0])
     multiapi_list = genapi.get_api_functions('MULTIARRAY_API',
-                                             MULTIARRAY_API_ORDER)
+                                             sources[1])
     # API fixes for __arrayobject_api.h
 
     fixed = 10

Modified: trunk/numpy/core/code_generators/generate_ufunc_api.py
===================================================================
--- trunk/numpy/core/code_generators/generate_ufunc_api.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/code_generators/generate_ufunc_api.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -1,8 +1,6 @@
 import os
 import genapi
 
-UFUNC_API_ORDER = 'ufunc_api_order.txt'
-
 h_template = r"""
 #ifdef _UMATHMODULE
 
@@ -72,18 +70,29 @@
 """
 
 def generate_api(output_dir, force=False):
-    header_file = os.path.join(output_dir, '__ufunc_api.h')
-    c_file = os.path.join(output_dir, '__ufunc_api.c')
-    doc_file = os.path.join(output_dir, 'ufunc_api.txt')
+    basename = 'ufunc_api'
+    
+    h_file = os.path.join(output_dir, '__%s.h' % basename)
+    c_file = os.path.join(output_dir, '__%s.c' % basename)
+    d_file = os.path.join(output_dir, '%s.txt' % basename)
+    targets = (h_file, c_file, d_file)
 
-    targets = (header_file, c_file, doc_file)
-    if (not force
-            and not genapi.should_rebuild(targets,
-                                          [UFUNC_API_ORDER, __file__])):
+    sources = ['ufunc_api_order.txt']
+
+    if (not force and not genapi.should_rebuild(targets, sources + [__file__])):
         return targets
+    else:
+        do_generate_api(targets, sources)
 
-    ufunc_api_list = genapi.get_api_functions('UFUNC_API', UFUNC_API_ORDER)
+    return targets
 
+def do_generate_api(targets, sources):
+    header_file = targets[0]
+    c_file = targets[1]
+    doc_file = targets[2]
+
+    ufunc_api_list = genapi.get_api_functions('UFUNC_API', sources[0])
+
     # API fixes for __arrayobject_api.h
 
     fixed = 1

Modified: trunk/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- trunk/numpy/core/include/numpy/ndarrayobject.h	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/include/numpy/ndarrayobject.h	2008-02-08 10:12:16 UTC (rev 4773)
@@ -13,8 +13,15 @@
        everything when you're typing */
 #endif
 /* This is auto-generated by the installer */
-#include "config.h"
+#include "numpyconfig.h"
 
+/* Only use thread if configured in config and python supports it */
+#if defined WITH_THREAD && !NPY_NO_SMP
+        #define NPY_ALLOW_THREADS 1
+#else
+        #define NPY_ALLOW_THREADS 0
+#endif
+
 /* There are several places in the code where an array of dimensions is
  * allocated statically.  This is the size of that static allocation.
  *
@@ -80,7 +87,8 @@
 #define NPY_FALSE 0
 #define NPY_TRUE 1
 
-#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE
+
+#if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
         typedef double npy_longdouble;
         #define NPY_LONGDOUBLE_FMT "g"
 #else
@@ -279,22 +287,15 @@
 #define NPY_MAX_ULONG  ULONG_MAX
 
 
-#define NPY_SIZEOF_LONG SIZEOF_LONG
-#define NPY_SIZEOF_INT SIZEOF_INT
-#define NPY_SIZEOF_SHORT SIZEOF_SHORT
-#define NPY_SIZEOF_FLOAT SIZEOF_FLOAT
-#define NPY_SIZEOF_DOUBLE SIZEOF_DOUBLE
-#define NPY_SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE
-#define NPY_SIZEOF_LONGLONG SIZEOF_LONG_LONG
 #define NPY_BITSOF_BOOL (sizeof(npy_bool)*CHAR_BIT)
 #define NPY_BITSOF_CHAR CHAR_BIT
-#define NPY_BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)
-#define NPY_BITSOF_INT (SIZEOF_INT*CHAR_BIT)
-#define NPY_BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)
-#define NPY_BITSOF_LONGLONG (NPY_SIZEOF_LONGLONG*CHAR_BIT)
-#define NPY_BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)
-#define NPY_BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)
-#define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE*CHAR_BIT)
+#define NPY_BITSOF_SHORT (NPY_SIZEOF_SHORT * CHAR_BIT)
+#define NPY_BITSOF_INT (NPY_SIZEOF_INT * CHAR_BIT)
+#define NPY_BITSOF_LONG (NPY_SIZEOF_LONG * CHAR_BIT)
+#define NPY_BITSOF_LONGLONG (NPY_SIZEOF_LONGLONG * CHAR_BIT)
+#define NPY_BITSOF_FLOAT (NPY_SIZEOF_FLOAT * CHAR_BIT)
+#define NPY_BITSOF_DOUBLE (NPY_SIZEOF_DOUBLE * CHAR_BIT)
+#define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE * CHAR_BIT)
 
 #if NPY_BITSOF_LONG == 8
 #define NPY_INT8 NPY_LONG
@@ -918,8 +919,8 @@
  * platform.  Py_intptr_t, Py_uintptr_t are defined in pyport.h. */
 typedef Py_intptr_t npy_intp;
 typedef Py_uintptr_t npy_uintp;
-#define NPY_SIZEOF_INTP SIZEOF_PY_INTPTR_T
-#define NPY_SIZEOF_UINTP SIZEOF_PY_INTPTR_T
+#define NPY_SIZEOF_INTP NPY_SIZEOF_PY_INTPTR_T
+#define NPY_SIZEOF_UINTP NPY_SIZEOF_PY_INTPTR_T
 
 #ifdef constchar
 #undef constchar
@@ -940,7 +941,7 @@
 #define constchar char
 #endif
 
-#if SIZEOF_PY_INTPTR_T == SIZEOF_INT
+#if NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_INT
         #define NPY_INTP NPY_INT
         #define NPY_UINTP NPY_UINT
         #define PyIntpArrType_Type PyIntArrType_Type
@@ -949,7 +950,7 @@
         #define NPY_MIN_INTP NPY_MIN_INT
         #define NPY_MAX_UINTP NPY_MAX_UINT
         #define NPY_INTP_FMT "d"
-#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG
+#elif NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONG
         #define NPY_INTP NPY_LONG
         #define NPY_UINTP NPY_ULONG
         #define PyIntpArrType_Type PyLongArrType_Type
@@ -958,7 +959,7 @@
         #define NPY_MIN_INTP MIN_LONG
         #define NPY_MAX_UINTP NPY_MAX_ULONG
         #define NPY_INTP_FMT "ld"
-#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)
+#elif defined(PY_LONG_LONG) && (NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONGLONG)
         #define NPY_INTP NPY_LONGLONG
         #define NPY_UINTP NPY_ULONGLONG
         #define PyIntpArrType_Type PyLongLongArrType_Type
@@ -1894,7 +1895,7 @@
 
 #define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
 #define NPY_REFCOUNT PyArray_REFCOUNT
-#define NPY_MAX_ELSIZE (2*SIZEOF_LONGDOUBLE)
+#define NPY_MAX_ELSIZE (2 * NPY_SIZEOF_LONGDOUBLE)
 
 #define PyArray_ContiguousFromAny(op, type, min_depth, max_depth)             \
         PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,           \

Copied: trunk/numpy/core/include/numpy/numpyconfig.h.in (from rev 4772, branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in)

Copied: trunk/numpy/core/scons_support.py (from rev 4772, branches/build_with_scons/numpy/core/scons_support.py)

Modified: trunk/numpy/core/setup.py
===================================================================
--- trunk/numpy/core/setup.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/setup.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -18,6 +18,36 @@
     ('rint', 'HAVE_RINT'),
     ]
 
+def is_npy_no_signal():
+    """Return True if the NPY_NO_SIGNAL symbol must be defined in configuration
+    header."""
+    return sys.platform == 'win32'
+
+def is_npy_no_smp():
+    """Return True if the NPY_NO_SMP symbol must be defined in public
+    header (when SMP support cannot be reliably enabled)."""
+    # Python 2.3 causes a segfault when
+    #  trying to re-acquire the thread-state
+    #  which is done in error-handling
+    #  ufunc code.  NPY_ALLOW_C_API and friends
+    #  cause the segfault. So, we disable threading
+    #  for now.
+    if sys.version[:5] < '2.4.2':
+        nosmp = 1
+    else:
+        # Perhaps a fancier check is in order here.
+        #  so that threads are only enabled if there
+        #  are actually multiple CPUS? -- but
+        #  threaded code can be nice even on a single
+        #  CPU so that long-calculating code doesn't
+        #  block.
+        try:
+            nosmp = os.environ['NPY_NOSMP']
+            nosmp = 1
+        except KeyError:
+            nosmp = 0
+    return nosmp == 1
+
 def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration,dot_join
     from numpy.distutils.system_info import get_info, default_lib_dirs
@@ -53,28 +83,7 @@
                 raise SystemError,"Failed to test configuration. "\
                       "See previous error messages for more information."
 
-                # Python 2.3 causes a segfault when
-                #  trying to re-acquire the thread-state
-                #  which is done in error-handling
-                #  ufunc code.  NPY_ALLOW_C_API and friends
-                #  cause the segfault. So, we disable threading
-                #  for now.
-            if sys.version[:5] < '2.4.2':
-                nosmp = 1
-            else:
-                # Perhaps a fancier check is in order here.
-                #  so that threads are only enabled if there
-                #  are actually multiple CPUS? -- but
-                #  threaded code can be nice even on a single
-                #  CPU so that long-calculating code doesn't
-                #  block.
-                try:
-                    nosmp = os.environ['NPY_NOSMP']
-                    nosmp = 1
-                except KeyError:
-                    nosmp = 0
-            if nosmp: moredefs = [('NPY_ALLOW_THREADS', '0')]
-            else: moredefs = []
+            moredefs = []
             #
             mathlibs = []
             tc = testcode_mathlib()
@@ -102,8 +111,8 @@
                 if check_func(func_name):
                     moredefs.append(defsymbol)
 
-            if sys.platform == 'win32':
-                moredefs.append('NPY_NO_SIGNAL')
+            if is_npy_no_signal():
+                moredefs.append('__NPY_PRIVATE_NO_SIGNAL')
 
             if sys.platform=='win32' or os.name=='nt':
                 from distutils.msvccompiler import get_build_architecture
@@ -123,8 +132,6 @@
                     target_f.write('#define %s\n' % (d))
                 else:
                     target_f.write('#define %s %s\n' % (d[0],d[1]))
-            if not nosmp:  # default is to use WITH_THREAD
-                target_f.write('#ifdef WITH_THREAD\n#define NPY_ALLOW_THREADS 1\n#else\n#define NPY_ALLOW_THREADS 0\n#endif\n')
             target_f.close()
             print 'File:',target
             target_f = open(target)
@@ -151,6 +158,39 @@
         config.add_data_files((header_dir,target))
         return target
 
+    def generate_numpyconfig_h(ext, build_dir):
+        """Depends on config.h: generate_config_h has to be called before !"""
+        target = join(build_dir,'numpyconfig.h')
+        if newer(__file__,target):
+            config_cmd = config.get_config_cmd()
+            log.info('Generating %s',target)
+            testcode = generate_numpyconfig_code(target)
+
+            from distutils import sysconfig
+            python_include = sysconfig.get_python_inc()
+            python_h = join(python_include, 'Python.h')
+            if not os.path.isfile(python_h):
+                raise SystemError,\
+                      "Non-existing %s. Perhaps you need to install"\
+                      " python-dev|python-devel." % (python_h)
+
+            config.numpy_include_dirs
+            result = config_cmd.try_run(testcode, 
+                                include_dirs = [python_include] + \
+                                                       config.numpy_include_dirs,
+                                        library_dirs = default_lib_dirs)
+
+            if not result:
+                raise SystemError,"Failed to generate numpy configuration. "\
+                      "See previous error messages for more information."
+
+            print 'File: %s' % target
+            target_f = open(target)
+            print target_f.read()
+            target_f.close()
+            print 'EOF'
+        return target
+                                
     def generate_api_func(module_name):
         def generate_api(ext, build_dir):
             script = join(codegen_dir, module_name + '.py')
@@ -205,6 +245,7 @@
     config.add_extension('multiarray',
                          sources = [join('src','multiarraymodule.c'),
                                     generate_config_h,
+                                    generate_numpyconfig_h,
                                     generate_array_api,
                                     join('src','scalartypes.inc.src'),
                                     join('src','arraytypes.inc.src'),
@@ -216,6 +257,7 @@
 
     config.add_extension('umath',
                          sources = [generate_config_h,
+                                    generate_numpyconfig_h,
                                     join('src','umathmodule.c.src'),
                                     generate_umath_c,
                                     generate_ufunc_api,
@@ -231,6 +273,7 @@
     config.add_extension('_sort',
                          sources=[join('src','_sortmodule.c.src'),
                                   generate_config_h,
+                                  generate_numpyconfig_h,
                                   generate_array_api,
                                   ],
                          )
@@ -238,6 +281,7 @@
     config.add_extension('scalarmath',
                          sources=[join('src','scalarmathmodule.c.src'),
                                   generate_config_h,
+                                  generate_numpyconfig_h,
                                   generate_array_api,
                                   generate_ufunc_api],
                          )
@@ -342,6 +386,85 @@
     testcode = '\n'.join(testcode)
     return testcode
 
+def generate_numpyconfig_code(target):
+    """Return the source code as a string of the code to generate the
+    numpyconfig header file."""
+    if sys.platform == 'win32':
+        target = target.replace('\\','\\\\')
+    # Config symbols to prepend
+    prepends = [('NPY_SIZEOF_SHORT', 'SIZEOF_SHORT'),
+            ('NPY_SIZEOF_INT', 'SIZEOF_INT'),
+            ('NPY_SIZEOF_LONG', 'SIZEOF_LONG'),
+            ('NPY_SIZEOF_FLOAT', 'SIZEOF_FLOAT'),
+            ('NPY_SIZEOF_DOUBLE', 'SIZEOF_DOUBLE'),
+            ('NPY_SIZEOF_LONGDOUBLE', 'SIZEOF_LONG_DOUBLE'),
+            ('NPY_SIZEOF_PY_INTPTR_T', 'SIZEOF_PY_INTPTR_T')]
+
+    testcode = ["""
+#include <Python.h>
+#include "config.h"
+
+int main()
+{   
+    FILE* f;
+   
+    f = fopen("%s", "w");
+    if (f == NULL) {
+        return -1;
+    }
+""" % target]
+
+    testcode.append(r"""
+    fprintf(f, "/*\n * This file is generated by %s. DO NOT EDIT \n */\n");
+""" % __file__)
+
+    # Prepend NPY_ to any SIZEOF defines
+    testcode.extend([r'    fprintf(f, "#define ' + i + r' %%d \n", %s);' % j for i, j in prepends])
+
+    # Conditionally define NPY_NO_SIGNAL
+    if is_npy_no_signal():
+        testcode.append(r'    fprintf(f, "\n#define NPY_NO_SIGNAL\n");')
+
+    # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot
+    # support thread support reliably
+    if is_npy_no_smp():
+        testcode.append(r'    fprintf(f, "#define NPY_NO_SMP 1\n");')
+    else:
+        testcode.append(r'    fprintf(f, "#define NPY_NO_SMP 0\n");')
+
+    tmpcode = r"""
+    #ifdef PY_LONG_LONG
+        fprintf(f, "\n#define %s %%d \n", %s);
+        fprintf(f, "#define %s %%d \n", %s);
+    #else
+        fprintf(f, "/* PY_LONG_LONG not defined  */ \n");
+    #endif"""
+    testcode.append(tmpcode % ('NPY_SIZEOF_LONGLONG', 'SIZEOF_LONG_LONG',
+                               'NPY_SIZEOF_PY_LONG_LONG', 'SIZEOF_PY_LONG_LONG'))
+
+    testcode.append(r"""
+#ifndef CHAR_BIT
+          {
+             unsigned char var = 2;
+             int i = 0;
+             while (var >= 2) {
+                     var = var << 1;
+                     i++;
+             }
+             fprintf(f,"#define CHAR_BIT %d\n", i+1);
+          }
+#else
+          fprintf(f, "/* #define CHAR_BIT %d */\n", CHAR_BIT);
+#endif""")
+
+    testcode.append("""
+    fclose(f);
+
+    return 0;
+}
+""")
+    return "\n".join(testcode)
+
 if __name__=='__main__':
     from numpy.distutils.core import setup
     setup(configuration=configuration)

Copied: trunk/numpy/core/setupscons.py (from rev 4772, branches/build_with_scons/numpy/core/setupscons.py)

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/src/arraytypes.inc.src	2008-02-08 10:12:16 UTC (rev 4773)
@@ -1,4 +1,5 @@
 /* -*- c -*- */
+#include "config.h"
 
 static longlong
 MyPyLong_AsLongLong(PyObject *vv)

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/src/multiarraymodule.c	2008-02-08 10:12:16 UTC (rev 4773)
@@ -7269,7 +7269,7 @@
 }
 
 
-#ifndef NPY_NO_SIGNAL
+#ifndef __NPY_PRIVATE_NO_SIGNAL
 
 SIGJMP_BUF _NPY_SIGINT_BUF;
 

Modified: trunk/numpy/core/src/umathmodule.c.src
===================================================================
--- trunk/numpy/core/src/umathmodule.c.src	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/core/src/umathmodule.c.src	2008-02-08 10:12:16 UTC (rev 4773)
@@ -5,6 +5,7 @@
 #define _UMATHMODULE
 #include "numpy/ufuncobject.h"
 #include "abstract.h"
+#include "config.h"
 #include <math.h>
 
 /* A whole slew of basic math functions are provided originally

Modified: trunk/numpy/distutils/command/build.py
===================================================================
--- trunk/numpy/distutils/command/build.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/distutils/command/build.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -32,3 +32,9 @@
         if build_scripts is None:
             self.build_scripts = os.path.join(self.build_base,
                                               'scripts' + plat_specifier)
+
+    def run(self):
+        # Make sure that scons based extensions are complete.
+        self.run_command('scons')
+
+        old_build.run(self)

Modified: trunk/numpy/distutils/command/config.py
===================================================================
--- trunk/numpy/distutils/command/config.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/distutils/command/config.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -101,6 +101,21 @@
                                  (body, headers, include_dirs,
                                   libraries, library_dirs, lang))
 
+    def check_decl(self, symbol,
+                   headers=None, include_dirs=None):
+        self._check_compiler()
+        body = """
+int main()
+{
+#ifndef %s
+    (void) %s;
+#endif
+    ;
+    return 0;
+}""" % (symbol, symbol)
+
+        return self.try_compile(body, headers, include_dirs)
+
     def check_func(self, func,
                    headers=None, include_dirs=None,
                    libraries=None, library_dirs=None,

Copied: trunk/numpy/distutils/command/scons.py (from rev 4772, branches/build_with_scons/numpy/distutils/command/scons.py)

Modified: trunk/numpy/distutils/core.py
===================================================================
--- trunk/numpy/distutils/core.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/distutils/core.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -21,9 +21,10 @@
 import distutils.dist
 
 from numpy.distutils.extension import Extension
+from numpy.distutils.numpy_distribution import NumpyDistribution
 from numpy.distutils.command import config, config_compiler, \
      build, build_py, build_ext, build_clib, build_src, build_scripts, \
-     sdist, install_data, install_headers, install, bdist_rpm
+     sdist, install_data, install_headers, install, bdist_rpm, scons
 from numpy.distutils.misc_util import get_data_files, is_sequence, is_string
 
 numpy_cmdclass = {'build':            build.build,
@@ -36,6 +37,7 @@
                   'build_py':         build_py.build_py,
                   'build_clib':       build_clib.build_clib,
                   'sdist':            sdist.sdist,
+                  'scons':            scons.scons,
                   'install_data':     install_data.install_data,
                   'install_headers':  install_headers.install_headers,
                   'install':          install.install,
@@ -95,9 +97,10 @@
     # class is local to a function in setuptools.command.easy_install
     if dist is not None and \
             'DistributionWithoutHelpCommands' in repr(dist):
+        raise NotImplementedError("setuptools not supported yet for numpy.scons branch")
         dist = None
     if always and dist is None:
-        dist = distutils.dist.Distribution()
+        dist = NumpyDistribution()
     return dist
 
 def _exit_interactive_session(_cache=[]):
@@ -175,6 +178,9 @@
        and 'headers' not in new_attr:
         new_attr['headers'] = []
 
+    # Use our custom NumpyDistribution class instead of distutils' one
+    new_attr['distclass'] = NumpyDistribution
+
     return old_setup(**new_attr)
 
 def _check_append_library(libraries, item):

Modified: trunk/numpy/distutils/misc_util.py
===================================================================
--- trunk/numpy/distutils/misc_util.py	2008-02-08 09:48:31 UTC (rev 4772)
+++ trunk/numpy/distutils/misc_util.py	2008-02-08 10:12:16 UTC (rev 4773)
@@ -112,11 +112,11 @@
     return minrelpath(joined)
 
 def get_mathlibs(path=None):
-    """Return the MATHLIB line from config.h
+    """Return the MATHLIB line from numpyconfig.h
     """
     if path is None:
         path = os.path.join(get_numpy_include_dirs()[0], 'numpy')
-    config_file = os.path.join(path,'config.h')
+    config_file = os.path.join(path,'numpyconfig.h')
     fid = open(config_file)
     mathlibs = []
     s = '#define MATHLIB'
@@ -574,7 +574,7 @@
 class Configuration(object):
 
     _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',
-                  'libraries', 'headers', 'scripts', 'py_modules']
+                  'libraries', 'headers', 'scripts', 'py_modules', 'scons_data']
     _dict_keys = ['package_dir']
     _extra_keys = ['name', 'version']
 
@@ -586,6 +586,7 @@
                  top_path=None,
                  package_path=None,
                  caller_level=1,
+                 setup_name='setup.py',
                  **attrs):
         """Construct configuration instance of a package.
 
@@ -674,6 +675,8 @@
             if caller_instance.options['delegate_options_to_subpackages']:
                 self.set_options(**caller_instance.options)
 
+        self.setup_name = setup_name
+
     def todict(self):
         """Return configuration distionary suitable for passing
         to distutils.core.setup() function.
@@ -795,7 +798,7 @@
         else:
             subpackage_path = njoin([subpackage_path] + l[:-1])
             subpackage_path = self.paths([subpackage_path])[0]
-        setup_py = njoin(subpackage_path, 'setup.py')
+        setup_py = njoin(subpackage_path, self.setup_name)
         if not self.options['ignore_setup_xxx_py']:
             if not os.path.isfile(setup_py):
                 setup_py = njoin(subpackage_path,
@@ -1165,6 +1168,55 @@
             self.warn('distutils distribution has been initialized,'\
                       ' it may be too late to add a library '+ name)
 
+    def add_sconscript(self, sconscript, subpackage_path=None,
+                       standalone = False, pre_hook = None,
+                       post_hook = None, source_files = None):
+        """Add a sconscript to configuration.
+
+        pre_hook and post hook should be sequences of callable, which will be
+        use before and after executing scons. """
+        if standalone:
+            parent_name = None
+        else:
+            parent_name = self.name
+
+        dist = self.get_distribution()
+        # Convert the sconscript name to a relative filename (relative from top
+        # setup.py's directory)
+        fullsconsname = self.paths(sconscript)[0]
+
+        # XXX: Think about a way to automatically register source files from
+        # scons...
+        full_source_files = []
+        if source_files:
+            full_source_files.extend([self.paths(i)[0] for i in source_files])
+
+        if dist is not None:
+            dist.scons_data.append((fullsconsname, 
+                                    pre_hook, 
+                                    post_hook,
+                                    full_source_files,
+                                    parent_name))
+            self.warn('distutils distribution has been initialized,'\
+                      ' it may be too late to add a subpackage '+ subpackage_name)
+            # XXX: we add a fake extension, to correctly initialize some
+            # options in distutils command.
+            dist.add_extension('', sources = [])
+        else:
+            self.scons_data.append((fullsconsname, 
+                                    pre_hook, 
+                                    post_hook,
+                                    full_source_files,
+                                    parent_name))
+            # XXX: we add a fake extension, to correctly initialize some
+            # options in distutils command.
+            self.add_extension('', sources = [])
+
+    def add_configres(self):
+        from numscons import get_scons_configres_dir, get_scons_configres_filename
+        file = os.path.join(get_scons_configres_dir(), self.local_path, 
+                            get_scons_configres_filename())
+
     def add_scripts(self,*files):
         """Add scripts to configuration.
         """
@@ -1394,6 +1446,12 @@
         """
         self.py_modules.append((self.name,name,generate_config_py))
 
+    def scons_make_config_py(self, name = '__config__'):
+        """Generate package __config__.py file containing system_info
+        information used during building the package.
+        """
+        self.py_modules.append((self.name, name, scons_generate_config_py))
+
     def get_info(self,*names):
         """Get resources information.
         """
@@ -1425,6 +1483,50 @@
     # 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
+    from numscons import get_scons_configres_dir, get_scons_configres_filename
+    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:
+                cnt = fid.read()
+                d[pkg_name] = eval(cnt)
+            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):

Copied: trunk/numpy/distutils/numpy_distribution.py (from rev 4772, branches/build_with_scons/numpy/distutils/numpy_distribution.py)

Copied: trunk/numpy/distutils/setupscons.py (from rev 4772, branches/build_with_scons/numpy/distutils/setupscons.py)

Copied: trunk/numpy/f2py/setupscons.py (from rev 4772, branches/build_with_scons/numpy/f2py/setupscons.py)

Copied: trunk/numpy/fft/SConstruct (from rev 4772, branches/build_with_scons/numpy/fft/SConstruct)

Copied: trunk/numpy/fft/setupscons.py (from rev 4772, branches/build_with_scons/numpy/fft/setupscons.py)

Copied: trunk/numpy/lib/SConstruct (from rev 4772, branches/build_with_scons/numpy/lib/SConstruct)

Copied: trunk/numpy/lib/setupscons.py (from rev 4772, branches/build_with_scons/numpy/lib/setupscons.py)

Copied: trunk/numpy/linalg/SConstruct (from rev 4772, branches/build_with_scons/numpy/linalg/SConstruct)

Copied: trunk/numpy/linalg/setupscons.py (from rev 4772, branches/build_with_scons/numpy/linalg/setupscons.py)

Copied: trunk/numpy/numarray/SConstruct (from rev 4772, branches/build_with_scons/numpy/numarray/SConstruct)

Copied: trunk/numpy/numarray/setupscons.py (from rev 4772, branches/build_with_scons/numpy/numarray/setupscons.py)

Copied: trunk/numpy/oldnumeric/setupscons.py (from rev 4772, branches/build_with_scons/numpy/oldnumeric/setupscons.py)

Copied: trunk/numpy/random/SConstruct (from rev 4772, branches/build_with_scons/numpy/random/SConstruct)

Copied: trunk/numpy/random/setupscons.py (from rev 4772, branches/build_with_scons/numpy/random/setupscons.py)

Copied: trunk/numpy/setupscons.py (from rev 4772, branches/build_with_scons/numpy/setupscons.py)

Copied: trunk/numpy/testing/setupscons.py (from rev 4772, branches/build_with_scons/numpy/testing/setupscons.py)

Copied: trunk/setupscons.py (from rev 4772, branches/build_with_scons/setupscons.py)

Copied: trunk/test.sh (from rev 4772, branches/build_with_scons/test.sh)




More information about the Numpy-svn mailing list