argcomplete 3.7.2__tar.gz → 3.8.0__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.
Files changed (54) hide show
  1. {argcomplete-3.7.2 → argcomplete-3.8.0}/.github/workflows/ci.yml +1 -1
  2. argcomplete-3.8.0/AGENTS.md +5 -0
  3. {argcomplete-3.7.2 → argcomplete-3.8.0}/Changes.rst +20 -0
  4. {argcomplete-3.7.2 → argcomplete-3.8.0}/PKG-INFO +19 -15
  5. {argcomplete-3.7.2 → argcomplete-3.8.0}/README.rst +17 -13
  6. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/__init__.py +5 -0
  7. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/_check_console_script.py +5 -3
  8. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/_check_module.py +4 -2
  9. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/bash_completion.d/_python-argcomplete +8 -0
  10. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/completers.py +18 -15
  11. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/exceptions.py +3 -0
  12. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/finders.py +111 -64
  13. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/io.py +2 -0
  14. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/lexers.py +11 -5
  15. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/packages/_argparse.py +65 -23
  16. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/packages/_shlex.py +10 -6
  17. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/scripts/activate_global_python_argcomplete.py +9 -5
  18. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/scripts/register_python_argcomplete.py +2 -0
  19. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/shell_integration.py +30 -18
  20. {argcomplete-3.7.2 → argcomplete-3.8.0}/docs/conf.py +2 -0
  21. {argcomplete-3.7.2 → argcomplete-3.8.0}/docs/examples/describe_github_user.py +4 -2
  22. {argcomplete-3.7.2 → argcomplete-3.8.0}/pyproject.toml +13 -0
  23. argcomplete-3.8.0/test/powershell_prog.py +16 -0
  24. argcomplete-3.8.0/test/powershell_quoting.ps1 +50 -0
  25. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/prog +3 -0
  26. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/test.py +433 -52
  27. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/test_contrib_shells.py +6 -5
  28. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/test_package/setup.py +2 -0
  29. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/test_package/test_module.py +2 -0
  30. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/test_package/test_package/__init__.py +3 -0
  31. argcomplete-3.8.0/test/test_powershell.py +141 -0
  32. {argcomplete-3.7.2 → argcomplete-3.8.0}/.github/FUNDING.yml +0 -0
  33. {argcomplete-3.7.2 → argcomplete-3.8.0}/.github/workflows/release.yml +0 -0
  34. {argcomplete-3.7.2 → argcomplete-3.8.0}/.gitignore +0 -0
  35. {argcomplete-3.7.2 → argcomplete-3.8.0}/Authors.rst +0 -0
  36. {argcomplete-3.7.2 → argcomplete-3.8.0}/LICENSE.rst +0 -0
  37. {argcomplete-3.7.2 → argcomplete-3.8.0}/MANIFEST.in +0 -0
  38. {argcomplete-3.7.2 → argcomplete-3.8.0}/Makefile +0 -0
  39. {argcomplete-3.7.2 → argcomplete-3.8.0}/NOTICE +0 -0
  40. {argcomplete-3.7.2 → argcomplete-3.8.0}/SECURITY.md +0 -0
  41. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/packages/__init__.py +0 -0
  42. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/py.typed +0 -0
  43. {argcomplete-3.7.2 → argcomplete-3.8.0}/argcomplete/scripts/__init__.py +0 -0
  44. {argcomplete-3.7.2 → argcomplete-3.8.0}/common.mk +0 -0
  45. {argcomplete-3.7.2 → argcomplete-3.8.0}/contrib/README.rst +0 -0
  46. {argcomplete-3.7.2 → argcomplete-3.8.0}/docs/changelog.rst +0 -0
  47. {argcomplete-3.7.2 → argcomplete-3.8.0}/docs/fish_help_string.png +0 -0
  48. {argcomplete-3.7.2 → argcomplete-3.8.0}/docs/index.rst +0 -0
  49. {argcomplete-3.7.2 → argcomplete-3.8.0}/docs/toc.html +0 -0
  50. {argcomplete-3.7.2 → argcomplete-3.8.0}/setup.cfg +0 -0
  51. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/__init__.py +0 -0
  52. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/inputrc +0 -0
  53. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/stuck +0 -0
  54. {argcomplete-3.7.2 → argcomplete-3.8.0}/test/test_package/__init__.py +0 -0
