more robust way to determine f2py call in /sources/c_codes/build_all.py, etc scripts

master
david.verelst 14 years ago
parent 2110de71e6
commit 6c046a0fb4

@ -5,23 +5,85 @@ See also http://www.scipy.org/Cookbook/CompilingExtensionsOnWindowsWithMinGW
""" """
import os import os
def compile_all(): def which(program):
"""
Test if program exists
======================
In order to test if a certain executable exists, it will search for the
program name in the environment variables.
If program is a full path to an executable, it will check it exists
# on Linux my linux version it is f2py2.6, don't know how that is on others Copied from:
if os.name == 'posix': http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python/
# this might vary among specific cases: f2py, f2py2.7, f2py3.2, ... It is supposed to mimic the UNIX command "which"
# TODO: more robust approach, find out what f2py is in the users path """
compile_format = 'f2py2.6 %s %s -c'
# Install microsoft visual c++ .NET 2003 and run the following to build the module: def is_exe(fpath):
elif os.name == 'nt': return os.path.exists(fpath) and os.access(fpath, os.X_OK)
# compile_format = 'f2py.py %s %s -c --fcompiler=gnu95 --compiler=mingw32 -lmsvcr71'
compile_format = 'f2py.py %s %s -c'
# give an Error for other OS-es fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else: else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def compile_all():
# regardless of platform, try to figure out which f2py call is in the path
# define possible options
f2py_call_list = ('f2py','f2py2.6','f2py2.7','f2py.py',)
no_f2py = True
for k in f2py_call_list:
# if the call command exists in the path, it will return the path as
# a string, otherwise it will return None
f2py_path = which(k)
if not f2py_path:
# didn't find the current call k, continue looking
pass
else:
# current call k is in the path
f2py_call = k
no_f2py = False
break
# raise exception if f2py is not found
if no_f2py:
raise UserWarning, \ raise UserWarning, \
'Untested platform:', os.name 'Couldn\'t locate f2py. Should be part of NumPy installation.'
else:
print '='*75
print 'compiling c_codes'
print '='*75
print 'found f2py in:', f2py_path
# on Windows: Install microsoft visual c++ .NET 2003 to run the following
# build command
# on posix: install gcc and gfortran
compile_format = f2py_call + ' %s %s -c'
# # on Linux my linux version it is f2py2.6, don't know how that is on others
# if os.name == 'posix':
# # this might vary among specific cases: f2py, f2py2.7, f2py3.2, ...
# # TODO: more robust approach, find out what f2py is in the users path
# compile_format = 'f2py2.6 %s %s -c'
#
# # Install microsoft visual c++ .NET 2003 and run the following to build the module:
# elif os.name == 'nt':
# # compile_format = 'f2py.py %s %s -c --fcompiler=gnu95 --compiler=mingw32 -lmsvcr71'
# compile_format = 'f2py.py %s %s -c'
#
# # give an Error for other OS-es
# else:
# raise UserWarning, \
# 'Untested platform:', os.name
pyfs = ('c_library.pyf',) pyfs = ('c_library.pyf',)
files =('c_functions.c',) files =('c_functions.c',)

@ -3,23 +3,80 @@ builds mvn.pyd
""" """
import os import os
def which(program):
"""
Test if program exists
======================
In order to test if a certain executable exists, it will search for the
program name in the environment variables.
If program is a full path to an executable, it will check it exists
Copied from:
http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python/
It is supposed to mimic the UNIX command "which"
"""
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def compile_all(): def compile_all():
#os.system('f2py.py mvn.pyf mvndst.f -c --fcompiler=gnu95 --compiler=mingw32 -lmsvcr71 ') #os.system('f2py.py mvn.pyf mvndst.f -c --fcompiler=gnu95 --compiler=mingw32 -lmsvcr71 ')
# this might vary among specific cases: f2py, f2py2.7, f2py3.2, ... # regardless of platform, try to figure out which f2py call is in the path
# TODO: more robust approach, find out what f2py is in the users path # define possible options
if os.name == 'posix': f2py_call_list = ('f2py','f2py2.6','f2py2.7','f2py.py',)
f2py_call = 'f2py2.6'
# Install microsoft visual c++ .NET 2003 and run the following to build the module: no_f2py = True
elif os.name == 'nt': for k in f2py_call_list:
f2py_call = 'f2py.py' # if the call command exists in the path, it will return the path as
# a string, otherwise it will return None
f2py_path = which(k)
if not f2py_path:
# didn't find the current call k, continue looking
pass
else:
# current call k is in the path
f2py_call = k
no_f2py = False
break
# give an Error for other OS-es # raise exception if f2py is not found
else: if no_f2py:
raise UserWarning, \ raise UserWarning, \
'Untested platform:', os.name 'Couldn\'t locate f2py. Should be part of NumPy installation.'
else:
print '='*75
print 'compiling mvn'
print '='*75
print 'found f2py in:', f2py_path
# # this might vary among specific cases: f2py, f2py2.7, f2py3.2, ...
# # TODO: more robust approach, find out what f2py is in the users path
# if os.name == 'posix':
# f2py_call = 'f2py2.6'
#
# # Install microsoft visual c++ .NET 2003 and run the following to build the module:
# elif os.name == 'nt':
# f2py_call = 'f2py.py'
#
# # give an Error for other OS-es
# else:
# raise UserWarning, \
# 'Untested platform:', os.name
os.system(f2py_call + ' mvn.pyf mvndst.f -c ') os.system(f2py_call + ' mvn.pyf mvndst.f -c ')

