|
6 | 6 | import argcomplete |
7 | 7 | except ImportError: # pragma: no cover |
8 | 8 | # not installed, skip the rest of the file |
9 | | - pass |
10 | | - |
| 9 | + DEFAULT_COMPLETER = None |
11 | 10 | else: |
12 | 11 | # argcomplete is installed |
13 | 12 |
|
| 13 | + # Newer versions of argcomplete have FilesCompleter at top level, older versions only have it under completers |
| 14 | + try: |
| 15 | + DEFAULT_COMPLETER = argcomplete.FilesCompleter() |
| 16 | + except AttributeError: |
| 17 | + DEFAULT_COMPLETER = argcomplete.completers.FilesCompleter() |
| 18 | + |
14 | 19 | from contextlib import redirect_stdout |
15 | 20 | import copy |
16 | 21 | from io import StringIO |
@@ -102,7 +107,7 @@ class CompletionFinder(argcomplete.CompletionFinder): |
102 | 107 |
|
103 | 108 | def __call__(self, argument_parser, completer=None, always_complete_options=True, exit_method=os._exit, output_stream=None, |
104 | 109 | exclude=None, validator=None, print_suppressed=False, append_space=None, |
105 | | - default_completer=argcomplete.FilesCompleter()): |
| 110 | + default_completer=DEFAULT_COMPLETER): |
106 | 111 | """ |
107 | 112 | :param argument_parser: The argument parser to autocomplete on |
108 | 113 | :type argument_parser: :class:`argparse.ArgumentParser` |
@@ -140,9 +145,14 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True |
140 | 145 | added to argcomplete.safe_actions, if their values are wanted in the ``parsed_args`` completer argument, or |
141 | 146 | their execution is otherwise desirable. |
142 | 147 | """ |
143 | | - self.__init__(argument_parser, always_complete_options=always_complete_options, exclude=exclude, |
144 | | - validator=validator, print_suppressed=print_suppressed, append_space=append_space, |
145 | | - default_completer=default_completer) |
| 148 | + # Older versions of argcomplete have fewer keyword arguments |
| 149 | + if sys.version_info >= (3, 5): |
| 150 | + self.__init__(argument_parser, always_complete_options=always_complete_options, exclude=exclude, |
| 151 | + validator=validator, print_suppressed=print_suppressed, append_space=append_space, |
| 152 | + default_completer=default_completer) |
| 153 | + else: |
| 154 | + self.__init__(argument_parser, always_complete_options=always_complete_options, exclude=exclude, |
| 155 | + validator=validator, print_suppressed=print_suppressed) |
146 | 156 |
|
147 | 157 | if "_ARGCOMPLETE" not in os.environ: |
148 | 158 | # not an argument completion invocation |
|
0 commit comments