Skip to contentSkip to conversation

Support python argcomplete

PATCH In review Jason Gunthorpe 2 participants 3 messages Aug 7 – Aug 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support python argcomplete

argcomplete is a alternative to shtab. While shtab provides an option to generate unique matching patterns for each program, argcomplete has a general completion hook that identifies compatible programs and dynamically pulls the completion out of the program itself.

This means that once argcomplete is enabled in the shell every compatible program automatically and effortlessly gets full shell completions that are perfectly up to date with the active version. When running out of a git check out this is a big improvement over shtab since completions Just Work with no need to specially manage the shtab files.

The boilerplate is setup so the argcomplete module is optional, if the user has it installed (and presumably enabled it for their shell) then it is activated.

---
 b4.sh             | 1 +
 src/b4/command.py | 7 +++++++
 2 files changed, 8 insertions(+)
b4.sh +1 -0
index e3fbb100be0f98..e47c5b68dbe6da 100755
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+# PYTHON_ARGCOMPLETE_OK
 #
 # Run b4 from a git checkout.
 #
src/b4/command.py +7 -0
index 8a8c96f635af67..803ed333346372 100644
@@ -1,4 +1,5 @@
 #!/usr/bin/env python3
+# PYTHON_ARGCOMPLETE_OK
 # -*- coding: utf-8 -*-
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (C) 2020 by the Linux Foundation
@@ -1331,6 +1332,12 @@ def setup_parser() -> argparse.ArgumentParser:
 
 def cmd() -> None:
     parser = setup_parser()
+    try:
+        import argcomplete
+        argcomplete.autocomplete(parser)
+    except ImportError:
+        pass
+
     cmdargs = parser.parse_args()
     logger.setLevel(logging.DEBUG)
 

base-commit: 362b87aa4d036884c36e4bfb9cdbdee626aba3bf

Signature · 1 line
2.43.0
#1 lore raw
Quoted 1 line · Jason Gunthorpe

Support python argcomplete

I've applied it, but note that this immediately fails ci.sh. I'll fix it up as a follow-up.

[1/1] Support python argcomplete

      commit: f6b44c86c5c7b26f0979fe56ad76c40df11b9ccb

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>
#2 lore raw
Quoted 6 lines · Konstantin Ryabitsev
Quoted 1 line · Jason Gunthorpe

Support python argcomplete

I've applied it, but note that this immediately fails ci.sh. I'll fix it up as a follow-up.

Thanks I had not discovered that! I will try it in future.

FWIW I am trying to use the b4 review to organize my unmanagable pile of patches to look at. It seems very promising, though I have a small list of pain points I may write up or try and fix :)

Jason