@ -3,6 +3,35 @@ builds mvnprdmod.pyd
""" """
import os import os
def which(program):
"""
Test if program exists
======================
In order to test if a certain executable exists, it will search for the
program name in the environment variables.
If program is a full path to an executable, it will check it exists
Copied from:
http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python/
It is supposed to mimic the UNIX command "which"
"""
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def compile_all(): def compile_all():
files = ['mvnprd', 'mvnprodcorrprb'] files = ['mvnprd', 'mvnprodcorrprb']
compile1_format = 'gfortran -fPIC -c %s.f' compile1_format = 'gfortran -fPIC -c %s.f'
@ -10,19 +39,47 @@ def compile_all():
os.system(compile1_format % file) os.system(compile1_format % file)
file_objects = '%s.o %s.o' % tuple(files) file_objects = '%s.o %s.o' % tuple(files)
# this might vary among specific cases: f2py, f2py2.7, f2py3.2, ... # regardless of platform, try to figure out which f2py call is in the path
# TODO: more robust approach, find out what f2py is in the users path # define possible options
if os.name == 'posix': f2py_call_list = ('f2py','f2py2.6','f2py2.7','f2py.py',)
f2py_call = 'f2py2.6'
# Install microsoft visual c++ .NET 2003 and run the following to build the module: no_f2py = True
elif os.name == 'nt': for k in f2py_call_list:
f2py_call = 'f2py.py' # if the call command exists in the path, it will return the path as
# a string, otherwise it will return None
f2py_path = which(k)
if not f2py_path:
# didn't find the current call k, continue looking
pass
else:
# current call k is in the path
f2py_call = k
no_f2py = False
break
# give an Error for other OS-es # raise exception if f2py is not found
else: if no_f2py:
raise UserWarning, \ raise UserWarning, \
'Untested platform:', os.name 'Couldn\'t locate f2py. Should be part of NumPy installation.'
else:
print '='*75
print 'compiling mvnprd'
print '='*75
print 'found f2py in:', f2py_path
# # this might vary among specific cases: f2py, f2py2.7, f2py3.2, ...
# # TODO: more robust approach, find out what f2py is in the users path
# if os.name == 'posix':
# f2py_call = 'f2py2.6'
#
# # Install microsoft visual c++ .NET 2003 and run the following to build the module:
# elif os.name == 'nt':
# f2py_call = 'f2py.py'
#
# # give an Error for other OS-es
# else:
# raise UserWarning, \
# 'Untested platform:', os.name
#os.system('f2py.py -m mvnprdmod -c %s mvnprd_interface.f --fcompiler=gnu95 --compiler=mingw32 -lmsvcr71' % file_objects) #os.system('f2py.py -m mvnprdmod -c %s mvnprd_interface.f --fcompiler=gnu95 --compiler=mingw32 -lmsvcr71' % file_objects)
os.system(f2py_call + ' -m mvnprdmod -c %s mvnprd_interface.f ' % file_objects) os.system(f2py_call + ' -m mvnprdmod -c %s mvnprd_interface.f ' % file_objects)

@ -3,6 +3,35 @@ Builds rindmod.pyd
""" """
import os import os
def which(program):
"""
Test if program exists
======================
In order to test if a certain executable exists, it will search for the
program name in the environment variables.
If program is a full path to an executable, it will check it exists
Copied from:
http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python/
It is supposed to mimic the UNIX command "which"
"""
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def compile_all(): def compile_all():
files = ['intmodule', 'jacobmod', 'swapmod', 'fimod','rindmod','rind71mod'] files = ['intmodule', 'jacobmod', 'swapmod', 'fimod','rindmod','rind71mod']
compile1_format = 'gfortran -fPIC -c %s.f' compile1_format = 'gfortran -fPIC -c %s.f'
@ -11,19 +40,47 @@ def compile_all():
os.system(compile1_format % file) os.system(compile1_format % file)
file_objects = format1 % tuple(files) file_objects = format1 % tuple(files)
# this might vary among specific cases: f2py, f2py2.7, f2py3.2, ... # regardless of platform, try to figure out which f2py call is in the path
# TODO: more robust approach, find out what f2py is in the users path # define possible options
if os.name == 'posix': f2py_call_list = ('f2py','f2py2.6','f2py2.7','f2py.py',)
f2py_call = 'f2py2.6'
# Install microsoft visual c++ .NET 2003 and run the following to build the module: no_f2py = True
elif os.name == 'nt': for k in f2py_call_list:
f2py_call = 'f2py.py' # if the call command exists in the path, it will return the path as
# a string, otherwise it will return None
f2py_path = which(k)
if not f2py_path:
# didn't find the current call k, continue looking
pass
else:
# current call k is in the path
f2py_call = k
no_f2py = False
break
# give an Error for other OS-es # raise exception if f2py is not found
else: if no_f2py:
raise UserWarning, \ raise UserWarning, \
'Untested platform:', os.name 'Couldn\'t locate f2py. Should be part of NumPy installation.'
else:
print '='*75
print 'compiling rind2007'
print '='*75
print 'found f2py in:', f2py_path
# # this might vary among specific cases: f2py, f2py2.7, f2py3.2, ...
# # TODO: more robust approach, find out what f2py is in the users path
# if os.name == 'posix':
# f2py_call = 'f2py2.6'
#
# # Install microsoft visual c++ .NET 2003 and run the following to build the module:
# elif os.name == 'nt':
# f2py_call = 'f2py.py'
#
# # give an Error for other OS-es
# else:
# raise UserWarning, \
# 'Untested platform:', os.name
os.system(f2py_call + ' -m rindmod -c %s rind_interface.f ' % file_objects) os.system(f2py_call + ' -m rindmod -c %s rind_interface.f ' % file_objects)

Loading…
Cancel
Save