diff --git a/datalad/ui/dialog.py b/datalad/ui/dialog.py index f43d6cc2b3..4d217fd454 100644 --- a/datalad/ui/dialog.py +++ b/datalad/ui/dialog.py @@ -31,7 +31,7 @@ from ..utils import auto_repr from ..utils import on_windows from .base import InteractiveUI -from .utils import has_terminal +from .utils import can_prompt from datalad.support.exceptions import CapturedException # Example APIs which might be useful to look for "inspiration" @@ -359,7 +359,7 @@ def get_progressbar(self, *args, **kwargs): *args, **kwargs) def input(self, prompt, hidden=False): - if not has_terminal(): + if not can_prompt(): # we are not interactive raise RuntimeError('Interactive input not available for `ui.input()` in annex remotes') return super(UnderAnnexUI, self).input(prompt, hidden) @@ -371,7 +371,7 @@ def question(self, default=None, hidden=False, repeat=None): - if not has_terminal(): + if not can_prompt(): # we are not interactive raise RuntimeError('Interactive input not available for `ui.question()` in annex remotes') return super(UnderAnnexUI, self).question( diff --git a/datalad/ui/utils.py b/datalad/ui/utils.py index 2576bb2858..e3de1adf31 100644 --- a/datalad/ui/utils.py +++ b/datalad/ui/utils.py @@ -76,13 +76,17 @@ def show_hint(msg): ansi_colors.YELLOW))) -def has_terminal(): - """Return True if the process has a controlling terminal +def can_prompt() -> bool: + """Return True if the process can prompt for credentials - This checks for a controlling terminal on Linux + On Linux this method checks for a controlling terminal. + On Windows it always returns True. """ - try: - open('/dev/tty', 'r').close() + if on_windows: return True - except (IOError, OSError): - return False + else: + try: + open('/dev/tty', 'r').close() + return True + except (IOError, OSError): + return False