Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move debug_stream initialization to helper method #471

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions argcomplete/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ def __call__(
# not an argument completion invocation
return

try:
_io.debug_stream = os.fdopen(9, "w")
except Exception:
_io.debug_stream = sys.stderr
debug()
self._init_debug_stream()

if output_stream is None:
filename = os.environ.get("_ARGCOMPLETE_STDOUT_FILENAME")
Expand Down Expand Up @@ -190,6 +186,19 @@ def __call__(
_io.debug_stream.flush()
exit_method(0)

def _init_debug_stream(self):
"""Initialize debug output stream

By default, writes to file descriptor 9, or stderr if that fails.
This can be overridden by derived classes, for example to avoid
clashes with file descriptors being used elsewhere (such as in pytest).
"""
try:
_io.debug_stream = os.fdopen(9, "w")
except Exception:
_io.debug_stream = sys.stderr
debug()

def _get_completions(self, comp_words, cword_prefix, cword_prequote, last_wordbreak_pos):
active_parsers = self._patch_argument_parser()

Expand Down
Loading