[Avida-cvs] [avida-svn] r717 - in development: source source/bindings source/bindings/Boost.Python support/utils/AvidaUtils

kaben@myxo.css.msu.edu kaben at myxo.css.msu.edu
Sat May 27 22:46:01 PDT 2006


Author: kaben
Date: 2006-05-28 01:46:01 -0400 (Sun, 28 May 2006)
New Revision: 717

Added:
   development/source/bindings/Boost.Python/SConscript
   development/source/bindings/Boost.Python/cUInt.pyste
   development/source/bindings/SConscript
   development/support/utils/AvidaUtils/GCCXMLTool.py
   development/support/utils/AvidaUtils/PythonTool.py
Modified:
   development/source/SConscript
   development/support/utils/AvidaUtils/CmdLineOpts.py
   development/support/utils/AvidaUtils/PlatformTool.py
   development/support/utils/AvidaUtils/__init__.py
Log:

Initial 'AvidaCore' Python package. For start, this incorporates just
the cUInt class from Avida, and it only works on OS X.



Modified: development/source/SConscript
===================================================================
--- development/source/SConscript	2006-05-27 10:26:27 UTC (rev 716)
+++ development/source/SConscript	2006-05-28 05:46:01 UTC (rev 717)
@@ -21,4 +21,7 @@
 if environment['enableTestCode'] in ('True', '1', 1):
   environment.SConscript('testsuites/SConscript')
 
+if environment['enablePyPkg'] in ('True', '1', 1):
+  environment.SConscript('bindings/Boost.Python/SConscript')
+
 # vim: set ft=python:

Added: development/source/bindings/Boost.Python/SConscript
===================================================================
--- development/source/bindings/Boost.Python/SConscript	2006-05-27 10:26:27 UTC (rev 716)
+++ development/source/bindings/Boost.Python/SConscript	2006-05-28 05:46:01 UTC (rev 717)
@@ -0,0 +1,45 @@
+##############################################################################
+## Copyright (C) 1999-2005 Michigan State University                        ##
+## Based on work Copyright (C) 1993-2003 California Institute of Technology ##
+##                                                                          ##
+## Read the COPYING and README files, or contact 'avida at alife.org',         ##
+## before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     ##
+##############################################################################
+    
+import os
+    
+Import('environment')
+e = environment
+
+pf = e.File('pyste_util.py')
+e.Local(pf)
+
+package_name = 'AvidaCore'
+package_modules = e.PystePackageSubmodule(
+  [
+    'cUInt.pyste',
+  ],
+  pyste_package_name = package_name,
+  LIBS = ['tools'],
+)
+package_init_file = e.PystePackageInitFile(
+  package_modules,
+  pyste_package_name = package_name,
+)
+package = e.PystePackage(
+  package_modules + package_init_file,
+  pyste_package_name = package_name,
+)
+
+package_install_dir = os.path.join(e['execPrefix'], package_name)
+e.Install(
+  package_install_dir,
+  [package_modules, package_init_file]
+)
+e.Alias(
+  'install',
+  package_install_dir
+)
+
+#
+# vim: set ft=python:

Added: development/source/bindings/Boost.Python/cUInt.pyste
===================================================================
--- development/source/bindings/Boost.Python/cUInt.pyste	2006-05-27 10:26:27 UTC (rev 716)
+++ development/source/bindings/Boost.Python/cUInt.pyste	2006-05-28 05:46:01 UTC (rev 717)
@@ -0,0 +1,4 @@
+
+cUInt = Class("cUInt", "cUInt.h")
+
+# vim: set ft=python:

Added: development/source/bindings/SConscript
===================================================================
--- development/source/bindings/SConscript	2006-05-27 10:26:27 UTC (rev 716)
+++ development/source/bindings/SConscript	2006-05-28 05:46:01 UTC (rev 717)
@@ -0,0 +1,16 @@
+
+##############################################################################
+## Copyright (C) 1999-2005 Michigan State University                        ##
+## Based on work Copyright (C) 1993-2003 California Institute of Technology ##
+##                                                                          ##
+## Read the COPYING and README files, or contact 'avida at alife.org',         ##
+## before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     ##
+##############################################################################
+    
+import os
+    
+Import('environment')
+e = environment
+
+#
+# vim: set ft=python:

