Skip to content

Commit 56b6b54

Browse files
committed
Add more rigorous test for environment Booleans
The previous method treated any non-empty value as truth-y. This adds '0' and some Python-like values ('false', 'none') to the false-y values to allow scripts to be more explicit.
1 parent 6b16f73 commit 56b6b54

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

setup.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,27 @@ def process_options():
4848
return options
4949

5050

51+
def _get_environment_bool(var, default=False):
52+
"""
53+
Get a boolean value from the environment variable `var`. This evalutes to
54+
`default` if the environment variable is not present. The false-y values
55+
are '0', 'false', 'none' and empty string, insensitive to case. All other
56+
values are truth-y.
57+
"""
58+
from_env = os.environ.get(var)
59+
if from_env is None:
60+
return default
61+
return from_env.lower() not in {'0', 'false', 'none', ''}
62+
63+
5164
def _determine_user_arguments(options):
5265
"""
5366
Add the 'openmp' option to the collection, based on the passed command-line
5467
arguments or environment variables.
5568
"""
5669
options['openmp'] = (
5770
'--with-openmp' in sys.argv
58-
or bool(os.environ.get('CI_QUTIP_WITH_OPENMP'))
71+
or _get_environment_bool('CI_QUTIP_WITH_OPENMP')
5972
)
6073
if "--with-openmp" in sys.argv:
6174
sys.argv.remove("--with-openmp")

0 commit comments

Comments
 (0)