Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/singlestoredb/magics/__init__.py
469 views
1
from IPython.core.interactiveshell import InteractiveShell
2
3
from .run_personal import RunPersonalMagic
4
from .run_shared import RunSharedMagic
5
6
# In order to actually use these magics, we must register them with a
7
# running IPython.
8
9
10
def load_ipython_extension(ip: InteractiveShell) -> None:
11
"""
12
Any module file that define a function named `load_ipython_extension`
13
can be loaded via `%load_ext module.path` or be configured to be
14
autoloaded by IPython at startup time.
15
"""
16
17
# Load jupysql extension
18
# This is necessary for jupysql to initialize internal state
19
# required to render messages
20
assert ip.extension_manager is not None
21
result = ip.extension_manager.load_extension('sql')
22
if result == 'no load function':
23
raise RuntimeError('Could not load sql extension. Is jupysql installed?')
24
25
# Check if %run magic command is defined
26
if ip.find_line_magic('run') is None:
27
raise RuntimeError(
28
'%run magic command is not defined. '
29
'Is it available in your IPython environment?',
30
)
31
32
# Register run_personal and run_shared
33
ip.register_magics(RunPersonalMagic(ip))
34
ip.register_magics(RunSharedMagic(ip))
35
36