Modified: development/support/utils/AvidaUtils/CmdLineOpts.py
===================================================================
--- development/support/utils/AvidaUtils/CmdLineOpts.py	2006-05-27 10:26:27 UTC (rev 716)
+++ development/support/utils/AvidaUtils/CmdLineOpts.py	2006-05-28 05:46:01 UTC (rev 717)
@@ -49,12 +49,12 @@
       """Set to "1" to build and run test code.""",
       '$plat_default_enableTestCode',
   ) )
-  #opts.Add(
-  #  SCons.Options.BoolOption(
-  #    'enablePyPkg',
-  #  """Set to "1" to wrap c++ interfaces for use in Python scripts.""",
-  #    '$plat_default_enablePyPkg',
-  #) )
+  opts.Add(
+    SCons.Options.BoolOption(
+      'enablePyPkg',
+    """Set to "1" to wrap c++ interfaces for use in Python scripts.""",
+      '$plat_default_enablePyPkg',
+  ) )
 
   #opts.Add(
   #  SCons.Options.BoolOption(
@@ -152,46 +152,46 @@
   #  )
   #)
   #
-  #opts.Add(
-  #  'pythonCommand',
-  #  'Command used to invoke Python interpreter.',
-  #  '$plat_default_pythonCommand',
-  #)
-  #opts.Add(
-  #  'boostIncludeDir',
-  #  'Path to the header directory for Boost.',
-  #  '$plat_default_boostIncludeDir',
-  #)
-  #opts.Add(
-  #  'boostPythonLibDir',
-  #  'Directory containing Boost Python library.',
-  #  '$plat_default_boostPythonLibDir',
-  #)
-  #opts.Add(
-  #  'boostPythonLib',
-  #  """Name of the Boost Python library.
-  #  - Note : name is sans prefix and suffix; e.g., boost_python-1_33.""",
-  #  '$plat_default_boostPythonLib',
-  #)
-  #opts.Add(
-  #  'GccXmlCommand',
-  #  'Command used to call gccxml.',
-  #  '$plat_default_GccXmlCommand',
-  #)
-  #opts.Add(
-  #  'pysteScriptPath',
-  #  'Full path to Pyste script.',
-  #  '$plat_default_pysteScriptPath',
-  #)
-  #opts.Add(
-  #  'pysteScriptCommand',
-  #  'Command used to call Pyste script.',
-  #  '$plat_default_pysteScriptCommand',
-  #)
+  opts.Add(
+    'pythonCommand',
+    'Command used to invoke Python interpreter.',
+    '$plat_default_pythonCommand',
+  )
+  opts.Add(
+    'boostIncludeDir',
+    'Path to the header directory for Boost.',
+    '$plat_default_boostIncludeDir',
+  )
+  opts.Add(
+    'boostPythonLibDir',
+    'Directory containing Boost Python library.',
+    '$plat_default_boostPythonLibDir',
+  )
+  opts.Add(
+    'boostPythonLib',
+    """Name of the Boost Python library.
+    - Note : name is sans prefix and suffix; e.g., boost_python-1_33.""",
+    '$plat_default_boostPythonLib',
+  )
+  opts.Add(
+    'GccXmlCommand',
+    'Command used to call gccxml.',
+    '$plat_default_GccXmlCommand',
+  )
+  opts.Add(
+    'pysteScriptPath',
+    'Full path to Pyste script.',
+    '$plat_default_pysteScriptPath',
+  )
+  opts.Add(
+    'pysteScriptCommand',
+    'Command used to call Pyste script.',
+    '$plat_default_pysteScriptCommand',
+  )
 
   # FIXME : Move me to support/utils/PysteTool.py, into a conftest
   # therein. @kgn
-  #env.Append(PYSTE_CMD = '$pysteScriptCommand')
+  env.Append(PYSTE_CMD = '$pysteScriptCommand')
 
   #opts.Add(
   #  SCons.Options.BoolOption(