@@ -8,7 +8,7 @@ jobs:
8
8
  strategy:
9
9
  fail-fast: false
10
10
  matrix:
11
- os: [ubuntu-22.04, ubuntu-latest, macos-14, macos-latest]
11
+ os: [ubuntu-22.04, ubuntu-latest, macos-15, macos-latest]
12
12
  python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
13
13
 
14
14
  steps:
@@ -0,0 +1,5 @@
1
+ # Project instructions
2
+
3
+ Mark every edit to `argcomplete/packages/_argparse.py` with an `Added by argcomplete` comment so maintainers can identify local changes when comparing the file with upstream `argparse`.
4
+
5
+ Do not use the Python `nonlocal` statement.
@@ -1,3 +1,23 @@
1
+ Changes for v3.8.0 (2026-11-21)
2
+ ===============================
3
+
4
+ - Improve tilde-prefixed completions (#579, #581, #587, #588)
5
+
6
+ - Complete only the suffix of a mid-word Bash quote (#589)
7
+
8
+ - Exclude directories from extension-filtered file completions (#582)
9
+
10
+ - Fix completion of attached option values with pending positionals
11
+ (#586)
12
+
13
+ - Avoid IndexError for empty completion suffixes (#576)
14
+
15
+ - Quote PowerShell completions with native escaping (#573)
16
+
17
+ - Expose consumed argument counts to custom completers (#567, #572)
18
+
19
+ - Neutralize IFS byte in zsh completion descriptions (#566)
20
+
1
21
  Changes for v3.7.2 (2026-08-05)
2
22
  ===============================
3
23
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: argcomplete
3
- Version: 3.7.2
3
+ Version: 3.8.0
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
@@ -150,6 +150,19 @@ way to do this at definition time is:
150
150
  parser.add_argument("--env-var2").completer = EnvironCompleter
151
151
  argcomplete.autocomplete(parser)
152
152
 
153
+ For an action that accepts several values, a completer can call
154
+ ``argcomplete.get_num_consumed_args(action)`` to distinguish their positions.
155
+ For example, the following completes ``--foobar KEY OP NAME`` differently at
156
+ each position, without changing the callable completer signature:
157
+
158
+ .. code-block:: python
159
+
160
+ def complete_foobar(prefix, action, **kwargs):
161
+ choices = (("owner", "status"), ("eq", "ne"), ("alice", "bob"))
162
+ return choices[argcomplete.get_num_consumed_args(action)]
163
+
164
+ parser.add_argument("--foobar", nargs=3).completer = complete_foobar
165
+
153
166
  If you specify the ``choices`` keyword for an argparse option or argument (and don't specify a completer), it will be
154
167
  used for completions.
155
168
 
@@ -265,8 +278,8 @@ multiple Python versions on the same system, the version being used to run the s
265
278
  .. admonition:: Bash version compatibility
266
279
 
267
280
  When using bash, global completion requires bash support for ``complete -D``, which was introduced in bash 4.2. Since
268
- Mac OS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
269
- `Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``/opt/homebrew/bin/bash`` to
281
+ macOS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
282
+ `Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``$(brew --prefix)/bin/bash`` to
270
283
  ``/etc/shells``, and run ``chsh`` to change your shell). You can check the version of the running copy of bash with
271
284
  ``echo $BASH_VERSION``.
272
285
 
@@ -301,7 +314,7 @@ Argcomplete requires Python 3.10+.
301
314
 
302
315
  Support for other shells
303
316
  ------------------------
304
- Argcomplete maintainers provide support only for the bash and zsh shells on Linux and MacOS. For resources related to
317
+ Argcomplete maintainers provide support only for the bash and zsh shells on Linux and macOS. For resources related to
305
318
  other shells and platforms, including fish, tcsh, xonsh, powershell, and Windows, please see the
306
319
  `contrib <https://github.com/kislyuk/argcomplete/tree/develop/contrib>`_ directory.
307
320
 
@@ -339,15 +352,6 @@ Please report bugs, issues, feature requests, etc. on `GitHub <https://github.co
339
352
 
340
353
  License
341
354
  -------
342
- Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors. Licensed under the terms of the
355
+ Copyright 2012-2026, Andrey Kislyuk and argcomplete contributors. Licensed under the terms of the
343
356
  `Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE
344
357
  files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
345
-
346
- .. image:: https://github.com/kislyuk/argcomplete/workflows/Python%20package/badge.svg
347
- :target: https://github.com/kislyuk/argcomplete/actions
348
- .. image:: https://codecov.io/github/kislyuk/argcomplete/coverage.svg?branch=master
349
- :target: https://codecov.io/github/kislyuk/argcomplete?branch=master
350
- .. image:: https://img.shields.io/pypi/v/argcomplete.svg
351
- :target: https://pypi.python.org/pypi/argcomplete
352
- .. image:: https://img.shields.io/pypi/l/argcomplete.svg
353
- :target: https://pypi.python.org/pypi/argcomplete
@@ -106,6 +106,19 @@ way to do this at definition time is:
106
106
  parser.add_argument("--env-var2").completer = EnvironCompleter
107
107
  argcomplete.autocomplete(parser)
108
108
 
109
+ For an action that accepts several values, a completer can call
110
+ ``argcomplete.get_num_consumed_args(action)`` to distinguish their positions.
111
+ For example, the following completes ``--foobar KEY OP NAME`` differently at
112
+ each position, without changing the callable completer signature:
113
+
114
+ .. code-block:: python
115
+
116
+ def complete_foobar(prefix, action, **kwargs):
117
+ choices = (("owner", "status"), ("eq", "ne"), ("alice", "bob"))
118
+ return choices[argcomplete.get_num_consumed_args(action)]
119
+
120
+ parser.add_argument("--foobar", nargs=3).completer = complete_foobar
121
+
109
122
  If you specify the ``choices`` keyword for an argparse option or argument (and don't specify a completer), it will be
110
123
  used for completions.
111
124
 
@@ -221,8 +234,8 @@ multiple Python versions on the same system, the version being used to run the s
221
234
  .. admonition:: Bash version compatibility
222
235
 
223
236
  When using bash, global completion requires bash support for ``complete -D``, which was introduced in bash 4.2. Since
224
- Mac OS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
225
- `Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``/opt/homebrew/bin/bash`` to
237
+ macOS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
238
+ `Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``$(brew --prefix)/bin/bash`` to
226
239
  ``/etc/shells``, and run ``chsh`` to change your shell). You can check the version of the running copy of bash with
227
240
  ``echo $BASH_VERSION``.
228
241
 
@@ -257,7 +270,7 @@ Argcomplete requires Python 3.10+.
257
270
 
258
271
  Support for other shells
259
272
  ------------------------
260
- Argcomplete maintainers provide support only for the bash and zsh shells on Linux and MacOS. For resources related to
273
+ Argcomplete maintainers provide support only for the bash and zsh shells on Linux and macOS. For resources related to
261
274
  other shells and platforms, including fish, tcsh, xonsh, powershell, and Windows, please see the
262
275
  `contrib <https://github.com/kislyuk/argcomplete/tree/develop/contrib>`_ directory.
263
276
 
@@ -295,15 +308,6 @@ Please report bugs, issues, feature requests, etc. on `GitHub <https://github.co
295
308
 
296
309
  License
297
310
  -------
298
- Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors. Licensed under the terms of the
311
+ Copyright 2012-2026, Andrey Kislyuk and argcomplete contributors. Licensed under the terms of the
299
312
  `Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE
300
313
  files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
301
-
302
- .. image:: https://github.com/kislyuk/argcomplete/workflows/Python%20package/badge.svg
303
- :target: https://github.com/kislyuk/argcomplete/actions
304
- .. image:: https://codecov.io/github/kislyuk/argcomplete/coverage.svg?branch=master
305
- :target: https://codecov.io/github/kislyuk/argcomplete?branch=master
306
- .. image:: https://img.shields.io/pypi/v/argcomplete.svg
307
- :target: https://pypi.python.org/pypi/argcomplete
308
- .. image:: https://img.shields.io/pypi/l/argcomplete.svg
309
- :target: https://pypi.python.org/pypi/argcomplete
@@ -1,12 +1,17 @@
1
1
  # Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors.
2
2
  # Licensed under the Apache License. See https://github.com/kislyuk/argcomplete for more info.
3
3
 
4
+ # mypy: implicit-reexport=True
5
+
6
+ from __future__ import annotations
7
+
4
8
  from . import completers
5
9
  from .completers import ChoicesCompleter, DirectoriesCompleter, EnvironCompleter, FilesCompleter, SuppressCompleter
6
10
  from .exceptions import ArgcompleteException
7
11
  from .finders import CompletionFinder, ExclusiveCompletionFinder, safe_actions
8
12
  from .io import debug, mute_stderr, warn
9
13
  from .lexers import split_line
14
+ from .packages._argparse import get_num_consumed_args
10
15
  from .shell_integration import shellcode
11
16
 
12
17
  autocomplete: CompletionFinder = CompletionFinder()
@@ -12,11 +12,13 @@ https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-cre
12
12
  Intended to be invoked by argcomplete's global completion function.
13
13
  """
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  import os
16
18
  import sys
19
+ from collections.abc import Iterable
17
20
  from importlib.metadata import EntryPoint
18
21
  from importlib.metadata import entry_points as importlib_entry_points
19
- from typing import Iterable
20
22
 
21
23
  from ._check_module import ArgcompleteMarkerNotFound, find
22
24
 
@@ -46,9 +48,9 @@ def main():
46
48
  # Check this looks like the script we really expected.
47
49
  with open(script_path) as f:
48
50
  script = f.read()
49
- if "from {} import {}".format(module_name, function_name) not in script:
51
+ if f"from {module_name} import {function_name}" not in script:
50
52
  raise ArgcompleteMarkerNotFound("does not appear to be a console script")
51
- if "sys.exit({}())".format(function_name) not in script:
53
+ if f"sys.exit({function_name}())" not in script:
52
54
  raise ArgcompleteMarkerNotFound("does not appear to be a console script")
53
55
 
54
56
  # Look for the argcomplete marker in the script it imports.
@@ -7,6 +7,8 @@ The module name should be specified in a form usable with `python -m`.
7
7
  Intended to be invoked by argcomplete's global completion function.
8
8
  """
9
9
 
10
+ from __future__ import annotations
11
+
10
12
  import os
11
13
  import sys
12
14
  import tokenize
@@ -26,12 +28,12 @@ def find(name, return_package=False):
26
28
  break
27
29
 
28
30
  if spec is None:
29
- raise ArgcompleteMarkerNotFound('no module named "{}"'.format(names[0]))
31
+ raise ArgcompleteMarkerNotFound(f'no module named "{names[0]}"')
30
32
  if not spec.has_location:
31
33
  raise ArgcompleteMarkerNotFound("cannot locate file")
32
34
  if spec.submodule_search_locations is None:
33
35
  if len(names) != 1:
34
- raise ArgcompleteMarkerNotFound("{} is not a package".format(names[0]))
36
+ raise ArgcompleteMarkerNotFound(f"{names[0]} is not a package")
35
37
  return spec.origin
36
38
  if len(spec.submodule_search_locations) != 1:
37
39
  raise ArgcompleteMarkerNotFound("expecting one search location")
@@ -212,6 +212,14 @@ _python_argcomplete_global() {
212
212
  _ARGCOMPLETE_SHELL="zsh" \
213
213
  _ARGCOMPLETE_SUPPRESS_SPACE=1 \
214
214
  __python_argcomplete_run "$executable" "${(@)req_argv[1, ${ARGCOMPLETE}-1]}"))
215
+ # Keep the typed tilde in the word and let _describe quote the rest.
216
+ local tilde_prefix='~'
217
+ [[ $PREFIX != '~'* && $PREFIX == *'=~'* ]] && tilde_prefix="${PREFIX%%=*}=~"
218
+ if [[ -z ${compstate[quote]} && $PREFIX == "$tilde_prefix"* && ${words[CURRENT]} == "$tilde_prefix"* &&
219
+ -z "${completions[@]:#"$tilde_prefix"*}" ]]; then
220
+ compset -p "${#tilde_prefix}"
221
+ completions=("${completions[@]#"$tilde_prefix"}")
222
+ fi
215
223
  local nosort=()
216
224
  local nospace=()
217
225
  if is-at-least 5.8; then
@@ -1,10 +1,12 @@
1
1
  # Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors.
2
2
  # Licensed under the Apache License. See https://github.com/kislyuk/argcomplete for more info.
3
3
 
4
+ from __future__ import annotations
5
+
4
6
  import argparse
5
7
  import os
6
8
  import subprocess
7
- from collections.abc import Callable, Generator, Iterable, Mapping
9
+ from collections.abc import Callable, Generator, Iterable
8
10
  from shlex import quote
9
11
  from typing import Final
10
12
 
@@ -32,12 +34,12 @@ class BaseCompleter:
32
34
 
33
35
 
34
36
  class ChoicesCompleter(BaseCompleter):
35
- choices: Final[Mapping[str, str | bytes]]
37
+ choices: Final[Iterable[object]]
36
38
 
37
- def __init__(self, choices: Mapping[str, str | bytes]) -> None:
39
+ def __init__(self, choices: Iterable[object]) -> None:
38
40
  self.choices = choices
39
41
 
40
- def _convert(self, choice):
42
+ def _convert(self, choice: object) -> str:
41
43
  if not isinstance(choice, str):
42
44
  choice = str(choice)
43
45
  return choice
@@ -74,21 +76,20 @@ class FilesCompleter(BaseCompleter):
74
76
  # correctly in older versions and calling bind makes them available. For details, see
75
77
  # https://savannah.gnu.org/support/index.php?111125
76
78
  files = _call(
77
- ["bash", "-c", "bind; compgen -A directory -- {p}".format(p=quote(prefix))],
79
+ ["bash", "-c", f"bind; compgen -A directory -- {quote(prefix)}"],
78
80
  stderr=subprocess.DEVNULL,
79
81
  )
80
82
  completion += [f + "/" for f in files]
81
83
  for x in self.allowednames:
82
- completion += _call(
83
- ["bash", "-c", "bind; compgen -A file -X '!*.{0}' -- {p}".format(x, p=quote(prefix))],
84
+ files = _call(
85
+ ["bash", "-c", f"bind; compgen -A file -X '!*.{x}' -- {quote(prefix)}"],
84
86
  stderr=subprocess.DEVNULL,
85
87
  )
88
+ completion += [f for f in files if not os.path.isdir(os.path.expanduser(f))]
86
89
  else:
87
- completion += _call(
88
- ["bash", "-c", "bind; compgen -A file -- {p}".format(p=quote(prefix))], stderr=subprocess.DEVNULL
89
- )
90
+ completion += _call(["bash", "-c", f"bind; compgen -A file -- {quote(prefix)}"], stderr=subprocess.DEVNULL)
90
91
  anticomp = _call(
91
- ["bash", "-c", "bind; compgen -A directory -- {p}".format(p=quote(prefix))],
92
+ ["bash", "-c", f"bind; compgen -A directory -- {quote(prefix)}"],
92
93
  stderr=subprocess.DEVNULL,
93
94
  )
94
95
  completion = list(set(completion) - set(anticomp))
@@ -115,15 +116,16 @@ class _FilteredFilesCompleter(BaseCompleter):
115
116
  """
116
117
  Provide completions on prefix
117
118
  """
119
+ prefix_dir = os.path.dirname(prefix)
118
120
  # Expand a leading "~" so that filesystem operations below work on a
119
121
  # real path (os.listdir("~") would otherwise raise FileNotFoundError).
120
- expanded_prefix = os.path.expanduser(prefix)
121
- target_dir = os.path.dirname(expanded_prefix)
122
+ # The completions keep the directory as typed, so that they still start with the prefix.
123
+ target_dir = os.path.expanduser(prefix_dir)
122
124
  try:
123
125
  names = os.listdir(target_dir or ".")
124
126
  except Exception:
125
127
  return # empty iterator
126
- incomplete_part = os.path.basename(expanded_prefix)
128
+ incomplete_part = os.path.basename(prefix)
127
129
  # Iterate on target_dir entries and filter on given predicate
128
130
  for name in names:
129
131
  if not name.startswith(incomplete_part):
@@ -131,7 +133,8 @@ class _FilteredFilesCompleter(BaseCompleter):
131
133
  candidate = os.path.join(target_dir, name)
132
134
  if not self.predicate(candidate):
133
135
  continue
134
- yield candidate + "/" if os.path.isdir(candidate) else candidate
136
+ completion = os.path.join(prefix_dir, name)
137
+ yield completion + "/" if os.path.isdir(candidate) else completion
135
138
 
136
139
 
137
140
  class DirectoriesCompleter(_FilteredFilesCompleter):
@@ -1,2 +1,5 @@
1
+ from __future__ import annotations
2
+
3
+
1
4
  class ArgcompleteException(Exception):
2
5
  "Exception raised when the shell argument completion process fails."