Prints fixing in setup.py

This commit is contained in:
Samer Afach 2017-01-12 20:49:24 +01:00
parent dc18dadb4c
commit 406913ce24

View File

@ -24,7 +24,8 @@ temp_dir = tempfile.gettempdir()
def _print_error(msg): def _print_error(msg):
sys.stderr.write("\n\nERROR: " + msg + "\n\n\n") sys.stderr.write("\n\n" + error_color_start + "ERROR: " + msg + color_end + " \n\n\n ")
sys.stderr.flush()
def which(program): def which(program):
@ -73,7 +74,7 @@ def deal_with_error_code(err_code, operation_name):
if err_code != 0: if err_code != 0:
_print_error("A non-zero error code was returned at operation: " + _print_error("A non-zero error code was returned at operation: " +
str(operation_name) + ". Code returned is: " + str(operation_name) + ". Code returned is: " +
str(err_code) + ". Exiting!\n") str(err_code) + ". Exiting!")
sys.exit(1) sys.exit(1)
@ -104,6 +105,7 @@ def clone_git_repository(dir, repos_link):
print("Done cloning repository: " + repos_link) print("Done cloning repository: " + repos_link)
question_color_start = "\x1b[0;37;44m" question_color_start = "\x1b[0;37;44m"
error_color_start = "\x1b[0;37;41m"
color_end = "\x1b[0m" color_end = "\x1b[0m"
def ask_openblas_optimization_level(): def ask_openblas_optimization_level():
@ -118,7 +120,8 @@ def ask_openblas_optimization_level():
print("3) -Ofast") print("3) -Ofast")
print("4) Keep the default") print("4) Keep the default")
print("5) Skip compiling OpenBLAS and assume it exists in the system") print("5) Skip compiling OpenBLAS and assume it exists in the system")
sys.stdout.write("Please enter the option number: ") print(question_color_start + "Please enter the option number: " + color_end)
sys.stdout.flush()
option_chosen = input() option_chosen = input()
if option_chosen.replace(" ", "") == '1': if option_chosen.replace(" ", "") == '1':
return "-O2" return "-O2"
@ -131,7 +134,7 @@ def ask_openblas_optimization_level():
elif option_chosen.replace(" ", "") == '5': elif option_chosen.replace(" ", "") == '5':
return "SKIPOPENBLAS" return "SKIPOPENBLAS"
else: else:
raise IndexError("Error: An unknown option was entered") raise IndexError(error_color_start + "Error: An unknown option was entered" + color_end)
def ask_spintrum_optimization_level(): def ask_spintrum_optimization_level():
@ -146,7 +149,8 @@ def ask_spintrum_optimization_level():
print("3) -O2") print("3) -O2")
print("4) -O3") print("4) -O3")
print("5) -Ofast") print("5) -Ofast")
sys.stdout.write("Please enter the option number: ") print(question_color_start + "Please enter the option number: " + color_end)
sys.stdout.flush()
option_chosen = input("") option_chosen = input("")
if option_chosen.replace(" ", "") == '1': if option_chosen.replace(" ", "") == '1':
return "-g" return "-g"
@ -159,7 +163,7 @@ def ask_spintrum_optimization_level():
elif option_chosen.replace(" ", "") == '5': elif option_chosen.replace(" ", "") == '5':
return "-Ofast" return "-Ofast"
else: else:
raise IndexError("Error: An unknown option was entered") raise IndexError(error_color_start + "Error: An unknown option was entered" + color_end)
def recursive_glob(rootdir, pattern='*'): def recursive_glob(rootdir, pattern='*'):
@ -169,12 +173,52 @@ def recursive_glob(rootdir, pattern='*'):
if fnmatch.fnmatch(filename, pattern)] if fnmatch.fnmatch(filename, pattern)]
return lst return lst
def get_openblas():
openblas_dir = "3rdparty/OpenBLAS"
openblas_dir_install = "spintrum/OpenBLAS_install"
openblas_full_path = os.path.join(start_working_dir, openblas_dir)
openblas_full_path_install = os.path.join(start_working_dir, openblas_dir_install)
openblas_git = "https://github.com/xianyi/OpenBLAS.git"
openblas_target_optimization = ask_openblas_optimization_level()
if openblas_target_optimization != "SKIPOPENBLAS":
clone_git_repository(openblas_full_path, openblas_git)
if openblas_target_optimization != "":
if not os.path.isdir(openblas_dir):
_print_error("Cannot open expected OpenBLAS directory " + openblas_dir)
sys.exit(1)
makefiles_to_glob = os.path.join(openblas_dir, "Makefile*")
makefiles = glob.glob(makefiles_to_glob)
print("Number of files found: " + str(len(makefiles)))
for f in makefiles:
print(f)
inplace_change(f, "-O2", openblas_target_optimization)
# make openblas
os.chdir(openblas_dir)
make_openblas_err_code = subprocess.call(["make"], shell=True)
deal_with_error_code(make_openblas_err_code, "Making OpenBLAS")
# install openblas
install_openblas_err_code = subprocess.call(
["make PREFIX=" + openblas_full_path_install +
" install"], shell=True)
deal_with_error_code(install_openblas_err_code, "Installing OpenBLAS")
os.chdir(start_working_dir) # restore working dir
dir_name = "spintrum" dir_name = "spintrum"
lib_file = "lib/libspintrum.so" lib_file = "lib/libspintrum.so"
class DependenciesBuilder(_build): class DependenciesBuilder(_build):
def run(self): def run(self):
sys.stdout.flush()
sys.stderr.flush()
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
_print_error("You cannot build Spintrum on Windows. It is not supported.") _print_error("You cannot build Spintrum on Windows. It is not supported.")
@ -186,41 +230,7 @@ class DependenciesBuilder(_build):
print("Building Spintrum C/C++ extension prerequisites") print("Building Spintrum C/C++ extension prerequisites")
########## get OpenBLAS get_openblas()
openblas_dir = "3rdparty/OpenBLAS"
openblas_dir_install = "spintrum/OpenBLAS_install"
openblas_full_path = os.path.join(start_working_dir, openblas_dir)
openblas_full_path_install = os.path.join(start_working_dir, openblas_dir_install)
openblas_git = "https://github.com/xianyi/OpenBLAS.git"
openblas_target_optimization = ask_openblas_optimization_level()
if openblas_target_optimization != "SKIPOPENBLAS":
clone_git_repository(openblas_full_path, openblas_git)
if openblas_target_optimization != "":
if not os.path.isdir(openblas_dir):
_print_error("Cannot open expected OpenBLAS directory " + openblas_dir + "\n")
sys.exit(1)
makefiles_to_glob = os.path.join(openblas_dir, "Makefile*")
makefiles = glob.glob(makefiles_to_glob)
print("Number of files found: " + str(len(makefiles)))
for f in makefiles:
print(f)
inplace_change(f, "-O2", openblas_target_optimization)
# make openblas
os.chdir(openblas_dir)
make_openblas_err_code = subprocess.call(["make"], shell=True)
deal_with_error_code(make_openblas_err_code, "Making OpenBLAS")
# install openblas
install_openblas_err_code = subprocess.call(
["make PREFIX=" + openblas_full_path_install +
" install"], shell=True)
deal_with_error_code(install_openblas_err_code, "Installing OpenBLAS")
os.chdir(start_working_dir) #restore working dir
############## get Polymath ############## get Polymath
polymath_git = "https://git.afach.de/samerafach/Polymath" polymath_git = "https://git.afach.de/samerafach/Polymath"
@ -230,12 +240,12 @@ class DependenciesBuilder(_build):
############## build spintrum ############## build spintrum
spintrum_optimization_target = ask_spintrum_optimization_level() spintrum_optimization_target = ask_spintrum_optimization_level()
print("Building Spintrum") print("Building Spintrum extension...")
err_code = subprocess.call(["cmake . -DPythonInstallation=1 -DOptimizationLevel=" + spintrum_optimization_target], shell=True) err_code = subprocess.call(["cmake . -DPythonInstallation=1 -DOptimizationLevel=" + spintrum_optimization_target], shell=True)
deal_with_error_code(err_code, "CMaking spintrum") deal_with_error_code(err_code, "CMaking spintrum")
err_code = subprocess.call(["make"], shell=True) err_code = subprocess.call(["make"], shell=True)
deal_with_error_code(err_code, "Making spintrum") deal_with_error_code(err_code, "Making spintrum")
print("Done building spintrum.") print("Done building spintrum extension.")
setup(name='spintrum', setup(name='spintrum',