Skip to content

Commit

Permalink
[Scons] Avoid some potential KeyErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwweber committed Jul 30, 2024
1 parent 46d59c3 commit 6a9a7bb
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions site_scons/buildutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ def check_module(name):
f"Could not execute the Python interpreter {env['python_cmd']!r}")
sys.exit(1)

versions = {}
for line in info:
if line.startswith("versions:"):
versions = {
Expand All @@ -1533,27 +1534,29 @@ def check_module(name):
msg.extend(line for line in info if not line.startswith("versions:"))
logger.warning("\n| ".join(msg))

if env["python_package"] == "y":
logger_method = logger.error
exit_on_error = True
else:
logger_method = logger.warning
exit_on_error = False

python_version = versions["python"]
if python_version < env["python_min_version"]:
logger.error(
python_version = versions.get("python")
if not python_version or python_version < env["python_min_version"]:
logger_method(
f"Python version is incompatible. Found {python_version} but "
f"{env['python_min_version']} or newer is required. In order to install "
"Cantera without Python support, specify 'python_package=n'.")
sys.exit(1)
if exit_on_error:
sys.exit(1)
return {"python_package": "n"}
elif python_version >= env["python_max_version"]:
logger.warning(
f"Python {python_version} is not supported for Cantera "
f"{env['cantera_version']}. Python versions {env['python_max_version']} and "
"newer are untested and may result in unexpected behavior. Proceed "
"with caution.")

if env["python_package"] == "y":
logger_method = logger.error
exit_on_error = True
else:
logger_method = logger.warning
exit_on_error = False
numpy_version = versions.get("numpy")
if not numpy_version:
logger_method("NumPy not found. Not building the Python package.")
Expand All @@ -1563,7 +1566,7 @@ def check_module(name):
elif numpy_version not in env["numpy_version_spec"]:
logger_method(
f"NumPy is an incompatible version: Found {numpy_version} but "
f"{env['numpy_min_version']} or newer is required.")
f"{env['numpy_version_spec']} is required.")
if exit_on_error:
sys.exit(1)
return {"python_package": "n"}
Expand All @@ -1579,7 +1582,7 @@ def check_module(name):
elif cython_version not in env["cython_version_spec"]:
logger_method(
f"Cython is an incompatible version: Found {cython_version} but "
f"{env['cython_min_version']} or newer is required.")
f"{env['cython_version_spec']} is required.")
if exit_on_error:
sys.exit(1)
return {"python_package": "n"}
Expand Down

0 comments on commit 6a9a7bb

Please sign in to comment.