Skip to content

Commit

Permalink
[SCons] Change prefix default if conda is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Feb 8, 2022
1 parent 0119484 commit 63b7d27
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ***
Expand Down Expand Up @@ -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'])
Expand Down

0 comments on commit 63b7d27

Please sign in to comment.