from textwrap import dedentkernel
The latest documentation for implementing a wrapper kernel is here, but the current code deviates from those instructions (which call for inheriting from kernelbase.Kernel), instead inheriting from the IPython kernel implementation, IPythonKernel.
For a diagram of the main dependencies among the principal nbstata modules, click here.
PyStataKernel
def PyStataKernel(
kwargs:VAR_KEYWORD
):
A jupyter kernel based on pystata
Config and Stata initialization
Stata is initialized during the execution of the first cell (in PyStataKernel.do_execute below) so that any configuration errors can be displayed in the notebook.
PyStataKernel.init_session
def init_session(
):
Stata code execution (and error display)
print_stata_error
def print_stata_error(
text
):
print_stata_error(dedent("""\
output prior to error
error message
error code
"""))output prior to error
error message
error code
_user_expressions({"1": "5 + 1"}){'1': {'status': 'ok', 'data': {'text/plain': '6'}, 'metadata': {}}}
_user_expressions({"1": "sam"})sam not found
Invalid Stata '[%fmt] [=]exp' display expression: sam
{'1': {'status': 'error',
'traceback': [],
'ename': 'Stata user expression error',
'evalue': "sam not found\n\nInvalid Stata '[%fmt] [=]exp' display expression: sam"}}
PyStataKernel.post_do_hook
def post_do_hook(
):
PyStataKernel.do_execute
def do_execute(
code, silent, store_history:bool=True, user_expressions:NoneType=None, allow_stdin:bool=False
):
Execute Stata code cell
Other kernel capabilities
PyStataKernel.do_inspect
def do_inspect(
code, cursor_pos, detail_level:int=0, omit_sections:tuple=()
):
Display Stata ‘describe’ output (regardless of cursor position)
PyStataKernel.do_complete
def do_complete(
code, cursor_pos
):
Provide context-aware tab-autocomplete suggestions
PyStataKernel.do_is_complete
def do_is_complete(
code
):
Overrides IPythonKernel with kernelbase default
PyStataKernel.do_history
def do_history(
hist_access_type, output, raw, session:NoneType=None, start:NoneType=None, stop:NoneType=None, n:NoneType=None,
pattern:NoneType=None, unique:bool=False
):
Overrides IPythonKernel with kernelbase default