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). This is the reason why metakernel above 1.0.4 is mandatory.
For python 3.11 version, some flag completion might be broken. Consider upgrading to >3.11
Metadata
Release files for boosted-magics 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| boosted_magics-0.1.1.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| boosted_magics-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / boosted_magics-0.1.1.tar.gz
| Download URL | boosted_magics-0.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eca829abac9b87391c641277c2c2bda395f6a3360345a8702e07b414d373987a
|
|
BLAKE2b-256 checksum How to use checksums |
1febbd9308a804b730fa8ea70d526d3fbfabbcd43322f6fd3f381c17ac2c1ca3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Release files / boosted_magics-0.1.1-py3-none-any.whl
| Download URL | boosted_magics-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c1b22583d505e6bb72accf66075e7cb4dabbbe7de045a9a90b895485894b6b7
|
|
BLAKE2b-256 checksum How to use checksums |
d015c0aa324e88637c2b9d5c98ef61144313de91f60dd2a3904f876168c0d71a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|