Skip to content

Commit 78a2603

Browse files
authored
Merge pull request #1081 from sphinx-contrib/handle-stty-failures-under-mingw
util: handle stty failures under mingw for getpass workaround
2 parents 80ae2ee + 1df6593 commit 78a2603

File tree

1 file changed

+18
-7
lines changed
  • sphinxcontrib/confluencebuilder

1 file changed

+18
-7
lines changed

sphinxcontrib/confluencebuilder/util.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33

44
from __future__ import annotations
55
from contextlib import contextmanager
6+
from contextlib import suppress
67
from pathlib import Path
78
from sphinxcontrib.confluencebuilder.std.confluence import API_REST_V1
89
from sphinxcontrib.confluencebuilder.std.confluence import API_REST_V2
910
from sphinxcontrib.confluencebuilder.std.confluence import FONT_SIZE
1011
from sphinxcontrib.confluencebuilder.std.confluence import FONT_X_HEIGHT
12+
from subprocess import check_call
1113
from hashlib import sha256
1214
from urllib.parse import urlparse
1315
import getpass
1416
import os
1517
import re
1618
import shutil
17-
import subprocess
1819
import tempfile
1920
import unicodedata
2021

@@ -334,13 +335,23 @@ def getpass2(prompt='Password: '):
334335
# disable this feature.
335336
if (os.name == 'nt' and 'MSYSTEM' in os.environ and 'TERM' in os.environ and
336337
'CONFLUENCEBUILDER_NO_GETPASS_HOOK' not in os.environ):
337-
subprocess.check_call(['/usr/bin/stty', '-echo']) # noqa: S603
338338
try:
339-
value = input(prompt)
340-
finally:
341-
subprocess.check_call(['/usr/bin/stty', 'echo']) # noqa: S603
342-
print()
343-
return value
339+
check_call(['/usr/bin/stty', '-echo']) # noqa: S603
340+
except: # noqa: E722
341+
print()
342+
print()
343+
print('(error) pass input not available; please run with winpty')
344+
print()
345+
return None
346+
else:
347+
try:
348+
value = input(prompt)
349+
finally:
350+
with suppress(Exception):
351+
check_call(['/usr/bin/stty', 'echo']) # noqa: S603
352+
353+
print()
354+
return value
344355

345356
return getpass.getpass(prompt=prompt)
346357

0 commit comments

Comments
 (0)