mailr8706 - in /branches/relax_disp: dep_check.py sconstruct


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by sebastien . morin . 1 on February 01, 2009 - 20:59:
Author: semor
Date: Sun Feb  1 20:59:09 2009
New Revision: 8706

URL: http://svn.gna.org/viewcvs/relax?rev=8706&view=rev
Log:
Added compiling of the relaxation dispersion C code as scons default and 
added dependency checks.

More work is needed, sucha as, obviously, the modification of the c code 
itself to suit relaxation
dispersion needs.


Modified:
    branches/relax_disp/dep_check.py
    branches/relax_disp/sconstruct

Modified: branches/relax_disp/dep_check.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/dep_check.py?rev=8706&r1=8705&r2=8706&view=diff
==============================================================================
--- branches/relax_disp/dep_check.py (original)
+++ branches/relax_disp/dep_check.py Sun Feb  1 20:59:09 2009
@@ -118,6 +118,29 @@
 # Compiled C modules.
 #####################
 
+# Relaxation dispersion curve fitting.
+try:    
+    from maths_fns.relax_disp import setup
+    del setup
+    C_module_exp_fn = True
+except ImportError, message:
+    # The OS.
+    system = platform.system()
+                
+    # Does the compiled file exist.
+    file = 'relax_disp.so'
+    if system == 'Windows' or system == 'Microsoft':
+        file = 'relax_disp.pyd'
+    if not access('maths_fns' + sep + file, F_OK):
+        C_module_exp_fn_mesg = "ImportError: relaxation dispersion curve 
fitting is unavailable, the corresponding C modules have not been compiled."
+
+    # Show the full error.
+    else:
+        C_module_exp_fn_mesg = "ImportError: " + message[0] + "\nRelaxation 
dispersion curve fitting is unavailable, try compiling the C modules."
+
+    # Set the flag.
+    C_module_exp_fn = False
+
 # Relaxation curve fitting.
 try:
     from maths_fns.relax_fit import setup

Modified: branches/relax_disp/sconstruct
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/sconstruct?rev=8706&r1=8705&r2=8706&view=diff
==============================================================================
--- branches/relax_disp/sconstruct (original)
+++ branches/relax_disp/sconstruct Sun Feb  1 20:59:09 2009
@@ -176,7 +176,8 @@
 
         # Setup the rules for building the relaxation curve fitting C 
modules (and set it as the default).
         self.relax_fit()
-        Default(self.relax_fit_object)
+        self.relax_disp()
+        Default(self.relax_fit_object, self.relax_disp_object)
 
 
 
@@ -210,7 +211,8 @@
         binary_dist_env = Environment(BUILDERS={'dummy' : 
Builder(action=self.dummy)})
         binary_dist_env.dummy(target='binary_dist', source=None)
         binary_dist_env.Depends('binary_dist', 'version_check')           # 
First check the program version number.
-        binary_dist_env.Depends('binary_dist', self.relax_fit_object)     # 
Compile the C code.
+        binary_dist_env.Depends('binary_dist', self.relax_disp_object)     # 
Compile the C code for relaxation dispersion curve fitting.
+        binary_dist_env.Depends('binary_dist', self.relax_fit_object)     # 
Compile the C code for relaxation curve fitting.
         binary_dist_env.Depends('binary_dist', 'manual_clean_nodeps')     # 
Clean up the temporary manual files.
         binary_dist_env.Depends('binary_dist', 'clean')                   # 
Then clean up all other temporary files.
         binary_dist_env.Depends('binary_dist', 'package_bin')             # 
Package the binary distribution.
@@ -463,6 +465,72 @@
         Help(string)
 
 
+    def relax_disp(self):
+        """Function for setting up scons for building the relaxation 
dispersion curve fitting C modules."""
+
+        # The directory.
+        dir = 'maths_fns'
+
+        # File names.
+        files = ['dispersion.c',
+                 'relax_disp.c']
+
+        # Construct the python include path (for Python.h).
+        py_include_minpath = sys.prefix + path.sep + 'include'
+        py_include_fullpath = py_include_minpath + path.sep + 'python' + 
`sys.version_info[0]` + '.' + `sys.version_info[1]`
+
+        # Get the numpy include path (for numpy/arrayobject.h).
+        numpy_path = get_include()
+
+        # C flags.
+        if SYSTEM == 'Windows':
+            cflags = '/nologo /I\"' + py_include_minpath + '\" /I\"' + 
numpy_path + '\"'
+        else:
+            cflags = '-I' + py_include_fullpath + ' -I' + numpy_path
+
+        # Relaxation dispersion curve fitting build environment.
+        env = Environment()
+
+        # Python library path.
+        libpath = ''
+        if SYSTEM == 'Windows':
+            libpath = sys.prefix + path.sep + 'libs'
+
+        # Add the python library path to the environment.
+        env.Append(LIBPATH = libpath)
+
+        # Catch Mac OS X and send the correct command line options to the 
linker (these may become redundant as SCons improves).
+        if env['PLATFORM'] == 'darwin':
+            env.Append(LINKFLAGS = ['-bundle', '-bundle_loader', sys.prefix 
+ path.sep + 'bin' + path.sep + 'python', '-dynamic'])
+            env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS')
+
+        # Shared library prefix and suffix.
+        prefix = ''
+        suffix = '.so'
+        if SYSTEM == 'Windows':
+            suffix = '.pyd'
+
+        # Loop over the relaxation dispersion curve fitting files.
+        nodes = []
+        for file in files:
+            nodes.append(env.SharedObject(dir + path.sep + file, 
CCFLAGS=cflags))
+
+        # Build the relaxation dispersion curve fitting module.
+        self.relax_disp_object = env.SharedLibrary(target=dir + path.sep + 
'relax_disp', source=nodes, SHLIBPREFIX=prefix, SHLIBSUFFIX=suffix)
+
+        # Print out string returning function.
+        def print_string(target, source, env):
+            string = "\n\n\n\n"
+            string = string + "###########################\n"
+            string = string + "# Compiling the C modules #\n"
+            string = string + "###########################\n\n\n"
+            string = string + "Building the relaxation dispersion curve 
fitting module " + `str(self.relax_disp_object[0])` + "\n"
+            return string
+
+        # Add the print out as an action to take before constructing the 
first object.
+        env.AddPreAction(nodes[0], Action(self.dummy, print_string))
+
+
     def relax_fit(self):
         """Function for setting up scons for building the relaxation curve 
fitting C modules."""
 




Related Messages


Powered by MHonArc, Updated Mon Feb 02 05:40:03 2009