Metakernel magics with TAB completion
Project description
Boosted Magics
Python package that extends the magics of metakernel to provide TAB completion (complete_request messages) on arguments of the magic.
Supports :
- argument name completion
- argument value completion, with custom
completerfunction- parsing of magic command line with argparse
pip install boosted-magics
Creating a Boosted Magic
Boosted Magic subclasses Metakernel Magic, so the magic declaration is the same. To have argument completion, you have to replace @option decorator of Magic with a @boosted_option, as below :
from boosted_magics import boosted_option, BoostedMagic
class ExampleMagic(BoostedMagic):
@boosted_option(
"--very_long_option",
"-o",
default=None,
help="This is a very long option name",
)
@boosted_option(
"--an_other_option_but_which_is_a_flag",
default=None,
action="store_true",
help="This is an other option",
)
@boosted_option(
"-a",
"--an_option_with_custom_completion_method",
help="An option with custom completion method",
completer=lambda w, r: ["customa1", "customa2"],
)
def line_example(
self,
very_long_option,
an_other_option_but_which_is_a_flag,
an_option_with_custom_completion_method,
):
"""
%example : try the boosted magic completion
"""
self.kernel: TestKernel
self.kernel.Print(
f"Example magic successfully called, with args :\n• very_long_option : {very_long_option}\n• an_other_option : {an_other_option_but_which_is_a_flag}\n• an_option_with_custom_completion_method : {an_option_with_custom_completion_method}"
)
def register_magics(kernel) -> None:
kernel.register_magics(ExampleMagic)
The boosted_option uses argparse under the hood for parsing (replacing optparse of metakernel), at command execution time. Hence, any parameter that you would give to an argparse argument will work for a boosted_option.
This allows flags (
action='store_true'), ...
For argument completion, boosted_magics uses statikomand, a custom package that mimics argparse mechanism for uncomplete commands. Completion is then proposed only for arguments that are not present on the command line.
You can create a custom completer function, that will be called just after you added the argument name (see example above). However, you will have to type at least the first letter of the argument value to get completion proposals.
Troubleshooting
TAB completion for magic can be broken (some completion erase all line) with older metakernel versions (before 1.0.4). To fix it, install the 1.0.4 (or above) manually within the project that uses boosted-magics :
uv add "metakernel @ git+https://github.com/Calysto/metakernel.git@afd3ddd"
or without uv:
git clone https://github.com/Calysto/metakernel
cd metakernel
git checkout afd3ddd
pip install -e .
cd ..
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file boosted_magics-0.0.2.tar.gz.
File metadata
- Download URL: boosted_magics-0.0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
334fd7f6a8d36febbcdc6178083b752127958c97e48ac19d0104717e78668c54
|
|
| MD5 |
7592caa8f262aad9851ded43f99ff485
|
|
| BLAKE2b-256 |
14043d1df5ce3c405cc4d8caf703d41dd919ab4d47b68603331b16245afed0f8
|
File details
Details for the file boosted_magics-0.0.2-py3-none-any.whl.
File metadata
- Download URL: boosted_magics-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3c3520cc7a42a191845dfe25eb46eeaba0efcd2454d01e7de93e59c61f7b7f0
|
|
| MD5 |
7f8deb85a51c7301f4270958e751c324
|
|
| BLAKE2b-256 |
4b94410d1729d3b8b770e46bc692bcd04e100edd6bd960cf26a8b067607ab768
|