Skip to content

Commit 1df6593

Browse files
committed
util: handle stty failures under mingw for getpass workaround
When operating in a MinGW terminal without invoking `winpty`, getpass does not function as expected. This extension included a workaround by using `stty`; however, it has been observed in recent environments that stty may fail to run. This would result in an exception and break a user's attempt to perform a publish request. First, this commit improves the handling when stty fails to invoke as expected (instead of throwing exceptions a user may not understand). Second, if stty, instead of falling back to trying `getpass` (which seems to always never work in this environment), just stop and report the issue. Users can should always be able to run with `winpty` to prevent issues when using the ask-password capability. Signed-off-by: James Knight <git@jdknight.me>
1 parent 80ae2ee commit 1df6593

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)