[Numpy-svn] r4455 - branches/numpy.scons/numpy/distutils/scons/core

numpy-svn@scip... numpy-svn@scip...
Wed Nov 14 01:34:16 CST 2007


Author: cdavid
Date: 2007-11-14 01:34:10 -0600 (Wed, 14 Nov 2007)
New Revision: 4455

Modified:
   branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
Log:
Clean up GetNumpyEnvironment

Modified: branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py	2007-11-14 06:46:09 UTC (rev 4454)
+++ branches/numpy.scons/numpy/distutils/scons/core/numpyenv.py	2007-11-14 07:34:10 UTC (rev 4455)
@@ -114,50 +114,18 @@
     env.AppendUnique(LINKFLAGS = env['NUMPY_OPTIM_LDFLAGS'])
     return env
 
-def _GetNumpyEnvironment(args):
-    """Call this with args = ARGUMENTS."""
-    from SCons.Environment import Environment
-    from SCons.Tool import Tool, FindTool, FindAllTools
-    from SCons.Script import BuildDir, Help
-    from SCons.Errors import EnvironmentError
-
-    # XXX: I would prefer subclassing Environment, because we really expect
-    # some different behaviour than just Environment instances...
-    opts = GetNumpyOptions(args)
-
-    # Get the python extension suffix
-    # XXX this should be defined somewhere else. Is there a way to reliably get
-    # all the necessary informations specific to python extensions (linkflags,
-    # etc...) dynamically ?
-    pyextsuffix = get_config_vars('SO')
-
-    # We set tools to an empty list, to be sure that the custom options are
-    # given first. We have to 
-    env = Environment(options = opts, tools = [], PYEXTSUFFIX = pyextsuffix)
-
-    # Add the file substitution tool
-    TOOL_SUBST(env)
-
-    # Setting dirs according to command line options
-    env.AppendUnique(build_dir = pjoin(env['build_prefix'], env['src_dir']))
-    env.AppendUnique(distutils_installdir = pjoin(env['distutils_libdir'], 
-                                                  env['pkg_name']))
-
-    # ===============================================
-    # Setting tools according to command line options
-
-    # List of supplemental paths to take into account
-    path_list = []
-
+def initialize_cc(env, path_list):
     # XXX: how to handle tools which are not in standard location ? Is adding
     # the full path of the compiler enough ? (I am sure some compilers also
     # need LD_LIBRARY_SHARED and other variables to be set, too....)
+    from SCons.Tool import Tool
+
     if len(env['cc_opt']) > 0:
         try:
             if len(env['cc_opt_path']) > 0:
                 if env['cc_opt'] == 'intelc':
                     # Intel Compiler SCons.Tool has a special way to set the
-                    # path, o we use this one instead of changing
+                    # path, so we use this one instead of changing
                     # env['ENV']['PATH'].
                     t = Tool(env['cc_opt'], 
                              topdir = os.path.split(env['cc_opt_path'])[0])
@@ -166,8 +134,6 @@
                 else:
                     if is_cc_suncc(pjoin(env['cc_opt_path'], env['cc_opt'])):
                         env['cc_opt'] = 'suncc'
-                    # XXX: what is the right way to add one directory in the
-                    # PATH ? (may not work on windows).
                     t = Tool(env['cc_opt'])
                     t(env) 
                     customize_cc(t.name, env)
@@ -187,12 +153,13 @@
         t(env)
         customize_cc(t.name, env)
 
+def initialize_f77(env, path_list):
+    from SCons.Tool import Tool
+
     # F77 compiler
     if len(env['f77_opt']) > 0:
         try:
             if len(env['f77_opt_path']) > 0:
-                # XXX: what is the right way to add one directory in the
-                # PATH ? (may not work on windows).
                 t = Tool(env['f77_opt'], toolpath = ['numpy/distutils/scons/tools'])
                 t(env) 
                 path_list.append(env['f77_opt_path'])
@@ -210,37 +177,48 @@
         else:
             print "========== NO FORTRAN COMPILER FOUND ==========="
 
-    if not env['ENV'].has_key('PATH'):
-        env['ENV']['PATH'] = os.pathsep.join(path_list)
-    else:
-        env['ENV']['PATH'] = os.pathsep.join(path_list + env['ENV']['PATH'].split(os.pathsep))
+def _GetNumpyEnvironment(args):
+    """Call this with args = ARGUMENTS."""
+    from SCons.Environment import Environment
+    from SCons.Tool import Tool, FindTool, FindAllTools
+    from SCons.Script import BuildDir, Help
+    from SCons.Errors import EnvironmentError
 
