argcomplete 3.7.0__tar.gz → 3.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {argcomplete-3.7.0 → argcomplete-3.7.1}/.github/workflows/ci.yml +1 -1
- {argcomplete-3.7.0 → argcomplete-3.7.1}/Changes.rst +8 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/PKG-INFO +1 -1
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/__init__.py +1 -1
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/bash_completion.d/_python-argcomplete +6 -2
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/completers.py +29 -15
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/finders.py +51 -33
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/io.py +5 -4
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/lexers.py +2 -2
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/scripts/activate_global_python_argcomplete.py +17 -15
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/scripts/register_python_argcomplete.py +2 -2
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/shell_integration.py +8 -1
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/test.py +38 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/.github/FUNDING.yml +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/.github/workflows/release.yml +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/.gitignore +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/Authors.rst +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/LICENSE.rst +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/MANIFEST.in +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/Makefile +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/NOTICE +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/README.rst +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/SECURITY.md +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/_check_console_script.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/_check_module.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/exceptions.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/packages/__init__.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/packages/_argparse.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/packages/_shlex.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/py.typed +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/scripts/__init__.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/common.mk +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/contrib/README.rst +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/docs/changelog.rst +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/docs/conf.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/docs/examples/describe_github_user.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/docs/fish_help_string.png +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/docs/index.rst +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/docs/toc.html +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/pyproject.toml +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/setup.cfg +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/__init__.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/inputrc +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/prog +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/stuck +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/test_contrib_shells.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/test_package/__init__.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/test_package/setup.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/test_package/test_module.py +0 -0
- {argcomplete-3.7.0 → argcomplete-3.7.1}/test/test_package/test_package/__init__.py +0 -0
|
@@ -9,7 +9,7 @@ jobs:
|
|
|
9
9
|
fail-fast: false
|
|
10
10
|
matrix:
|
|
11
11
|
os: [ubuntu-22.04, ubuntu-latest, macos-14, macos-latest]
|
|
12
|
-
python-version: ["3.
|
|
12
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
13
13
|
|
|
14
14
|
steps:
|
|
15
15
|
- uses: actions/checkout@v7
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
Changes for v3.7.1 (2026-08-04)
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
- Fix for kislyuk#544 => TestZshGlobalExplicit tests are failing after
|
|
5
|
+
upgrade to zsh 5.9.0.1 (#557)
|
|
6
|
+
|
|
7
|
+
- Expand ~ in \_FilteredFilesCompleter (DirectoriesCompleter) (#553)
|
|
8
|
+
|
|
1
9
|
Changes for v3.7.0 (2026-06-30)
|
|
2
10
|
===============================
|
|
3
11
|
|
|
@@ -9,5 +9,5 @@ from .io import debug, mute_stderr, warn
|
|
|
9
9
|
from .lexers import split_line
|
|
10
10
|
from .shell_integration import shellcode
|
|
11
11
|
|
|
12
|
-
autocomplete = CompletionFinder()
|
|
12
|
+
autocomplete: CompletionFinder = CompletionFinder()
|
|
13
13
|
autocomplete.__doc__ = """ Use this to access argcomplete. See :meth:`argcomplete.CompletionFinder.__call__()`. """
|
|
@@ -145,9 +145,13 @@ _python_argcomplete_global() {
|
|
|
145
145
|
req_argv=( "" "${COMP_WORDS[@]:1}" )
|
|
146
146
|
__python_argcomplete_expand_tilde_by_ref executable
|
|
147
147
|
else
|
|
148
|
-
|
|
148
|
+
# Reconstruct the unshifted words array from BUFFER to handle cases where
|
|
149
|
+
# a helper completion function (like _python) has shifted the words array.
|
|
150
|
+
local -a local_words
|
|
151
|
+
local_words=( ${(z)BUFFER} )
|
|
152
|
+
executable="${local_words[1]}"
|
|
149
153
|
__python_argcomplete_expand_tilde_by_ref executable
|
|
150
|
-
req_argv=( "${
|
|
154
|
+
req_argv=( "${local_words[@]:1}" )
|
|
151
155
|
fi
|
|
152
156
|
|
|
153
157
|
local ARGCOMPLETE=0
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
import argparse
|
|
5
5
|
import os
|
|
6
6
|
import subprocess
|
|
7
|
+
from collections.abc import Callable, Generator, Iterable, Mapping
|
|
7
8
|
from shlex import quote
|
|
9
|
+
from typing import Final
|
|
10
|
+
|
|
11
|
+
_Ignored = object
|
|
8
12
|
|
|
9
13
|
|
|
10
14
|
def _call(*args, **kwargs):
|
|
@@ -23,12 +27,14 @@ class BaseCompleter:
|
|
|
23
27
|
|
|
24
28
|
def __call__(
|
|
25
29
|
self, *, prefix: str, action: argparse.Action, parser: argparse.ArgumentParser, parsed_args: argparse.Namespace
|
|
26
|
-
) ->
|
|
30
|
+
) -> Iterable[str]:
|
|
27
31
|
raise NotImplementedError("This method should be implemented by a subclass.")
|
|
28
32
|
|
|
29
33
|
|
|
30
34
|
class ChoicesCompleter(BaseCompleter):
|
|
31
|
-
|
|
35
|
+
choices: Final[Mapping[str, str | bytes]]
|
|
36
|
+
|
|
37
|
+
def __init__(self, choices: Mapping[str, str | bytes]) -> None:
|
|
32
38
|
self.choices = choices
|
|
33
39
|
|
|
34
40
|
def _convert(self, choice):
|
|
@@ -36,11 +42,11 @@ class ChoicesCompleter(BaseCompleter):
|
|
|
36
42
|
choice = str(choice)
|
|
37
43
|
return choice
|
|
38
44
|
|
|
39
|
-
def __call__(self, **kwargs):
|
|
45
|
+
def __call__(self, **kwargs: _Ignored) -> Iterable[str]:
|
|
40
46
|
return (self._convert(c) for c in self.choices)
|
|
41
47
|
|
|
42
48
|
|
|
43
|
-
EnvironCompleter = ChoicesCompleter(os.environ)
|
|
49
|
+
EnvironCompleter: Final[ChoicesCompleter] = ChoicesCompleter(os.environ)
|
|
44
50
|
|
|
45
51
|
|
|
46
52
|
class FilesCompleter(BaseCompleter):
|
|
@@ -48,7 +54,10 @@ class FilesCompleter(BaseCompleter):
|
|
|
48
54
|
File completer class, optionally takes a list of allowed extensions
|
|
49
55
|
"""
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
allowednames: Final[list[str]]
|
|
58
|
+
directories: Final[bool]
|
|
59
|
+
|
|
60
|
+
def __init__(self, allowednames: Iterable[str] | str = (), directories: bool = True) -> None:
|
|
52
61
|
# Fix if someone passes in a string instead of a list
|
|
53
62
|
if isinstance(allowednames, (str, bytes)):
|
|
54
63
|
allowednames = [allowednames]
|
|
@@ -56,8 +65,8 @@ class FilesCompleter(BaseCompleter):
|
|
|
56
65
|
self.allowednames = [x.lstrip("*").lstrip(".") for x in allowednames]
|
|
57
66
|
self.directories = directories
|
|
58
67
|
|
|
59
|
-
def __call__(self, prefix, **kwargs):
|
|
60
|
-
completion = []
|
|
68
|
+
def __call__(self, prefix: str, **kwargs: _Ignored) -> list[str]:
|
|
69
|
+
completion: list[str] = []
|
|
61
70
|
if self.allowednames:
|
|
62
71
|
if self.directories:
|
|
63
72
|
# Using 'bind' in this and the following commands is a workaround to a bug in bash
|
|
@@ -90,26 +99,31 @@ class FilesCompleter(BaseCompleter):
|
|
|
90
99
|
|
|
91
100
|
|
|
92
101
|
class _FilteredFilesCompleter(BaseCompleter):
|
|
93
|
-
|
|
102
|
+
predicate: Final[Callable[[str], bool]]
|
|
103
|
+
|
|
104
|
+
def __init__(self, predicate: Callable[[str], bool]) -> None:
|
|
94
105
|
"""
|
|
95
106
|
Create the completer
|
|
96
107
|
|
|
97
108
|
A predicate accepts as its only argument a candidate path and either
|
|
98
109
|
accepts it or rejects it.
|
|
99
110
|
"""
|
|
100
|
-
assert predicate, "Expected a callable predicate"
|
|
111
|
+
assert predicate, "Expected a callable predicate" # type: ignore[truthy-function]
|
|
101
112
|
self.predicate = predicate
|
|
102
113
|
|
|
103
|
-
def __call__(self, prefix, **kwargs):
|
|
114
|
+
def __call__(self, prefix: str, **kwargs: _Ignored) -> Generator[str]:
|
|
104
115
|
"""
|
|
105
116
|
Provide completions on prefix
|
|
106
117
|
"""
|
|
107
|
-
|
|
118
|
+
# Expand a leading "~" so that filesystem operations below work on a
|
|
119
|
+
# real path (os.listdir("~") would otherwise raise FileNotFoundError).
|
|
120
|
+
expanded_prefix = os.path.expanduser(prefix)
|
|
121
|
+
target_dir = os.path.dirname(expanded_prefix)
|
|
108
122
|
try:
|
|
109
123
|
names = os.listdir(target_dir or ".")
|
|
110
124
|
except Exception:
|
|
111
125
|
return # empty iterator
|
|
112
|
-
incomplete_part = os.path.basename(
|
|
126
|
+
incomplete_part = os.path.basename(expanded_prefix)
|
|
113
127
|
# Iterate on target_dir entries and filter on given predicate
|
|
114
128
|
for name in names:
|
|
115
129
|
if not name.startswith(incomplete_part):
|
|
@@ -121,7 +135,7 @@ class _FilteredFilesCompleter(BaseCompleter):
|
|
|
121
135
|
|
|
122
136
|
|
|
123
137
|
class DirectoriesCompleter(_FilteredFilesCompleter):
|
|
124
|
-
def __init__(self):
|
|
138
|
+
def __init__(self) -> None:
|
|
125
139
|
_FilteredFilesCompleter.__init__(self, predicate=os.path.isdir)
|
|
126
140
|
|
|
127
141
|
|
|
@@ -130,10 +144,10 @@ class SuppressCompleter(BaseCompleter):
|
|
|
130
144
|
A completer used to suppress the completion of specific arguments
|
|
131
145
|
"""
|
|
132
146
|
|
|
133
|
-
def __init__(self):
|
|
147
|
+
def __init__(self) -> None:
|
|
134
148
|
pass
|
|
135
149
|
|
|
136
|
-
def suppress(self):
|
|
150
|
+
def suppress(self) -> bool:
|
|
137
151
|
"""
|
|
138
152
|
Decide if the completion should be suppressed
|
|
139
153
|
"""
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import argparse
|
|
7
7
|
import os
|
|
8
8
|
import sys
|
|
9
|
-
from collections.abc import Mapping
|
|
10
|
-
from typing import Callable,
|
|
9
|
+
from collections.abc import Container, Mapping
|
|
10
|
+
from typing import Callable, Literal, TextIO
|
|
11
11
|
|
|
12
12
|
from . import io as _io
|
|
13
13
|
from .completers import BaseCompleter, ChoicesCompleter, FilesCompleter, SuppressCompleter
|
|
@@ -26,28 +26,42 @@ safe_actions = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
def default_validator(completion, prefix):
|
|
29
|
+
def default_validator(completion: str, prefix: str) -> bool:
|
|
30
30
|
return completion.startswith(prefix)
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
class CompletionFinder
|
|
33
|
+
class CompletionFinder:
|
|
34
34
|
"""
|
|
35
35
|
Inherit from this class if you wish to override any of the stages below. Otherwise, use
|
|
36
36
|
``argcomplete.autocomplete()`` directly (it's a convenience instance of this class). It has the same signature as
|
|
37
37
|
:meth:`CompletionFinder.__call__()`.
|
|
38
38
|
"""
|
|
39
39
|
|
|
40
|
+
_parser: argparse.ArgumentParser | None
|
|
41
|
+
_formatter: argparse.HelpFormatter | None
|
|
42
|
+
always_complete_options: bool | Literal["long", "short"]
|
|
43
|
+
exclude: Container[str] | None
|
|
44
|
+
validator: Callable[[str, str], bool]
|
|
45
|
+
print_suppressed: bool
|
|
46
|
+
completing: bool
|
|
47
|
+
_display_completions: dict[str, str]
|
|
48
|
+
default_completer: BaseCompleter
|
|
49
|
+
append_space: bool
|
|
50
|
+
|
|
51
|
+
active_parsers: list[argparse.ArgumentParser]
|
|
52
|
+
visited_positionals: list[argparse.Action]
|
|
53
|
+
|
|
40
54
|
def __init__(
|
|
41
55
|
self,
|
|
42
|
-
argument_parser=None,
|
|
43
|
-
always_complete_options=True,
|
|
44
|
-
exclude=None,
|
|
45
|
-
validator=None,
|
|
46
|
-
print_suppressed=False,
|
|
47
|
-
default_completer=FilesCompleter(),
|
|
48
|
-
append_space=None,
|
|
49
|
-
):
|
|
50
|
-
self._parser = argument_parser
|
|
56
|
+
argument_parser: argparse.ArgumentParser | None = None,
|
|
57
|
+
always_complete_options: bool | Literal["long", "short"] = True,
|
|
58
|
+
exclude: Container[str] | None = None,
|
|
59
|
+
validator: Callable[[str, str], bool] | None = None,
|
|
60
|
+
print_suppressed: bool = False,
|
|
61
|
+
default_completer: BaseCompleter = FilesCompleter(),
|
|
62
|
+
append_space: bool | None = None,
|
|
63
|
+
) -> None:
|
|
64
|
+
self._parser = argument_parser # type: ignore[assignment]
|
|
51
65
|
self._formatter = None
|
|
52
66
|
self.always_complete_options = always_complete_options
|
|
53
67
|
self.exclude = exclude
|
|
@@ -56,7 +70,7 @@ class CompletionFinder(object):
|
|
|
56
70
|
self.validator = validator
|
|
57
71
|
self.print_suppressed = print_suppressed
|
|
58
72
|
self.completing = False
|
|
59
|
-
self._display_completions
|
|
73
|
+
self._display_completions = {}
|
|
60
74
|
self.default_completer = default_completer
|
|
61
75
|
if append_space is None:
|
|
62
76
|
append_space = os.environ.get("_ARGCOMPLETE_SUPPRESS_SPACE") != "1"
|
|
@@ -65,13 +79,13 @@ class CompletionFinder(object):
|
|
|
65
79
|
def __call__(
|
|
66
80
|
self,
|
|
67
81
|
argument_parser: argparse.ArgumentParser,
|
|
68
|
-
always_complete_options:
|
|
82
|
+
always_complete_options: bool | str = True,
|
|
69
83
|
exit_method: Callable = os._exit,
|
|
70
|
-
output_stream:
|
|
71
|
-
exclude:
|
|
72
|
-
validator:
|
|
84
|
+
output_stream: TextIO | None = None,
|
|
85
|
+
exclude: Container[str] | None = None,
|
|
86
|
+
validator: Callable[[str, str], bool] | None = None,
|
|
73
87
|
print_suppressed: bool = False,
|
|
74
|
-
append_space:
|
|
88
|
+
append_space: bool | None = None,
|
|
75
89
|
default_completer: BaseCompleter = FilesCompleter(),
|
|
76
90
|
) -> None:
|
|
77
91
|
"""
|
|
@@ -158,6 +172,7 @@ class CompletionFinder(object):
|
|
|
158
172
|
start = int(os.environ["_ARGCOMPLETE"]) - 1
|
|
159
173
|
comp_words = comp_words[start:]
|
|
160
174
|
|
|
175
|
+
assert self._parser is not None
|
|
161
176
|
if cword_prefix and cword_prefix[0] in self._parser.prefix_chars and "=" in cword_prefix:
|
|
162
177
|
# Special case for when the current word is "--optional=PARTIAL_VALUE". Give the optional to the parser.
|
|
163
178
|
comp_words.append(cword_prefix.split("=", 1)[0])
|
|
@@ -211,6 +226,7 @@ class CompletionFinder(object):
|
|
|
211
226
|
try:
|
|
212
227
|
debug("invoking parser with", comp_words[1:])
|
|
213
228
|
with mute_stderr():
|
|
229
|
+
assert self._parser is not None
|
|
214
230
|
a = self._parser.parse_known_args(comp_words[1:], namespace=parsed_args)
|
|
215
231
|
debug("parsed args:", a)
|
|
216
232
|
except BaseException as e:
|
|
@@ -233,8 +249,8 @@ class CompletionFinder(object):
|
|
|
233
249
|
figure out which subparsers need to be activated (then recursively monkey-patch those).
|
|
234
250
|
We save all active ArgumentParsers to extract all their possible option names later.
|
|
235
251
|
"""
|
|
236
|
-
self.active_parsers
|
|
237
|
-
self.visited_positionals
|
|
252
|
+
self.active_parsers = []
|
|
253
|
+
self.visited_positionals = []
|
|
238
254
|
|
|
239
255
|
completer = self
|
|
240
256
|
|
|
@@ -289,12 +305,14 @@ class CompletionFinder(object):
|
|
|
289
305
|
return ""
|
|
290
306
|
if "%" not in action.help:
|
|
291
307
|
return action.help
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
308
|
+
formatters = self._formatter
|
|
309
|
+
if formatters is None:
|
|
310
|
+
assert self._parser is not None
|
|
311
|
+
self._formatter = formatters = self._parser.formatter_class(prog=self._parser.prog)
|
|
312
|
+
return formatters._expand_help(action)
|
|
295
313
|
|
|
296
314
|
def _get_subparser_completions(self, parser, cword_prefix):
|
|
297
|
-
aliases_by_parser:
|
|
315
|
+
aliases_by_parser: dict[argparse.ArgumentParser, list[str]] = {}
|
|
298
316
|
for key in parser.choices.keys():
|
|
299
317
|
p = parser.choices[key]
|
|
300
318
|
aliases_by_parser.setdefault(p, []).append(key)
|
|
@@ -433,15 +451,15 @@ class CompletionFinder(object):
|
|
|
433
451
|
return completions
|
|
434
452
|
|
|
435
453
|
def collect_completions(
|
|
436
|
-
self, active_parsers:
|
|
437
|
-
) ->
|
|
454
|
+
self, active_parsers: list[argparse.ArgumentParser], parsed_args: argparse.Namespace, cword_prefix: str
|
|
455
|
+
) -> list[str]:
|
|
438
456
|
"""
|
|
439
457
|
Visits the active parsers and their actions, executes their completers or introspects them to collect their
|
|
440
458
|
option strings. Returns the resulting completions as a list of strings.
|
|
441
459
|
|
|
442
460
|
This method is exposed for overriding in subclasses; there is no need to use it directly.
|
|
443
461
|
"""
|
|
444
|
-
completions:
|
|
462
|
+
completions: list[str] = []
|
|
445
463
|
|
|
446
464
|
debug("all active parsers:", active_parsers)
|
|
447
465
|
active_parser = active_parsers[-1]
|
|
@@ -488,7 +506,7 @@ class CompletionFinder(object):
|
|
|
488
506
|
|
|
489
507
|
return None
|
|
490
508
|
|
|
491
|
-
def filter_completions(self, completions:
|
|
509
|
+
def filter_completions(self, completions: list[str]) -> list[str]:
|
|
492
510
|
"""
|
|
493
511
|
De-duplicates completions and excludes those specified by ``exclude``.
|
|
494
512
|
Returns the filtered completions as a list.
|
|
@@ -505,8 +523,8 @@ class CompletionFinder(object):
|
|
|
505
523
|
return filtered_completions
|
|
506
524
|
|
|
507
525
|
def quote_completions(
|
|
508
|
-
self, completions:
|
|
509
|
-
) ->
|
|
526
|
+
self, completions: list[str], cword_prequote: str, last_wordbreak_pos: int | None
|
|
527
|
+
) -> list[str]:
|
|
510
528
|
"""
|
|
511
529
|
If the word under the cursor started with a quote (as indicated by a nonempty ``cword_prequote``), escapes
|
|
512
530
|
occurrences of that quote character in the completions, and adds the quote to the beginning of each completion.
|
|
@@ -570,7 +588,7 @@ class CompletionFinder(object):
|
|
|
570
588
|
|
|
571
589
|
return escaped_completions
|
|
572
590
|
|
|
573
|
-
def rl_complete(self, text, state):
|
|
591
|
+
def rl_complete(self, text: str, state: int) -> str | None:
|
|
574
592
|
"""
|
|
575
593
|
Alternate entry point for using the argcomplete completer in a readline-based REPL. See also
|
|
576
594
|
`rlcompleter <https://docs.python.org/3/library/rlcompleter.html#completer-objects>`_.
|
|
@@ -598,7 +616,7 @@ class CompletionFinder(object):
|
|
|
598
616
|
else:
|
|
599
617
|
return None
|
|
600
618
|
|
|
601
|
-
def get_display_completions(self):
|
|
619
|
+
def get_display_completions(self) -> dict[str, str]:
|
|
602
620
|
"""
|
|
603
621
|
This function returns a mapping of completions to their help strings for displaying to the user.
|
|
604
622
|
"""
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import contextlib
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
|
+
from collections.abc import Generator
|
|
4
5
|
|
|
5
6
|
_DEBUG = "_ARC_DEBUG" in os.environ
|
|
6
7
|
|
|
7
8
|
debug_stream = sys.stderr
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
def debug(*args):
|
|
11
|
+
def debug(*args: object) -> None:
|
|
11
12
|
if _DEBUG:
|
|
12
13
|
print(file=debug_stream, *args)
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
@contextlib.contextmanager
|
|
16
|
-
def mute_stdout():
|
|
17
|
+
def mute_stdout() -> Generator[None]:
|
|
17
18
|
stdout = sys.stdout
|
|
18
19
|
sys.stdout = open(os.devnull, "w")
|
|
19
20
|
try:
|
|
@@ -23,7 +24,7 @@ def mute_stdout():
|
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
@contextlib.contextmanager
|
|
26
|
-
def mute_stderr():
|
|
27
|
+
def mute_stderr() -> Generator[None]:
|
|
27
28
|
stderr = sys.stderr
|
|
28
29
|
sys.stderr = open(os.devnull, "w")
|
|
29
30
|
try:
|
|
@@ -33,7 +34,7 @@ def mute_stderr():
|
|
|
33
34
|
sys.stderr = stderr
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
def warn(*args):
|
|
37
|
+
def warn(*args: object) -> None:
|
|
37
38
|
"""
|
|
38
39
|
Prints **args** to standard error when running completions. This will interrupt the user's command line interaction;
|
|
39
40
|
use it to indicate an error condition that is preventing your completer from working.
|
|
@@ -5,7 +5,7 @@ from .io import debug
|
|
|
5
5
|
from .packages import _shlex
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def split_line(line, point=None):
|
|
8
|
+
def split_line(line: str, point: int | None = None) -> tuple[str, str, str, list[str], int | None]:
|
|
9
9
|
if point is None:
|
|
10
10
|
point = len(line)
|
|
11
11
|
line = line[:point]
|
|
@@ -14,7 +14,7 @@ def split_line(line, point=None):
|
|
|
14
14
|
lexer.wordbreaks = os.environ.get("_ARGCOMPLETE_COMP_WORDBREAKS", "")
|
|
15
15
|
words = []
|
|
16
16
|
|
|
17
|
-
def split_word(word):
|
|
17
|
+
def split_word(word: str) -> tuple[str, str, str, list[str], int | None]:
|
|
18
18
|
# TODO: make this less ugly
|
|
19
19
|
point_in_word = len(word) + point - lexer.instream.tell()
|
|
20
20
|
if isinstance(lexer.state, (str, bytes)) and lexer.state in lexer.whitespace:
|
{argcomplete-3.7.0 → argcomplete-3.7.1}/argcomplete/scripts/activate_global_python_argcomplete.py
RENAMED
|
@@ -32,7 +32,9 @@ source "{activator}"
|
|
|
32
32
|
# End added by argcomplete
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
|
-
parser
|
|
35
|
+
parser: argparse.ArgumentParser = argparse.ArgumentParser(
|
|
36
|
+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
|
|
37
|
+
)
|
|
36
38
|
parser.add_argument("-y", "--yes", help="automatically answer yes for all questions", action="store_true")
|
|
37
39
|
parser.add_argument("--dest", help='Specify the shell completion modules directory to install into, or "-" for stdout')
|
|
38
40
|
parser.add_argument("--user", help="Install into user directory", action="store_true")
|
|
@@ -40,18 +42,18 @@ argcomplete.autocomplete(parser)
|
|
|
40
42
|
args = None
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
def get_local_dir():
|
|
45
|
+
def get_local_dir() -> str:
|
|
44
46
|
try:
|
|
45
47
|
return subprocess.check_output(["brew", "--prefix"]).decode().strip()
|
|
46
48
|
except (FileNotFoundError, subprocess.CalledProcessError):
|
|
47
49
|
return "/usr/local"
|
|
48
50
|
|
|
49
51
|
|
|
50
|
-
def get_zsh_system_dir():
|
|
52
|
+
def get_zsh_system_dir() -> str:
|
|
51
53
|
return f"{get_local_dir()}/share/zsh/site-functions"
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
def get_bash_system_dir():
|
|
56
|
+
def get_bash_system_dir() -> str:
|
|
55
57
|
if "BASH_COMPLETION_COMPAT_DIR" in os.environ:
|
|
56
58
|
return os.environ["BASH_COMPLETION_COMPAT_DIR"]
|
|
57
59
|
elif sys.platform == "darwin":
|
|
@@ -60,15 +62,15 @@ def get_bash_system_dir():
|
|
|
60
62
|
return "/etc/bash_completion.d" # created by bash-completion
|
|
61
63
|
|
|
62
64
|
|
|
63
|
-
def get_activator_dir():
|
|
65
|
+
def get_activator_dir() -> str:
|
|
64
66
|
return os.path.join(os.path.abspath(os.path.dirname(argcomplete.__file__)), "bash_completion.d")
|
|
65
67
|
|
|
66
68
|
|
|
67
|
-
def get_activator_path():
|
|
69
|
+
def get_activator_path() -> str:
|
|
68
70
|
return os.path.join(get_activator_dir(), "_python-argcomplete")
|
|
69
71
|
|
|
70
72
|
|
|
71
|
-
def install_to_destination(dest):
|
|
73
|
+
def install_to_destination(dest: str) -> None:
|
|
72
74
|
activator = get_activator_path()
|
|
73
75
|
if dest == "-":
|
|
74
76
|
with open(activator) as fh:
|
|
@@ -92,7 +94,7 @@ def install_to_destination(dest):
|
|
|
92
94
|
)
|
|
93
95
|
|
|
94
96
|
|
|
95
|
-
def get_consent():
|
|
97
|
+
def get_consent() -> bool:
|
|
96
98
|
assert args is not None
|
|
97
99
|
if args.yes is True:
|
|
98
100
|
return True
|
|
@@ -106,7 +108,7 @@ def get_consent():
|
|
|
106
108
|
return False
|
|
107
109
|
|
|
108
110
|
|
|
109
|
-
def append_to_config_file(path, shellcode):
|
|
111
|
+
def append_to_config_file(path: str | os.PathLike[str], shellcode: str) -> None:
|
|
110
112
|
if os.path.exists(path):
|
|
111
113
|
with open(path, 'r') as fh:
|
|
112
114
|
if shellcode in fh.read():
|
|
@@ -124,23 +126,23 @@ def append_to_config_file(path, shellcode):
|
|
|
124
126
|
print("Added.", file=sys.stderr)
|
|
125
127
|
|
|
126
128
|
|
|
127
|
-
def link_zsh_user_rcfile(zsh_fpath=None):
|
|
129
|
+
def link_zsh_user_rcfile(zsh_fpath: str | None = None) -> None:
|
|
128
130
|
zsh_rcfile = os.path.join(os.path.expanduser(os.environ.get("ZDOTDIR", "~")), ".zshenv")
|
|
129
131
|
append_to_config_file(zsh_rcfile, zsh_shellcode.format(zsh_fpath=zsh_fpath or get_activator_dir()))
|
|
130
132
|
|
|
131
133
|
|
|
132
|
-
def link_bash_user_rcfile():
|
|
134
|
+
def link_bash_user_rcfile() -> None:
|
|
133
135
|
bash_completion_user_file = os.path.expanduser("~/.bash_completion")
|
|
134
136
|
append_to_config_file(bash_completion_user_file, bash_shellcode.format(activator=get_activator_path()))
|
|
135
137
|
|
|
136
138
|
|
|
137
|
-
def link_user_rcfiles():
|
|
139
|
+
def link_user_rcfiles() -> None:
|
|
138
140
|
# TODO: warn if running as superuser
|
|
139
141
|
link_zsh_user_rcfile()
|
|
140
142
|
link_bash_user_rcfile()
|
|
141
143
|
|
|
142
144
|
|
|
143
|
-
def add_zsh_system_dir_to_fpath_for_user():
|
|
145
|
+
def add_zsh_system_dir_to_fpath_for_user() -> None:
|
|
144
146
|
if "zsh" not in os.environ.get("SHELL", ""):
|
|
145
147
|
return
|
|
146
148
|
try:
|
|
@@ -154,7 +156,7 @@ def add_zsh_system_dir_to_fpath_for_user():
|
|
|
154
156
|
pass
|
|
155
157
|
|
|
156
158
|
|
|
157
|
-
def main():
|
|
159
|
+
def main() -> None:
|
|
158
160
|
global args
|
|
159
161
|
args = parser.parse_args()
|
|
160
162
|
|
|
@@ -190,4 +192,4 @@ def main():
|
|
|
190
192
|
|
|
191
193
|
|
|
192
194
|
if __name__ == "__main__":
|
|
193
|
-
sys.exit(main())
|
|
195
|
+
sys.exit(main()) # type: ignore[func-returns-value]
|
|
@@ -32,7 +32,7 @@ import argcomplete
|
|
|
32
32
|
__package__ = "argcomplete.scripts"
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def main():
|
|
35
|
+
def main() -> None:
|
|
36
36
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
37
37
|
|
|
38
38
|
parser.add_argument(
|
|
@@ -76,4 +76,4 @@ def main():
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
if __name__ == "__main__":
|
|
79
|
-
sys.exit(main())
|
|
79
|
+
sys.exit(main()) # type: ignore[func-returns-value]
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
|
|
4
4
|
# See https://github.com/kislyuk/argcomplete for more info.
|
|
5
5
|
|
|
6
|
+
from collections.abc import Iterable
|
|
6
7
|
from shlex import quote
|
|
7
8
|
|
|
8
9
|
bashcode = r"""#compdef %(executables)s
|
|
@@ -135,7 +136,13 @@ Register-ArgumentCompleter -Native -CommandName %(executable)s -ScriptBlock {
|
|
|
135
136
|
shell_codes = {"bash": bashcode, "tcsh": tcshcode, "fish": fishcode, "powershell": powershell_code}
|
|
136
137
|
|
|
137
138
|
|
|
138
|
-
def shellcode(
|
|
139
|
+
def shellcode(
|
|
140
|
+
executables: Iterable[str],
|
|
141
|
+
use_defaults: bool = True,
|
|
142
|
+
shell: str = "bash",
|
|
143
|
+
complete_arguments: Iterable[str] | None = None,
|
|
144
|
+
argcomplete_script: str | None = None,
|
|
145
|
+
) -> str:
|
|
139
146
|
"""
|
|
140
147
|
Provide the shell code required to register a python executable for use with the argcomplete module.
|
|
141
148
|
|
|
@@ -414,6 +414,44 @@ class TestArgcomplete(unittest.TestCase):
|
|
|
414
414
|
self.assertEqual(c("def/k"), set([]))
|
|
415
415
|
return
|
|
416
416
|
|
|
417
|
+
def test_directory_completion_with_tilde(self):
|
|
418
|
+
# Regression test for https://github.com/kislyuk/argcomplete/issues/529
|
|
419
|
+
# "~/<TAB>" should expand the home directory instead of yielding nothing
|
|
420
|
+
# (os.listdir("~") would otherwise raise FileNotFoundError).
|
|
421
|
+
completer = DirectoriesCompleter()
|
|
422
|
+
|
|
423
|
+
def c(prefix):
|
|
424
|
+
return set(completer(prefix))
|
|
425
|
+
|
|
426
|
+
old_home = os.environ.get("HOME")
|
|
427
|
+
old_userprofile = os.environ.get("USERPROFILE")
|
|
428
|
+
with TempDir(prefix="test_dir_tilde", dir=".") as tmp_dir:
|
|
429
|
+
home = os.path.realpath(tmp_dir)
|
|
430
|
+
os.environ["HOME"] = home
|
|
431
|
+
os.environ["USERPROFILE"] = home
|
|
432
|
+
try:
|
|
433
|
+
# Create some directories and files (files must be ignored)
|
|
434
|
+
os.makedirs(os.path.join(home, "abc", "baz"))
|
|
435
|
+
os.makedirs(os.path.join(home, "abb"))
|
|
436
|
+
with open(os.path.join(home, "abc1"), "w") as fp:
|
|
437
|
+
fp.write("A test")
|
|
438
|
+
# "~/" lists the home directory
|
|
439
|
+
self.assertEqual(c("~/"), set([os.path.join(home, "abb") + "/", os.path.join(home, "abc") + "/"]))
|
|
440
|
+
# "~/ab" filters within the home directory
|
|
441
|
+
self.assertEqual(c("~/ab"), set([os.path.join(home, "abb") + "/", os.path.join(home, "abc") + "/"]))
|
|
442
|
+
# "~/abc/" recurses into a subdirectory
|
|
443
|
+
self.assertEqual(c("~/abc/"), set([os.path.join(home, "abc", "baz") + "/"]))
|
|
444
|
+
finally:
|
|
445
|
+
if old_home is None:
|
|
446
|
+
os.environ.pop("HOME", None)
|
|
447
|
+
else:
|
|
448
|
+
os.environ["HOME"] = old_home
|
|
449
|
+
if old_userprofile is None:
|
|
450
|
+
os.environ.pop("USERPROFILE", None)
|
|
451
|
+
else:
|
|
452
|
+
os.environ["USERPROFILE"] = old_userprofile
|
|
453
|
+
return
|
|
454
|
+
|
|
417
455
|
def test_default_completer(self):
|
|
418
456
|
def make_parser():
|
|
419
457
|
parser = ArgumentParser(add_help=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|