def _ask_command(command): if not console_utils.stdin_is_interactive(): return None if platform.system() == 'Windows': other = 'windows' else: other = 'unix' choices = {'b': 'bokeh_app', 'c': other, 'n': 'notebook'} while True: data = console_utils.console_input( "Is `{}` a (B)okeh app, (N)otebook, or (C)ommand line? ".format( command)) data = data.lower().strip() if len(data) == 0 or data[0] not in choices: print("Please enter 'b', 'n', or 'c'.") print( " A Bokeh app is the project-relative path to a Bokeh script or app directory." ) print( " A notebook file is the project-relative path to a .ipynb file." ) print( " A command line is any command you might type at the command prompt." ) continue return choices[data]
def test_console_get_password(monkeypatch, capsys): def mock_isatty_true(): return True # python 2 can throw a "readonly" error if you try to patch sys.stdin.isatty itself monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_isatty_true) _monkeypatch_getpass(monkeypatch, "s3kr3t") password = console_utils.console_input("foo: ", encrypted=True) assert password == 's3kr3t' (out, err) = capsys.readouterr() assert out == '' assert err == 'foo: '
def _interactively_fix_missing_variables(project, result): """Return True if we need to re-prepare.""" if project.problems: return False if not console_utils.stdin_is_interactive(): return False # We don't ask the user to manually enter CONDA_PREFIX # (CondaEnvRequirement) because it's a bizarre/confusing # thing to ask. can_ask_about = [ status for status in result.statuses if (not status and isinstance(status.requirement, EnvVarRequirement) and not isinstance(status.requirement, CondaEnvRequirement)) ] if can_ask_about: print("(Use Ctrl+C to quit.)") start_over = False values = dict() for status in can_ask_about: reply = console_utils.console_input( "Value for " + status.requirement.env_var + ": ", encrypted=status.requirement.encrypted) if reply is None: return False # EOF reply = reply.strip() if reply == '': start_over = True break values[status.requirement.env_var] = reply if len(values) > 0: status = project_ops.set_variables(project, result.env_spec_name, values.items(), result) if status: return True else: console_utils.print_status_errors(status) return False else: return start_over