/[escript]/branches/prepy3/SConstruct
ViewVC logotype

Diff of /branches/prepy3/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3664 by jfenwick, Fri Nov 11 04:27:58 2011 UTC revision 3665 by jfenwick, Tue Nov 15 07:12:49 2011 UTC
# Line 16  EnsurePythonVersion(2,5) Line 16  EnsurePythonVersion(2,5)
16  import sys, os, platform, re  import sys, os, platform, re
17  from distutils import sysconfig  from distutils import sysconfig
18  from site_init import *  from site_init import *
19    import subprocess
20    from subprocess import PIPE, Popen
21    
22  # Version number to check for in options file. Increment when new features are  # Version number to check for in options file. Increment when new features are
23  # added or existing options changed.  # added or existing options changed.
# Line 126  vars.AddVariables( Line 128  vars.AddVariables(
128    ('sys_libs', 'Extra libraries to link with', []),    ('sys_libs', 'Extra libraries to link with', []),
129    ('escript_opts_version', 'Version of options file (do not specify on command line)'),    ('escript_opts_version', 'Version of options file (do not specify on command line)'),
130    ('SVN_VERSION', 'Do not use from options file', -2),    ('SVN_VERSION', 'Do not use from options file', -2),
131      ('pythoncmd', 'which python to compile with','python'),
132  )  )
133    
134  ##################### Create environment and help text #######################  ##################### Create environment and help text #######################
# Line 405  if IS_WINDOWS: Line 408  if IS_WINDOWS:
408  else:  else:
409      python_libs=['python'+sysconfig.get_python_version()]      python_libs=['python'+sysconfig.get_python_version()]
410    
411    #if we want to use a python other than the one scons is running
412    if env['pythoncmd']!='python':
413       py3scons=False   # Is scons running on python3?
414       initstring='from __future__ import print_function;from distutils import sysconfig;'
415       if IS_WINDOWS:
416          cmd='print("python%s%s"%(sys.version_info[0], sys.version_info[1]))'
417       else:
418          cmd='print("python"+sysconfig.get_python_version())'
419       p=Popen([env['pythoncmd'], '-c', initstring+cmd], stdout=PIPE)
420       python_libs=p.stdout.readline()
421       if type(python_libs)!=str():
422          py3scons=True
423          python_libs=python_libs.encode()
424       p.wait()
425       python_libs=python_libs.strip()
426       # Now we know whether we are using python3 or not
427       p=Popen([env['pythoncmd'], '-c',  initstring+'print(sysconfig.get_python_inc())'], stdout=PIPE)
428       python_inc_path=p.stdout.readline()
429       if py3scons:
430             python_inc_path=python_inc_path.encode()
431       p.wait()  
432       python_inc_path=python_inc_path.strip()
433       if IS_WINDOWS:
434            cmd="os.path.join(sysconfig.get_config_var('prefix'), 'libs')"
435       elif env['PLATFORM']=='darwin':
436            cmd="sysconfig.get_config_var(\"LIBPL\")"
437       else:
438            cmd="sysconfig.get_config_var(\"LIBDIR\")"
439    
440       p=Popen([env['pythoncmd'], '-c', initstring+'print('+cmd+')'], stdout=PIPE)
441       python_lib_path=p.stdout.readline()
442       if py3scons:
443          python_lib_path=python_lib_path.decode()
444       p.wait()
445       python_lib_path=python_lib_path.strip()
446    
 # Joel's nasty hacks to hook to python3 need a script to supply these values  
 python_inc_path='/usr/include/python3.1'  
 python_lib_path='/usr/lib'  
 python_libs='python3.1'  
   
   
 #end this block of nasty hacks  
447    
448    
449    
# Line 455  env.PrependENVPath(LD_LIBRARY_PATH_KEY, Line 486  env.PrependENVPath(LD_LIBRARY_PATH_KEY,
486    
487  ######## numpy (required)  ######## numpy (required)
488    
489  #try:  if env['pythoncmd']=='python':
490  #    from numpy import identity      try:
491  #except ImportError:        from numpy import identity
492  #    print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)      except ImportError:
493  #    Exit(1)        print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)
494          Exit(1)
495    else:
496  # More nasty hacking      p=subprocess.call([env['pythoncmd'],'-c','import numpy'])
497  #The problem here is that importing numpy into the scons instance of python does not      if p!=0:
498  #say much about the ability to import into the real version  of python        print("Cannot import numpy, you need to set your PYTHONPATH and probably %s"%LD_LIBRARY_PATH_KEY)
499  #Perhaps this should be tested in an external script?        Exit(1)
 #In my case numpy was installed for py3 and scons (running in py2) could not understand it  
500    
501  ######## CppUnit (required for tests)  ######## CppUnit (required for tests)
502    
# Line 773  buildvars.write("svn_revision="+str(glob Line 803  buildvars.write("svn_revision="+str(glob
803  buildvars.write("prefix="+prefix+"\n")  buildvars.write("prefix="+prefix+"\n")
804  buildvars.write("cc="+env['CC']+"\n")  buildvars.write("cc="+env['CC']+"\n")
805  buildvars.write("cxx="+env['CXX']+"\n")  buildvars.write("cxx="+env['CXX']+"\n")
806  #buildvars.write("python="+sys.executable+"\n")  buildvars.write("python="+env['pythoncmd']+"\n")
807  #buildvars.write("python_version="+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"\n")  #buildvars.write("python_version="+str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])+"\n")
808    
809    if env['pythoncmd']=='python':
810  #Nasty hack     verstring=str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2])
811    else:
812  #This should run things via the chosen executable     p=Popen([env['pythoncmd'], '-c', 'from __future__ import print_function;import sys;print(str(sys.version_info[0])+"."+str(sys.version_info[1])+"."+str(sys.version_info[2]))'], stdout=PIPE)
813       verstring=p.stdout.readline().strip()
814  buildvars.write("python=python3\n")     p.wait()
 buildvars.write("python_version=3.1\n")  
   
 #nasty hack  
815    
816    
817    buildvars.write("python_version="+verstring+"\n")
818  buildvars.write("boost_inc_path="+boost_inc_path+"\n")  buildvars.write("boost_inc_path="+boost_inc_path+"\n")
819  buildvars.write("boost_lib_path="+boost_lib_path+"\n")  buildvars.write("boost_lib_path="+boost_lib_path+"\n")
820  buildvars.write("boost_version="+boostversion+"\n")  buildvars.write("boost_version="+boostversion+"\n")

Legend:
Removed from v.3664  
changed lines
  Added in v.3665

  ViewVC Help
Powered by ViewVC 1.1.26