From 63b7d27de64a8a30465d6ad6da381eb44734afe5 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Tue, 8 Feb 2022 14:13:45 -0600 Subject: [PATCH] [SCons] Change prefix default if conda is detected --- SConstruct | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/SConstruct b/SConstruct index d33f56eb28c..f42e84ce5bb 100644 --- a/SConstruct +++ b/SConstruct @@ -819,6 +819,9 @@ config["python_cmd"].default = sys.executable opts.AddVariables(*config.to_scons()) opts.Update(env) opts.Save('cantera.conf', env) +cantera_conf = [] +for line in open('cantera.conf'): + cantera_conf.append(line.strip()) # Expand ~/ and environment variables used in cantera.conf (variables used on # the command line will be expanded by the shell) @@ -866,10 +869,11 @@ except subprocess.CalledProcessError: env["git_commit"] = "unknown" # Print values of all build options: -print("Configuration variables read from 'cantera.conf' and command line:") -for line in open('cantera.conf'): - print(' ', line.strip()) -print() +msg = ["Configuration variables read from 'cantera.conf' and command line:"] +for line in cantera_conf: + msg.append(f" {line}") +msg.append("") +logger.info("\n".join(msg), print_level=False) # ******************************************** # *** Configure system-specific properties *** @@ -1626,6 +1630,17 @@ if env['matlab_toolbox'] == 'y': # /usr/local because of dist-packages vs site-packages env['debian'] = any(name.endswith('dist-packages') for name in sys.path) +# Check whether cantera should be installed into a conda environment +conda_prefix = os.environ.get("CONDA_PREFIX") +use_conda = False +if conda_prefix is not None: + arg_list = set(line.split("=")[0].strip() for line in cantera_conf) + use_conda = not arg_list & {"prefix", "python_prefix", "python_cmd"} + use_conda &= sys.executable.startswith(conda_prefix) + if use_conda: + env["prefix"] = pjoin(conda_prefix, "Library") + logger.info(f"Using conda environment as default 'prefix': {env['prefix']}") + # Directories where things will be after actually being installed. These # variables are the ones that are used to populate header files, scripts, etc. env['prefix'] = os.path.normpath(env['prefix'])