Reputation: 2689
We're planning on using iPython and/or Jupyter notebooks for an interactive environment to interface with our DUT (device under test).
There will be classes created, etc. to interact with the DUT, but some of the functions take "many" parameters. I'd like to be able to help our users by enhancing tab-completion to:
DUT.< tab >
DUT.a < tab >
DUT.activate( < tab >
DUT.activate( A< tab >
DUT.activate( 1, ACTUATOR=< tab >
I know this question is open ended, but google doesn't seem to find any examples on point or worse, doesn't say if it's the "right" way to do it or not. All of the keywords I can come up with don't really narrow down the search to anything on topic.
I've seen ipython.set_hook('complete_command',...)
, but I can't really find any documentation on it.
Honestly, I'd hope there was a way to decorate/document my classes so it could just be sucked up from the docstring, that would be the most awesome, but I can do that if I know how I'm supposed to hook into the tab completion.
Bonus points if I can get it to work under the standard intellisense stuff in VSCODE (so much of the behavior is available in both writing scripts and interactively).
Or am I being too ambitious here?
Upvotes: 0
Views: 722
Reputation: 76
It's indeed an open ended question. My suggestions and comments:
The iPython shell automatically does tab completion if you instantiate an object. But it also shows all magic keywords for inspection and for python.
You can also look at the Python docstring functionality. With it you can call the internal help()
function on the class, and it will spit out the documentation. e.g.:
In [7]: class A(object):
...: def __init__(self):
...: self.a = 1
...: self.autostart = 'b'
...: def activate(aa, ab, actuator):
...: """
...: function to activate the DUT
...: :param aa: first parameter
...: :param ab: second parameter
...: :param actuator: actuator param
...: :returns: None
...: """
...: print(aa, ab, actuator)
...:
In [8]: a = A()
In [9]: help(A)
Help on class A in module __main__:
class A(__builtin__.object)
| Methods defined here:
|
| __init__(self)
|
| activate(aa, ab, actuator)
| function to activate the DUT
| :param aa: first parameter
| :param ab: second parameter
| :param actuator: actuator param
| :returns: None
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
In [10]:
With this docstring you can also generate automatic documentation. For example the module sphinx supports different output formats: pdf, html, ...
VS code, intellisense can also understand the docstring. Although the caveat there is that it does not seem to support the mainstream formats.
For Jupyter notebooks, there is also a plugin you can install similar to intellisense, called Kite (Copilot)
Upvotes: 1