File: metakernel_python.py

package info (click to toggle)
metakernel 0.27.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,280 kB
  • sloc: python: 5,018; makefile: 207; sh: 27
file content (65 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import print_function

from metakernel import MetaKernel
import sys

class MetaKernelPython(MetaKernel):
    implementation = 'MetaKernel Python'
    implementation_version = '1.0'
    language = 'python'
    language_version = '0.1'
    banner = "MetaKernel Python - evaluates Python statements and expressions"
    language_info = {
        'mimetype': 'text/x-python',
        'name': 'python',
        # ------ If different from 'language':
        # 'codemirror_mode': {
        #    "version": 2,
        #    "name": "ipython"
        # }
        # 'pygments_lexer': 'language',
        # 'version'       : "x.y.z",
        'file_extension': '.py',
        'help_links': MetaKernel.help_links,
    }
    kernel_json = {
        "argv": [
            sys.executable, "-m", "metakernel_python", "-f", "{connection_file}"],
        "display_name": "MetaKernel Python",
        "language": "python",
        "name": "metakernel_python"
    }

    def get_usage(self):
        return ("This is MetaKernel Python. It implements a Python " +
                "interpreter.")

    def set_variable(self, name, value):
        """
        Set a variable in the kernel language.
        """
        python_magic = self.line_magics['python']
        python_magic.env[name] = value

    def get_variable(self, name):
        """
        Get a variable from the kernel language.
        """
        python_magic = self.line_magics['python']
        return python_magic.env.get(name, None)

    def do_execute_direct(self, code):
        python_magic = self.line_magics['python']
        return python_magic.eval(code.strip())

    def get_completions(self, info):
        python_magic = self.line_magics['python']
        return python_magic.get_completions(info)

    def get_kernel_help_on(self, info, level=0, none_on_fail=False):
        python_magic = self.line_magics['python']
        return python_magic.get_help_on(info, level, none_on_fail)


if __name__ == '__main__':
    MetaKernelPython.run_as_main()