Added: development/support/utils/AvidaUtils/GCCXMLTool.py
===================================================================
--- development/support/utils/AvidaUtils/GCCXMLTool.py	2006-05-27 10:26:27 UTC (rev 716)
+++ development/support/utils/AvidaUtils/GCCXMLTool.py	2006-05-28 05:46:01 UTC (rev 717)
@@ -0,0 +1,54 @@
+##############################################################################
+## Copyright (C) 1999-2005 Michigan State University                        ##
+## Based on work Copyright (C) 1993-2003 California Institute of Technology ##
+##                                                                          ##
+## Read the COPYING and README files, or contact 'avida at alife.org',         ##
+## before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     ##
+##############################################################################
+
+"""
+GCCXMLTool
+
+Tool-specific initialization for gccxml.
+
+Provides configuration variables used to call gccxml. gccxml is used by
+Boost.Python's Pyste to help generate C++ files interfacing C++
+libraries to Python.
+"""
+
+import SCons
+import os.path
+
+def _checkKeySubst(env, key):
+  if env.Dictionary().has_key(key) and (None != env[key]): return env.subst('$%s' % key)
+
+def find(env):
+  """
+  Searches for gccxml executable along PATH or PATHEXT environment variable.
+  """
+  gccxml_command = _checkKeySubst(env, 'GccXmlCommand')
+  if not gccxml_command or not os.path.exists(gccxml_command):
+    env.Append(
+      GCCXML_TOOL_ERR = """
+GCCXMLTool error:
+  Couldn't find gccxml executable. Is command-line option
+  "GccXmlCommand" set correctly?
+"""
+    )
+
+
+def generate(env):
+  """
+  Adds construction variables for gccxml to an Environment.
+  """
+  env.SetDefault(
+    GCCXML_TOOL_ERR = '',
+    GCCXML_CMD = '$GccXmlCommand',
+  )
+  if env.subst('$runConfTests') in ['yes', '1']:
+    find(env)
+
+def exists(env):
+  return find(env)
+
+

Modified: development/support/utils/AvidaUtils/PlatformTool.py
===================================================================
--- development/support/utils/AvidaUtils/PlatformTool.py	2006-05-27 10:26:27 UTC (rev 716)
+++ development/support/utils/AvidaUtils/PlatformTool.py	2006-05-28 05:46:01 UTC (rev 717)
@@ -25,7 +25,8 @@
   env.SetDefault(
     PLATFORM_CPPPATH = CLVar('/usr/include /usr/local/include /opt/local/include' '$CPPPATH'),
     PLATFORM_LIBPATH = CLVar('/usr/lib /usr/local/lib /opt/local/lib' '$LIBPATH'),
-    _PLATFORM_DEBUG_BUILD_FLAGS = "-g $COMPILER_WARNING_FLAGS -pedantic -DDEBUG",
+    #_PLATFORM_DEBUG_BUILD_FLAGS = "-g $COMPILER_WARNING_FLAGS -pedantic -DDEBUG",
+    _PLATFORM_DEBUG_BUILD_FLAGS = "-g $COMPILER_WARNING_FLAGS -DDEBUG",
     _PLATFORM_RELEASE_DEBUG_BUILD_FLAGS = "-O2 -ffast-math -g $COMPILER_WARNING_FLAGS -pedantic -DDEBUG",
     _PLATFORM_RELEASE_BUILD_FLAGS = "-O3 -ffast-math -DNDEBUG",
     _PLATFORM_MINIMUM_RELEASE_BUILD_FLAGS = "-Os -DNDEBUG",
@@ -54,7 +55,7 @@
     plat_default_boostPythonLibDir = None,
     plat_default_boostPythonLib = None,
     plat_default_GccXmlCommand = None,
-    plat_default_pysteScriptPath = os.path.join(sys.path[0], '${support_utils_rel_dir}', 'AvidaPyste.py'),
+    plat_default_pysteScriptPath = os.path.join(sys.path[0], '${AvidaUtils_path}', 'AvidaPyste.py'),
     plat_default_pysteScriptCommand = SCons.Util.CLVar('$pythonCommand $pysteScriptPath'),
   )
 
@@ -354,7 +355,7 @@
     plat_default_boostPythonLibDir = None,
     plat_default_boostPythonLib = None,
     plat_default_GccXmlCommand = None,
