diff options
author | Philip Yang <darthsuogles@gmail.com> | 2018-01-02 17:13:01 -0800 |
---|---|---|
committer | Shanqing Cai <cais@google.com> | 2018-01-02 20:13:01 -0500 |
commit | 136697ecdc64b5171522fb7f89cfe51a02f0f1c1 (patch) | |
tree | 70ceabf17fed5907c5d9a57425a31ce6af9f516b /configure.py | |
parent | d87a9fbbc5f49ec5ae8eb52c62628f0b1a0bf67f (diff) |
[configure] eagerly determine the truthfulness of environment variables (#15780)
* determine environment variable truthfulness
Signed-off-by: Philip Yang <darthsuogles@gmail.com>
Diffstat (limited to 'configure.py')
-rw-r--r-- | configure.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/configure.py b/configure.py index e4218b5651..11256d47d8 100644 --- a/configure.py +++ b/configure.py @@ -302,6 +302,12 @@ def get_var(environ_cp, Returns: boolean value of the variable. + + Raises: + UserInputError: if an environment variable is set, but it cannot be + interpreted as a boolean indicator, assume that the user has made a + scripting error, and will continue to provide invalid input. + Raise the error to avoid infinitely looping. """ if not question: question = 'Do you wish to build TensorFlow with %s support?' % query_item @@ -319,6 +325,22 @@ def get_var(environ_cp, question += ' [y/N]: ' var = environ_cp.get(var_name) + if var is not None: + var_content = var.strip().lower() + if var_content in ('1', 't', 'true', 'y', 'yes'): + var = True + elif var_content in ('0', 'f', 'false', 'n', 'no'): + var = False + else: + raise UserInputError('Environment variable %s must be set as a boolean indicator.\n' + 'The followings are accepted as TRUE : %s.\n' + 'The followings are accepted as FALSE: %s.\n' + 'Current value is %s' % + (var_name, + ','.join(true_contents), + ','.join(false_contents), + var)) + while var is None: user_input_origin = get_input(question) user_input = user_input_origin.strip().lower() @@ -605,8 +627,8 @@ def prompt_loop_or_load_from_env( Raises: UserInputError: if a query has been attempted n_ask_attempts times without - success, assume that the user has made a scripting error, and will continue - to provide invalid input. Raise the error to avoid infinitely looping. + success, assume that the user has made a scripting error, and will continue + to provide invalid input. Raise the error to avoid infinitely looping. """ default = environ_cp.get(var_name) or var_default full_query = '%s [Default is %s]: ' % ( |