Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy import the IPython related stuff #504

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Lazy import the IPython related stuff
  • Loading branch information
gaogaotiantian committed Nov 12, 2024
commit 5a8923b20dc593b1e1b97d80d9f4ac069e38d01e
15 changes: 6 additions & 9 deletions src/viztracer/cellmagic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/gaogaotiantian/viztracer/blob/master/NOTICE.txt

try:

def load_ipython_extension(ipython) -> None:
"""
Use `%load_ext viztracer`
Lazy execute the following code because importing IPython is slow
"""
from IPython.core.magic import (Magics, cell_magic, # type: ignore
magics_class, needs_local_scope)
from IPython.core.magic_arguments import (argument, magic_arguments, parse_argstring) # type: ignore
Expand Down Expand Up @@ -62,12 +67,4 @@ def view(): # pragma: no cover

display(button)

except ImportError: # pragma: no cover
pass


def load_ipython_extension(ipython) -> None:
"""
Use `%load_ext viztracer`
"""
ipython.register_magics(VizTracerMagics)
Loading