-    plat_default_pysteScriptPath = os.path.join(sys.path[0], '${support_utils_rel_dir}', 'AvidaPyste.py'),
+    plat_default_pysteScriptPath = os.path.join(sys.path[0], '${AvidaUtils_path}', 'AvidaPyste.py'),
     plat_default_pysteScriptCommand = SCons.Util.CLVar('$pythonCommand $pysteScriptPath'),
   )
   env.SetDefault(

Added: development/support/utils/AvidaUtils/PythonTool.py
===================================================================
--- development/support/utils/AvidaUtils/PythonTool.py	2006-05-27 10:26:27 UTC (rev 716)
+++ development/support/utils/AvidaUtils/PythonTool.py	2006-05-28 05:46:01 UTC (rev 717)
@@ -0,0 +1,123 @@
+##############################################################################
+## Copyright (C) 1999-2005 Michigan State University                        ##
+## Based on work Copyright (C) 1993-2003 California Institute of Technology ##
+##                                                                          ##
+## Read the COPYING and README files, or contact 'avida at alife.org',         ##
+## before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     ##
+##############################################################################
+
+"""
+PythonTool
+
+Tool-specific initialization for Python.
+
+Provides configuration variables used to build Python extension modules.
+"""
+
+## Values on my PowerBook:
+#
+#  env['PYTHON']            '/usr/local/bin/python'
+#  env['PYTHON_CC']         'gcc'
+#  env['PYTHON_CXX']        'c++'
+#  env['PYTHON_BASECFLAGS'] '-fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic'
+#  env['PYTHON_OPT']        '-DNDEBUG -g -O3 -Wall -Wstrict-prototypes'
+#  env['PYTHON_INCLUDEPY']  '/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4'
+#  env['PYTHON_CCSHARED']   ''
+#  env['PYTHON_LDSHARED']   'g++  -bundle -Wl,-F/Library/Frameworks -framework Python'
+#  env['PYTHON_SO']         '.so'
+
+import SCons
+import os
+import re
+
+none_re = re.compile('None')
+trailing_whitespace_re = re.compile(r'^\s*(.*)\s*$')
+
+def queryPython(python_command, sysconfig_variable):
+  query_command = """ -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('%s')," """
+  line = os.popen(python_command + query_command % sysconfig_variable).readline()
+  line = trailing_whitespace_re.sub(r'\1', line)
+  if not none_re.match(line): return line
+  else: return None
+
+def checkPython(python_command):
+  check_command = """ -c "print 'hello'," """
+  print "python_command + check_command", python_command + check_command
+  the_file = os.popen(python_command + check_command)
+  the_file.read()
+  return the_file.close()
+
+def find(env):
+  if env['PYTHON'] is None:
+    env.Append(
+      PYTHON_TOOL_ERR = """
+PythonTool error:
+  PYTHON has been set to None
+  since no Python executable
+  $$pythonCommand == '%s'
+  was found.
+""" % env.subst('$pythonCommand')
+    )
+    
+  pycmd = env.subst('$PYTHON')
+  if checkPython(pycmd) is not None:
+    env.Append(
+      PYTHON_TOOL_ERR = """
+PythonTool error:
+  Python command doesn't seem to work. Is command-line option
+  "pythonCommand" set correctly?
+""" % pycmd
+    )
+
+def generate(env):
+  """
+  Adds construction variables for Python to an Environment.
+  """
+  env.SetDefault(
+    PYTHON = env.Detect(env.subst('$pythonCommand')),
+    PYTHON_TOOL_ERR = '',
+  )
+  pycmd = env.subst('$PYTHON')
+
+  # Ask Python about its preferred build tools.
+  #
+  # Preferred C compiler.
+  python_cc =         queryPython(pycmd, 'CC')
+  # Preferred C++ compiler.
+  python_cxx =        queryPython(pycmd, 'CXX')
+  # Preferred complier flags.
+  python_basecflags = queryPython(pycmd, 'BASECFLAGS')
+  # Additional compiler flags to use when optimizing.
+  python_opt =        queryPython(pycmd, 'OPT')
+  # Path to Python header files.
+  python_includepy =  queryPython(pycmd, 'INCLUDEPY')
+  # Command to compile shared object used to build python module.
+  python_ccshared =   queryPython(pycmd, 'CCSHARED')
+  # Command used to link python module.
+  python_ldshared =   queryPython(pycmd, 'LDSHARED')
+  #   Fixup -- typical link command is for C, not C++.
+  python_ldshared = re.sub(python_cc, python_cxx, python_ldshared)
+  # FIXME: osx-specific fixup -- @kgn
+  python_framework =   queryPython(pycmd, 'PYTHONFRAMEWORK')
+  python_framework_prefix =   queryPython(pycmd, 'PYTHONFRAMEWORKPREFIX')
+  python_framework_dir =   queryPython(pycmd, 'PYTHONFRAMEWORKDIR')
+  python_ldshared += ' -F%s -framework %s' % (python_framework_prefix, python_framework)
+  # Suffix for python modules.
+  python_so =         queryPython(pycmd, 'SO')
+  env.SetDefault(
+    PYTHON_CC =         SCons.Util.CLVar(python_cc),
+    PYTHON_CXX =        SCons.Util.CLVar(python_cxx),
+    PYTHON_BASECFLAGS = SCons.Util.CLVar(python_basecflags),
+    PYTHON_OPT =        SCons.Util.CLVar(python_opt),
+    PYTHON_INCLUDEPY =  SCons.Util.CLVar(python_includepy),
+    PYTHON_CCSHARED =   SCons.Util.CLVar(python_ccshared),
+    PYTHON_LDSHARED =   SCons.Util.CLVar(python_ldshared),
+    PYTHON_SO =         SCons.Util.CLVar(python_so),
+  )
+
+  if env.subst('$runConfTests') in ['yes', '1']:
+    find(env)
+
+def exists(env):
+  return find(env)
+  #return env.Detect(env.subst('$pythonCommand'))

Modified: development/support/utils/AvidaUtils/__init__.py
===================================================================
--- development/support/utils/AvidaUtils/__init__.py	2006-05-27 10:26:27 UTC (rev 716)
+++ development/support/utils/AvidaUtils/__init__.py	2006-05-28 05:46:01 UTC (rev 717)
@@ -13,10 +13,17 @@
 def Configure(args, env):
   env.Replace(AvidaUtils_path = __path__)
 
+  # Load platform-specific configuration and default options.
+  env.Tool('PlatformTool', toolpath = __path__)
+
   # Load custom options file: if user specified the customOptions
   # option, figure out what custom options file they want to use,
   # otherwise use the default one.
   #
+  # This step uses platform-specific defaults defined in the
+  # 'PlatformTool', so must run after the 'PlatformTool' has been
+  # loaded.
+  #
   env.Replace(default_custom_options_filename = 'my_avida_build_options.py')
   custom_options = args.get('customOptions', env.subst('$default_custom_options_filename'))
   if custom_options not in ['None', 'none']:
@@ -24,17 +31,25 @@
 
   # Load command-line arguments into Options parser.
   opts = SCons.Options.Options([custom_options], args)
-  
-  # Load platform-specific configuration and default options.
-  env.Tool('PlatformTool', toolpath = __path__)
 
-  env.Tool('UnitTestTool', toolpath = __path__)
-
   # Parses Avida-specific command-line arguments, loads default values
   # for options not specified at the command line, and creates help text
   # for available options.
   #
   CmdLineOpts.Update(opts, env)
   SConsOpts.Update(env)
+  
+  # Load various customized build tools.
+  #
+  # Some of these can be tweaked by our custom command-line options, so
+  # must be loaded after command-line arguments are parsed.
+  #
+  env.Tool('GCCXMLTool', toolpath = __path__)
+  env.Tool('PythonTool', toolpath = __path__)
+  env.Tool('BoostPythonTool', toolpath = __path__)
+  env.Tool('PysteTool', toolpath = __path__)
+  env.Tool('UnitTestTool', toolpath = __path__)
+
+  # Provide help text.
   StaticHelp.GenerateStaticHelpText(env)
   env.Help(opts.GenerateHelpText(env))




More information about the Avida-cvs mailing list