Skip to content

Commit 1bcf598

Browse files
authored
Merge pull request #439 from python-cmd2/test_bash_complete
Minor formatting changes to argcomplete_bridge.py
2 parents dd299bf + 608e290 commit 1bcf598

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

cmd2/argcomplete_bridge.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ def tokens_for_completion(line, endidx):
106106
class CompletionFinder(argcomplete.CompletionFinder):
107107
"""Hijack the functor from argcomplete to call AutoCompleter"""
108108

109-
def __call__(self, argument_parser, completer=None, always_complete_options=True, exit_method=os._exit, output_stream=None,
110-
exclude=None, validator=None, print_suppressed=False, append_space=None,
109+
def __call__(self, argument_parser, completer=None, always_complete_options=True, exit_method=os._exit,
110+
output_stream=None, exclude=None, validator=None, print_suppressed=False, append_space=None,
111111
default_completer=DEFAULT_COMPLETER):
112112
"""
113113
:param argument_parser: The argument parser to autocomplete on
114114
:type argument_parser: :class:`argparse.ArgumentParser`
115115
:param always_complete_options:
116-
Controls the autocompletion of option strings if an option string opening character (normally ``-``) has not
117-
been entered. If ``True`` (default), both short (``-x``) and long (``--x``) option strings will be
118-
suggested. If ``False``, no option strings will be suggested. If ``long``, long options and short options
119-
with no long variant will be suggested. If ``short``, short options and long options with no short variant
120-
will be suggested.
116+
Controls the autocompletion of option strings if an option string opening character (normally ``-``) has
117+
not been entered. If ``True`` (default), both short (``-x``) and long (``--x``) option strings will be
118+
suggested. If ``False``, no option strings will be suggested. If ``long``, long options and short
119+
options with no long variant will be suggested. If ``short``, short options and long options with no
120+
short variant will be suggested.
121121
:type always_complete_options: boolean or string
122122
:param exit_method:
123123
Method used to stop the program after printing completions. Defaults to :meth:`os._exit`. If you want to
@@ -126,8 +126,8 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
126126
:param exclude: List of strings representing options to be omitted from autocompletion
127127
:type exclude: iterable
128128
:param validator:
129-
Function to filter all completions through before returning (called with two string arguments, completion
130-
and prefix; return value is evaluated as a boolean)
129+
Function to filter all completions through before returning (called with two string arguments,
130+
completion and prefix; return value is evaluated as a boolean)
131131
:type validator: callable
132132
:param print_suppressed:
133133
Whether or not to autocomplete options that have the ``help=argparse.SUPPRESS`` keyword argument set.
@@ -142,18 +142,18 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
142142
143143
Produces tab completions for ``argument_parser``. See module docs for more info.
144144
145-
Argcomplete only executes actions if their class is known not to have side effects. Custom action classes can be
146-
added to argcomplete.safe_actions, if their values are wanted in the ``parsed_args`` completer argument, or
147-
their execution is otherwise desirable.
145+
Argcomplete only executes actions if their class is known not to have side effects. Custom action classes
146+
can be added to argcomplete.safe_actions, if their values are wanted in the ``parsed_args`` completer
147+
argument, or their execution is otherwise desirable.
148148
"""
149149
# Older versions of argcomplete have fewer keyword arguments
150150
if sys.version_info >= (3, 5):
151151
self.__init__(argument_parser, always_complete_options=always_complete_options, exclude=exclude,
152-
validator=validator, print_suppressed=print_suppressed, append_space=append_space,
153-
default_completer=default_completer)
152+
validator=validator, print_suppressed=print_suppressed, append_space=append_space,
153+
default_completer=default_completer)
154154
else:
155155
self.__init__(argument_parser, always_complete_options=always_complete_options, exclude=exclude,
156-
validator=validator, print_suppressed=print_suppressed)
156+
validator=validator, print_suppressed=print_suppressed)
157157

158158
if "_ARGCOMPLETE" not in os.environ:
159159
# not an argument completion invocation
@@ -171,10 +171,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
171171
argcomplete.debug("Unable to open fd 8 for writing, quitting")
172172
exit_method(1)
173173

174-
# print("", stream=debug_stream)
175-
# for v in "COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY _ARGCOMPLETE_COMP_WORDBREAKS COMP_WORDS".split():
176-
# print(v, os.environ[v], stream=debug_stream)
177-
178174
ifs = os.environ.get("_ARGCOMPLETE_IFS", "\013")
179175
if len(ifs) != 1:
180176
argcomplete.debug("Invalid value for IFS, quitting [{v}]".format(v=ifs))
@@ -190,8 +186,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
190186
#
191187
# Replaced with our own tokenizer function
192188
##############################
193-
194-
# cword_prequote, cword_prefix, cword_suffix, comp_words, last_wordbreak_pos = split_line(comp_line, comp_point)
195189
tokens, _, begidx, endidx = tokens_for_completion(comp_line, comp_point)
196190

197191
# _ARGCOMPLETE is set by the shell script to tell us where comp_words
@@ -259,9 +253,13 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
259253
exit_method(0)
260254

261255

262-
def bash_complete(action, show_hint: bool=True):
263-
"""Helper function to configure an argparse action to fall back to bash completion"""
256+
def bash_complete(action, show_hint: bool = True):
257+
"""Helper function to configure an argparse action to fall back to bash completion.
258+
259+
This function tags a parameter for bash completion, bypassing the autocompleter (for file input).
260+
"""
264261
def complete_none(*args, **kwargs):
265262
return None
263+
266264
setattr(action, ACTION_SUPPRESS_HINT, not show_hint)
267265
setattr(action, ACTION_ARG_CHOICES, (complete_none,))

tasks.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,25 @@ def pytest(context):
4949
def pytest_clean(context):
5050
"Remove pytest cache and code coverage files and directories"
5151
#pylint: disable=unused-argument
52-
dirs = ['.pytest-cache', '.cache', 'htmlcov', '.coverage']
52+
dirs = ['.pytest_cache', '.cache', 'htmlcov', '.coverage']
5353
rmrf(dirs)
5454
namespace_clean.add_task(pytest_clean, 'pytest')
5555

56+
@invoke.task
57+
def mypy(context):
58+
"Run mypy optional static type checker"
59+
context.run("mypy main.py")
60+
namespace.add_task(mypy)
61+
namespace.add_task(mypy)
62+
63+
@invoke.task
64+
def mypy_clean(context):
65+
"Remove mypy cache directory"
66+
#pylint: disable=unused-argument
67+
dirs = ['.mypy_cache']
68+
rmrf(dirs)
69+
namespace_clean.add_task(mypy_clean, 'mypy')
70+
5671
@invoke.task
5772
def tox(context):
5873
"Run unit and integration tests on multiple python versions using tox"

0 commit comments

Comments
 (0)