Skip to content

Commit 19942e5

Browse files
authored
Merge 9aba4e7 into ba74374
2 parents ba74374 + 9aba4e7 commit 19942e5

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

venvUtils/ensureVenv.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919
requirements_path: str = os.path.join(top_dir, "requirements.txt")
2020
venv_orig_requirements_path: str = os.path.join(venv_path, "_requirements.txt")
2121
venv_python_version_path: str = os.path.join(venv_path, "python_version")
22+
#: Whether this script is run interactively,
23+
#: i.e. whether user input is possible to answer questions.
24+
#: Value is True if interactive (i.e. stdout is attached to a terminal), False otherwise.
25+
isInteractive = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
2226

2327

24-
def askYesNoQuestion(message: str) -> bool:
28+
def askYesNoQuestion(message: str, default: bool = True) -> bool:
2529
"""
2630
Displays the given message to the user and accepts y or n as input.
2731
Any other input causes the question to be asked again.
28-
@returns: True for y and n for False.
32+
If isInteractive is False, the default is always returned.
33+
@returns: True for y and False for n.
2934
"""
30-
while True:
35+
while isInteractive:
3136
answer = input(
3237
message + " [y/n]: "
3338
)
@@ -37,6 +42,7 @@ def askYesNoQuestion(message: str) -> bool:
3742
return True
3843
else:
3944
continue # ask again
45+
return default
4046

4147

4248
def fetchRequirementsSet(path: str) -> Set[str]:

0 commit comments

Comments
 (0)