-    print env['ENV']['PATH']
-    # XXX: Really, we should use our own subclass of Environment, instead of
-    # adding Numpy* functions !
+    # XXX: I would prefer subclassing Environment, because we really expect
+    # some different behaviour than just Environment instances...
+    opts = GetNumpyOptions(args)
 
-    # Put config code and log in separate dir for each subpackage
-    from utils import curry
-    NumpyConfigure = curry(env.Configure, 
-                           conf_dir = pjoin(env['build_dir'], '.sconf'), 
-                           log_file = pjoin(env['build_dir'], 'config.log'))
-    env.NumpyConfigure = NumpyConfigure
+    # Get the python extension suffix
+    # XXX this should be defined somewhere else. Is there a way to reliably get
+    # all the necessary informations specific to python extensions (linkflags,
+    # etc...) dynamically ?
+    pyextsuffix = get_config_vars('SO')
 
-    # XXX: Huge, ugly hack ! SConsign needs an absolute path or a path
-    # relative to where the SConstruct file is. We have to find the path of
-    # the build dir relative to the src_dir: we add n .., where n is the number
-    # of occureant of the path separator in the src dir.
-    def get_build_relative_src(srcdir, builddir):
-        n = srcdir.count(os.sep)
-        if len(srcdir) > 0 and not srcdir == '.':
-            n += 1
-        return pjoin(os.sep.join([os.pardir for i in range(n)]), builddir)
-    sconsign = pjoin(get_build_relative_src(env['src_dir'], 
-                                            env['build_dir']),
-                     '.sconsign.dblite')
-    env.SConsignFile(sconsign)
+    # We set tools to an empty list, to be sure that the custom options are
+    # given first. We have to 
+    env = Environment(options = opts, tools = [], PYEXTSUFFIX = pyextsuffix)
 
-    # ========================================================================
+    # Add the file substitution tool
+    TOOL_SUBST(env)
+
+    # Setting dirs according to command line options
+    env.AppendUnique(build_dir = pjoin(env['build_prefix'], env['src_dir']))
+    env.AppendUnique(distutils_installdir = pjoin(env['distutils_libdir'], 
+                                                  env['pkg_name']))
+
+    #------------------------------------------------
+    # Setting tools according to command line options
+    #------------------------------------------------
+
+    # List of supplemental paths to take into account
+    path_list = []
+
+    # Initialize CC tool from distutils info
+    initialize_cc(env, path_list)
+
+    # Initialize F77 tool from distutils info
+    initialize_f77(env, path_list)
+
     # Adding default tools for the one we do not customize: mingw is special
     # according to scons, don't ask me why, but this does not work as expected
     # for this tool.
@@ -263,6 +241,43 @@
 
     finalize_env(env)
 
+    # Add the tool paths in the environment
+    if not env['ENV'].has_key('PATH'):
+        env['ENV']['PATH'] = os.pathsep.join(path_list)
+    else:
+        env['ENV']['PATH'] = os.pathsep.join(path_list + env['ENV']['PATH'].split(os.pathsep))
+
+    # XXX: Really, we should use our own subclass of Environment, instead of
+    # adding Numpy* functions !
+
+    #---------------
+    #     Misc
+    #---------------
+
+    # Put config code and log in separate dir for each subpackage
+    from utils import curry
+    NumpyConfigure = curry(env.Configure, 
+                           conf_dir = pjoin(env['build_dir'], '.sconf'), 
+                           log_file = pjoin(env['build_dir'], 'config.log'))
+    env.NumpyConfigure = NumpyConfigure
+
+    # XXX: Huge, ugly hack ! SConsign needs an absolute path or a path relative
+    # to where the SConstruct file is. We have to find the path of the build
+    # dir relative to the src_dir: we add n .., where n is the number of
+    # occurances of the path separator in the src dir.
+    def get_build_relative_src(srcdir, builddir):
+        n = srcdir.count(os.sep)
+        if len(srcdir) > 0 and not srcdir == '.':
+            n += 1
+        return pjoin(os.sep.join([os.pardir for i in range(n)]), builddir)
+
+    sconsign = pjoin(get_build_relative_src(env['src_dir'], 
+                                            env['build_dir']),
+                     '.sconsign.dblite')
+    env.SConsignFile(sconsign)
+
+    # Add HOME in the environment: some tools seem to require it (Intel
+    # compiler, for licenses stuff)
     try:
         env['ENV']['HOME'] = os.environ['HOME']
     except KeyError:



More information about the Numpy-svn mailing list