argcomplete 3.6.3__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.6.3 → argcomplete-3.7.1}/.github/workflows/ci.yml +10 -10
- {argcomplete-3.6.3 → argcomplete-3.7.1}/Changes.rst +16 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/PKG-INFO +2 -2
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/__init__.py +1 -1
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/bash_completion.d/_python-argcomplete +7 -6
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/completers.py +36 -19
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/finders.py +52 -34
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/io.py +5 -4
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/lexers.py +2 -2
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/packages/_argparse.py +16 -8
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/scripts/activate_global_python_argcomplete.py +17 -15
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/scripts/register_python_argcomplete.py +2 -2
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/shell_integration.py +8 -1
- {argcomplete-3.6.3 → argcomplete-3.7.1}/pyproject.toml +1 -2
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/test.py +52 -0
- argcomplete-3.6.3/argcomplete/scripts/python_argcomplete_check_easy_install_script.py +0 -84
- {argcomplete-3.6.3 → argcomplete-3.7.1}/.github/FUNDING.yml +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/.github/workflows/release.yml +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/.gitignore +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/Authors.rst +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/LICENSE.rst +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/MANIFEST.in +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/Makefile +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/NOTICE +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/README.rst +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/SECURITY.md +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/_check_console_script.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/_check_module.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/exceptions.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/packages/__init__.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/packages/_shlex.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/py.typed +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/argcomplete/scripts/__init__.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/common.mk +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/contrib/README.rst +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/docs/changelog.rst +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/docs/conf.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/docs/examples/describe_github_user.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/docs/fish_help_string.png +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/docs/index.rst +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/docs/toc.html +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/setup.cfg +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/__init__.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/inputrc +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/prog +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/stuck +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/test_contrib_shells.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/test_package/__init__.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/test_package/setup.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/test_package/test_module.py +0 -0
- {argcomplete-3.6.3 → argcomplete-3.7.1}/test/test_package/test_package/__init__.py +0 -0
|
@@ -3,17 +3,17 @@ name: Python package
|
|
|
3
3
|
on: [push, pull_request]
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
|
-
|
|
6
|
+
ci:
|
|
7
7
|
runs-on: ${{matrix.os}}
|
|
8
8
|
strategy:
|
|
9
9
|
fail-fast: false
|
|
10
10
|
matrix:
|
|
11
|
-
os: [ubuntu-
|
|
12
|
-
python-version: ["3.
|
|
11
|
+
os: [ubuntu-22.04, ubuntu-latest, macos-14, macos-latest]
|
|
12
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
13
13
|
|
|
14
14
|
steps:
|
|
15
|
-
- uses: actions/checkout@
|
|
16
|
-
- uses: actions/setup-python@
|
|
15
|
+
- uses: actions/checkout@v7
|
|
16
|
+
- uses: actions/setup-python@v6
|
|
17
17
|
with:
|
|
18
18
|
python-version: ${{matrix.python-version}}
|
|
19
19
|
allow-prereleases: true
|
|
@@ -31,15 +31,15 @@ jobs:
|
|
|
31
31
|
- uses: codecov/codecov-action@v5
|
|
32
32
|
if: ${{matrix.python-version == '3.12' && matrix.os == 'ubuntu-22.04'}}
|
|
33
33
|
isort:
|
|
34
|
-
runs-on: ubuntu-
|
|
34
|
+
runs-on: ubuntu-24.04
|
|
35
35
|
steps:
|
|
36
|
-
- uses: actions/checkout@
|
|
36
|
+
- uses: actions/checkout@v7
|
|
37
37
|
- uses: isort/isort-action@v1.1.0
|
|
38
38
|
ruff:
|
|
39
39
|
runs-on: ubuntu-latest
|
|
40
40
|
steps:
|
|
41
|
-
- uses: actions/checkout@
|
|
42
|
-
- uses: astral-sh/ruff-action@
|
|
43
|
-
- uses: astral-sh/ruff-action@
|
|
41
|
+
- uses: actions/checkout@v7
|
|
42
|
+
- uses: astral-sh/ruff-action@v4.0.0
|
|
43
|
+
- uses: astral-sh/ruff-action@v4.0.0
|
|
44
44
|
with:
|
|
45
45
|
args: "format --check"
|
|
@@ -1,3 +1,19 @@
|
|
|
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
|
+
|
|
9
|
+
Changes for v3.7.0 (2026-06-30)
|
|
10
|
+
===============================
|
|
11
|
+
|
|
12
|
+
- Escape glob and brace metacharacters in quote_completions (#552)
|
|
13
|
+
- Quote prefix passed to compgen in FilesCompleter (#551)
|
|
14
|
+
- Remove deprecated easy_install script detection
|
|
15
|
+
- Type hinting improvements
|
|
16
|
+
|
|
1
17
|
Changes for v3.6.3 (2025-10-19)
|
|
2
18
|
===============================
|
|
3
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: argcomplete
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.1
|
|
4
4
|
Summary: Bash tab completion for argparse
|
|
5
5
|
Project-URL: Homepage, https://github.com/kislyuk/argcomplete
|
|
6
6
|
Project-URL: Documentation, https://kislyuk.github.io/argcomplete
|
|
@@ -22,12 +22,12 @@ Classifier: Operating System :: MacOS :: MacOS X
|
|
|
22
22
|
Classifier: Operating System :: POSIX
|
|
23
23
|
Classifier: Programming Language :: Python
|
|
24
24
|
Classifier: Programming Language :: Python :: 3
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
26
25
|
Classifier: Programming Language :: Python :: 3.9
|
|
27
26
|
Classifier: Programming Language :: Python :: 3.10
|
|
28
27
|
Classifier: Programming Language :: Python :: 3.11
|
|
29
28
|
Classifier: Programming Language :: Python :: 3.12
|
|
30
29
|
Classifier: Programming Language :: Python :: 3.13
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
31
31
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
32
32
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
33
33
|
Classifier: Topic :: Software Development
|
|
@@ -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
|
|
@@ -190,10 +194,7 @@ _python_argcomplete_global() {
|
|
|
190
194
|
interpreter=($interpreter)
|
|
191
195
|
fi
|
|
192
196
|
|
|
193
|
-
if (
|
|
194
|
-
&& "${interpreter[@]}" "$(__python_argcomplete_which python-argcomplete-check-easy-install-script)" "$SCRIPT_NAME") >/dev/null 2>&1; then
|
|
195
|
-
ARGCOMPLETE=1
|
|
196
|
-
elif ([[ "${interpreter[@]}" == *python* ]] || [[ "${interpreter[@]}" == *pypy* ]])\
|
|
197
|
+
if ([[ "${interpreter[@]}" == *python* ]] || [[ "${interpreter[@]}" == *pypy* ]])\
|
|
197
198
|
&& __python_argcomplete_run "${interpreter[@]}" -m argcomplete._check_console_script "$SCRIPT_NAME"; then
|
|
198
199
|
ARGCOMPLETE=1
|
|
199
200
|
fi
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
import argparse
|
|
5
5
|
import os
|
|
6
6
|
import subprocess
|
|
7
|
+
from collections.abc import Callable, Generator, Iterable, Mapping
|
|
8
|
+
from shlex import quote
|
|
9
|
+
from typing import Final
|
|
10
|
+
|
|
11
|
+
_Ignored = object
|
|
7
12
|
|
|
8
13
|
|
|
9
14
|
def _call(*args, **kwargs):
|
|
@@ -22,12 +27,14 @@ class BaseCompleter:
|
|
|
22
27
|
|
|
23
28
|
def __call__(
|
|
24
29
|
self, *, prefix: str, action: argparse.Action, parser: argparse.ArgumentParser, parsed_args: argparse.Namespace
|
|
25
|
-
) ->
|
|
30
|
+
) -> Iterable[str]:
|
|
26
31
|
raise NotImplementedError("This method should be implemented by a subclass.")
|
|
27
32
|
|
|
28
33
|
|
|
29
34
|
class ChoicesCompleter(BaseCompleter):
|
|
30
|
-
|
|
35
|
+
choices: Final[Mapping[str, str | bytes]]
|
|
36
|
+
|
|
37
|
+
def __init__(self, choices: Mapping[str, str | bytes]) -> None:
|
|
31
38
|
self.choices = choices
|
|
32
39
|
|
|
33
40
|
def _convert(self, choice):
|
|
@@ -35,11 +42,11 @@ class ChoicesCompleter(BaseCompleter):
|
|
|
35
42
|
choice = str(choice)
|
|
36
43
|
return choice
|
|
37
44
|
|
|
38
|
-
def __call__(self, **kwargs):
|
|
45
|
+
def __call__(self, **kwargs: _Ignored) -> Iterable[str]:
|
|
39
46
|
return (self._convert(c) for c in self.choices)
|
|
40
47
|
|
|
41
48
|
|
|
42
|
-
EnvironCompleter = ChoicesCompleter(os.environ)
|
|
49
|
+
EnvironCompleter: Final[ChoicesCompleter] = ChoicesCompleter(os.environ)
|
|
43
50
|
|
|
44
51
|
|
|
45
52
|
class FilesCompleter(BaseCompleter):
|
|
@@ -47,7 +54,10 @@ class FilesCompleter(BaseCompleter):
|
|
|
47
54
|
File completer class, optionally takes a list of allowed extensions
|
|
48
55
|
"""
|
|
49
56
|
|
|
50
|
-
|
|
57
|
+
allowednames: Final[list[str]]
|
|
58
|
+
directories: Final[bool]
|
|
59
|
+
|
|
60
|
+
def __init__(self, allowednames: Iterable[str] | str = (), directories: bool = True) -> None:
|
|
51
61
|
# Fix if someone passes in a string instead of a list
|
|
52
62
|
if isinstance(allowednames, (str, bytes)):
|
|
53
63
|
allowednames = [allowednames]
|
|
@@ -55,8 +65,8 @@ class FilesCompleter(BaseCompleter):
|
|
|
55
65
|
self.allowednames = [x.lstrip("*").lstrip(".") for x in allowednames]
|
|
56
66
|
self.directories = directories
|
|
57
67
|
|
|
58
|
-
def __call__(self, prefix, **kwargs):
|
|
59
|
-
completion = []
|
|
68
|
+
def __call__(self, prefix: str, **kwargs: _Ignored) -> list[str]:
|
|
69
|
+
completion: list[str] = []
|
|
60
70
|
if self.allowednames:
|
|
61
71
|
if self.directories:
|
|
62
72
|
# Using 'bind' in this and the following commands is a workaround to a bug in bash
|
|
@@ -64,20 +74,22 @@ class FilesCompleter(BaseCompleter):
|
|
|
64
74
|
# correctly in older versions and calling bind makes them available. For details, see
|
|
65
75
|
# https://savannah.gnu.org/support/index.php?111125
|
|
66
76
|
files = _call(
|
|
67
|
-
["bash", "-c", "bind; compgen -A directory --
|
|
77
|
+
["bash", "-c", "bind; compgen -A directory -- {p}".format(p=quote(prefix))],
|
|
78
|
+
stderr=subprocess.DEVNULL,
|
|
68
79
|
)
|
|
69
80
|
completion += [f + "/" for f in files]
|
|
70
81
|
for x in self.allowednames:
|
|
71
82
|
completion += _call(
|
|
72
|
-
["bash", "-c", "bind; compgen -A file -X '!*.{0}' --
|
|
83
|
+
["bash", "-c", "bind; compgen -A file -X '!*.{0}' -- {p}".format(x, p=quote(prefix))],
|
|
73
84
|
stderr=subprocess.DEVNULL,
|
|
74
85
|
)
|
|
75
86
|
else:
|
|
76
87
|
completion += _call(
|
|
77
|
-
["bash", "-c", "bind; compgen -A file --
|
|
88
|
+
["bash", "-c", "bind; compgen -A file -- {p}".format(p=quote(prefix))], stderr=subprocess.DEVNULL
|
|
78
89
|
)
|
|
79
90
|
anticomp = _call(
|
|
80
|
-
["bash", "-c", "bind; compgen -A directory --
|
|
91
|
+
["bash", "-c", "bind; compgen -A directory -- {p}".format(p=quote(prefix))],
|
|
92
|
+
stderr=subprocess.DEVNULL,
|
|
81
93
|
)
|
|
82
94
|
completion = list(set(completion) - set(anticomp))
|
|
83
95
|
|
|
@@ -87,26 +99,31 @@ class FilesCompleter(BaseCompleter):
|
|
|
87
99
|
|
|
88
100
|
|
|
89
101
|
class _FilteredFilesCompleter(BaseCompleter):
|
|
90
|
-
|
|
102
|
+
predicate: Final[Callable[[str], bool]]
|
|
103
|
+
|
|
104
|
+
def __init__(self, predicate: Callable[[str], bool]) -> None:
|
|
91
105
|
"""
|
|
92
106
|
Create the completer
|
|
93
107
|
|
|
94
108
|
A predicate accepts as its only argument a candidate path and either
|
|
95
109
|
accepts it or rejects it.
|
|
96
110
|
"""
|
|
97
|
-
assert predicate, "Expected a callable predicate"
|
|
111
|
+
assert predicate, "Expected a callable predicate" # type: ignore[truthy-function]
|
|
98
112
|
self.predicate = predicate
|
|
99
113
|
|
|
100
|
-
def __call__(self, prefix, **kwargs):
|
|
114
|
+
def __call__(self, prefix: str, **kwargs: _Ignored) -> Generator[str]:
|
|
101
115
|
"""
|
|
102
116
|
Provide completions on prefix
|
|
103
117
|
"""
|
|
104
|
-
|
|
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)
|
|
105
122
|
try:
|
|
106
123
|
names = os.listdir(target_dir or ".")
|
|
107
124
|
except Exception:
|
|
108
125
|
return # empty iterator
|
|
109
|
-
incomplete_part = os.path.basename(
|
|
126
|
+
incomplete_part = os.path.basename(expanded_prefix)
|
|
110
127
|
# Iterate on target_dir entries and filter on given predicate
|
|
111
128
|
for name in names:
|
|
112
129
|
if not name.startswith(incomplete_part):
|
|
@@ -118,7 +135,7 @@ class _FilteredFilesCompleter(BaseCompleter):
|
|
|
118
135
|
|
|
119
136
|
|
|
120
137
|
class DirectoriesCompleter(_FilteredFilesCompleter):
|
|
121
|
-
def __init__(self):
|
|
138
|
+
def __init__(self) -> None:
|
|
122
139
|
_FilteredFilesCompleter.__init__(self, predicate=os.path.isdir)
|
|
123
140
|
|
|
124
141
|
|
|
@@ -127,10 +144,10 @@ class SuppressCompleter(BaseCompleter):
|
|
|
127
144
|
A completer used to suppress the completion of specific arguments
|
|
128
145
|
"""
|
|
129
146
|
|
|
130
|
-
def __init__(self):
|
|
147
|
+
def __init__(self) -> None:
|
|
131
148
|
pass
|
|
132
149
|
|
|
133
|
-
def suppress(self):
|
|
150
|
+
def suppress(self) -> bool:
|
|
134
151
|
"""
|
|
135
152
|
Decide if the completion should be suppressed
|
|
136
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.
|
|
@@ -527,7 +545,7 @@ class CompletionFinder(object):
|
|
|
527
545
|
# (extended to characters other than the colon).
|
|
528
546
|
if last_wordbreak_pos is not None:
|
|
529
547
|
completions = [c[last_wordbreak_pos + 1 :] for c in completions]
|
|
530
|
-
special_chars += "()
|
|
548
|
+
special_chars += "();<>|&!`$*?[]{} \t\n\"'"
|
|
531
549
|
elif cword_prequote == '"':
|
|
532
550
|
special_chars += '"`$!'
|
|
533
551
|
|
|
@@ -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:
|
|
@@ -19,7 +19,13 @@ from argparse import (
|
|
|
19
19
|
_SubParsersAction,
|
|
20
20
|
)
|
|
21
21
|
from gettext import gettext
|
|
22
|
-
from typing import Dict, List, Set, Tuple
|
|
22
|
+
from typing import Dict, List, Optional, Set, Tuple, Union, cast
|
|
23
|
+
|
|
24
|
+
_OptionTuple = Union[
|
|
25
|
+
Tuple[Optional[Action], str, Optional[str]],
|
|
26
|
+
Tuple[Optional[Action], str, Optional[str], Optional[str]],
|
|
27
|
+
]
|
|
28
|
+
_OptionTupleEntry = Union[_OptionTuple, List[_OptionTuple]]
|
|
23
29
|
|
|
24
30
|
_num_consumed_args: Dict[Action, int] = {}
|
|
25
31
|
|
|
@@ -97,7 +103,7 @@ class IntrospectiveArgumentParser(ArgumentParser):
|
|
|
97
103
|
# find all option indices, and determine the arg_string_pattern
|
|
98
104
|
# which has an 'O' if there is an option at an index,
|
|
99
105
|
# an 'A' if there is an argument, or a '-' if there is a '--'
|
|
100
|
-
option_string_indices = {}
|
|
106
|
+
option_string_indices: Dict[int, _OptionTupleEntry] = {}
|
|
101
107
|
arg_string_pattern_parts = []
|
|
102
108
|
arg_strings_iter = iter(arg_strings)
|
|
103
109
|
for i, arg_string in enumerate(arg_strings_iter):
|
|
@@ -114,7 +120,7 @@ class IntrospectiveArgumentParser(ArgumentParser):
|
|
|
114
120
|
if option_tuple is None:
|
|
115
121
|
pattern = 'A'
|
|
116
122
|
else:
|
|
117
|
-
option_string_indices[i] = option_tuple
|
|
123
|
+
option_string_indices[i] = cast(_OptionTupleEntry, option_tuple)
|
|
118
124
|
pattern = 'O'
|
|
119
125
|
arg_string_pattern_parts.append(pattern)
|
|
120
126
|
|
|
@@ -161,9 +167,11 @@ class IntrospectiveArgumentParser(ArgumentParser):
|
|
|
161
167
|
# function to convert arg_strings into an optional action
|
|
162
168
|
def consume_optional(start_index):
|
|
163
169
|
# get the optional identified at this index
|
|
164
|
-
|
|
165
|
-
if isinstance(
|
|
166
|
-
option_tuple =
|
|
170
|
+
raw_option_tuple = option_string_indices[start_index]
|
|
171
|
+
if isinstance(raw_option_tuple, list): # Python 3.12.7+
|
|
172
|
+
option_tuple = raw_option_tuple[0]
|
|
173
|
+
else:
|
|
174
|
+
option_tuple = raw_option_tuple
|
|
167
175
|
if len(option_tuple) == 3:
|
|
168
176
|
action, option_string, explicit_arg = option_tuple
|
|
169
177
|
else: # Python 3.11.9+, 3.12.3+, 3.13+
|
|
@@ -241,8 +249,8 @@ class IntrospectiveArgumentParser(ArgumentParser):
|
|
|
241
249
|
# add the Optional to the list and return the index at which
|
|
242
250
|
# the Optional's string args stopped
|
|
243
251
|
assert action_tuples
|
|
244
|
-
for
|
|
245
|
-
take_action(
|
|
252
|
+
for optional_action, args, option_string in action_tuples:
|
|
253
|
+
take_action(optional_action, args, option_string)
|
|
246
254
|
return stop
|
|
247
255
|
|
|
248
256
|
# the list of Positionals left to be parsed; this is modified
|
{argcomplete-3.6.3 → 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
|
|
|
@@ -15,12 +15,12 @@ classifiers = [
|
|
|
15
15
|
"Operating System :: POSIX",
|
|
16
16
|
"Programming Language :: Python",
|
|
17
17
|
"Programming Language :: Python :: 3",
|
|
18
|
-
"Programming Language :: Python :: 3.8",
|
|
19
18
|
"Programming Language :: Python :: 3.9",
|
|
20
19
|
"Programming Language :: Python :: 3.10",
|
|
21
20
|
"Programming Language :: Python :: 3.11",
|
|
22
21
|
"Programming Language :: Python :: 3.12",
|
|
23
22
|
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
24
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
25
25
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
26
26
|
"Development Status :: 5 - Production/Stable",
|
|
@@ -32,7 +32,6 @@ classifiers = [
|
|
|
32
32
|
|
|
33
33
|
[project.scripts]
|
|
34
34
|
activate-global-python-argcomplete = "argcomplete.scripts.activate_global_python_argcomplete:main"
|
|
35
|
-
python-argcomplete-check-easy-install-script = "argcomplete.scripts.python_argcomplete_check_easy_install_script:main"
|
|
36
35
|
register-python-argcomplete = "argcomplete.scripts.register_python_argcomplete:main"
|
|
37
36
|
|
|
38
37
|
[project.optional-dependencies]
|
|
@@ -356,6 +356,15 @@ class TestArgcomplete(unittest.TestCase):
|
|
|
356
356
|
fp.write("test")
|
|
357
357
|
self.assertEqual(set(fc("a")), set(["abcdefж/", "abcaha/", "abcxyz"]))
|
|
358
358
|
|
|
359
|
+
def test_file_completion_quotes_prefix(self):
|
|
360
|
+
with TempDir(prefix="test_dir_fc_quote", dir="."):
|
|
361
|
+
marker = "should_not_exist"
|
|
362
|
+
prefix = "'; touch {0}; echo '".format(marker)
|
|
363
|
+
|
|
364
|
+
self.assertFalse(os.path.exists(marker))
|
|
365
|
+
self.assertEqual(FilesCompleter()(prefix), [])
|
|
366
|
+
self.assertFalse(os.path.exists(marker))
|
|
367
|
+
|
|
359
368
|
def test_filescompleter_filetype_integration(self):
|
|
360
369
|
def make_parser():
|
|
361
370
|
parser = ArgumentParser()
|
|
@@ -405,6 +414,44 @@ class TestArgcomplete(unittest.TestCase):
|
|
|
405
414
|
self.assertEqual(c("def/k"), set([]))
|
|
406
415
|
return
|
|
407
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
|
+
|
|
408
455
|
def test_default_completer(self):
|
|
409
456
|
def make_parser():
|
|
410
457
|
parser = ArgumentParser(add_help=False)
|
|
@@ -828,6 +875,7 @@ class TestArgcomplete(unittest.TestCase):
|
|
|
828
875
|
parser.add_argument("-1", choices=["bar<$>baz"])
|
|
829
876
|
parser.add_argument("-2", choices=[r"\* "])
|
|
830
877
|
parser.add_argument("-3", choices=["\"'"])
|
|
878
|
+
parser.add_argument("-4", choices=["data?", "file[1]", "{x,--flag}"])
|
|
831
879
|
return parser
|
|
832
880
|
|
|
833
881
|
self.assertEqual(set(self.run_completer(make_parser(), "prog -1 ")), {r"bar\<\$\>baz "})
|
|
@@ -835,6 +883,10 @@ class TestArgcomplete(unittest.TestCase):
|
|
|
835
883
|
self.assertEqual(set(self.run_completer(make_parser(), "prog -3 ")), {r"\"\' "})
|
|
836
884
|
self.assertEqual(set(self.run_completer(make_parser(), 'prog -3 "')), {r"\"'"})
|
|
837
885
|
self.assertEqual(set(self.run_completer(make_parser(), "prog -3 '")), {"\"'\\''"})
|
|
886
|
+
self.assertEqual(
|
|
887
|
+
set(self.run_completer(make_parser(), "prog -4 ")),
|
|
888
|
+
{r"data\?", r"file\[1\]", r"\{x,--flag\}"},
|
|
889
|
+
)
|
|
838
890
|
|
|
839
891
|
self.assertEqual(set(self.run_completer(make_parser(), "prog -1 ", shell="tcsh")), {"bar<$>baz "})
|
|
840
892
|
# The trailing space won't actually work correctly in tcsh.
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
# Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors.
|
|
4
|
-
# Licensed under the Apache License. See https://github.com/kislyuk/argcomplete for more info.
|
|
5
|
-
|
|
6
|
-
"""
|
|
7
|
-
This script is part of the Python argcomplete package (https://github.com/kislyuk/argcomplete).
|
|
8
|
-
It is used to check if an EASY-INSTALL-SCRIPT wrapper redirects to a script that contains the string
|
|
9
|
-
"PYTHON_ARGCOMPLETE_OK". If you have enabled global completion in argcomplete, the completion hook will run it every
|
|
10
|
-
time you press <TAB> in your shell.
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
python-argcomplete-check-easy-install-script <input executable file>
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
import sys
|
|
17
|
-
|
|
18
|
-
# PEP 366
|
|
19
|
-
__package__ = "argcomplete.scripts"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def main():
|
|
23
|
-
if len(sys.argv) != 2:
|
|
24
|
-
sys.exit(__doc__)
|
|
25
|
-
|
|
26
|
-
sys.tracebacklimit = 0
|
|
27
|
-
|
|
28
|
-
with open(sys.argv[1]) as fh:
|
|
29
|
-
line1, head = fh.read(1024).split("\n", 1)[:2]
|
|
30
|
-
if line1.startswith("#") and ("py" in line1 or "Py" in line1):
|
|
31
|
-
import re
|
|
32
|
-
|
|
33
|
-
lines = head.split("\n", 12)
|
|
34
|
-
for line in lines:
|
|
35
|
-
if line.startswith("# EASY-INSTALL-SCRIPT"):
|
|
36
|
-
import pkg_resources # type: ignore
|
|
37
|
-
|
|
38
|
-
re_match = re.match("# EASY-INSTALL-SCRIPT: '(.+)','(.+)'", line)
|
|
39
|
-
assert re_match is not None
|
|
40
|
-
dist, script = re_match.groups()
|
|
41
|
-
if "PYTHON_ARGCOMPLETE_OK" in pkg_resources.get_distribution(dist).get_metadata(
|
|
42
|
-
"scripts/" + script
|
|
43
|
-
):
|
|
44
|
-
return 0
|
|
45
|
-
elif line.startswith("# EASY-INSTALL-ENTRY-SCRIPT"):
|
|
46
|
-
re_match = re.match("# EASY-INSTALL-ENTRY-SCRIPT: '(.+)','(.+)','(.+)'", line)
|
|
47
|
-
assert re_match is not None
|
|
48
|
-
dist, group, name = re_match.groups()
|
|
49
|
-
import pkgutil
|
|
50
|
-
|
|
51
|
-
import pkg_resources # type: ignore
|
|
52
|
-
|
|
53
|
-
entry_point_info = pkg_resources.get_distribution(dist).get_entry_info(group, name)
|
|
54
|
-
assert entry_point_info is not None
|
|
55
|
-
module_name = entry_point_info.module_name
|
|
56
|
-
with open(pkgutil.get_loader(module_name).get_filename()) as mod_fh: # type: ignore
|
|
57
|
-
if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
|
|
58
|
-
return 0
|
|
59
|
-
elif line.startswith("# EASY-INSTALL-DEV-SCRIPT"):
|
|
60
|
-
for line2 in lines:
|
|
61
|
-
if line2.startswith("__file__"):
|
|
62
|
-
re_match = re.match("__file__ = '(.+)'", line2)
|
|
63
|
-
assert re_match is not None
|
|
64
|
-
filename = re_match.group(1)
|
|
65
|
-
with open(filename) as mod_fh:
|
|
66
|
-
if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
|
|
67
|
-
return 0
|
|
68
|
-
elif line.startswith("# PBR Generated"):
|
|
69
|
-
re_match = re.search("from (.*) import", head)
|
|
70
|
-
assert re_match is not None
|
|
71
|
-
module = re_match.groups()[0]
|
|
72
|
-
import pkgutil
|
|
73
|
-
|
|
74
|
-
import pkg_resources # type: ignore
|
|
75
|
-
|
|
76
|
-
with open(pkgutil.get_loader(module).get_filename()) as mod_fh: # type: ignore
|
|
77
|
-
if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
|
|
78
|
-
return 0
|
|
79
|
-
|
|
80
|
-
return 1
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if __name__ == "__main__":
|
|
84
|
-
sys.exit(main())
|
|
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
|