Skip to content

Commit

Permalink
change method of env check
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeMoussalli committed Jan 31, 2024
1 parent 068ae12 commit c8d543d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ python = ">= 3.8, <3.12"

fsspec = ">= 2023.4.0"
importlib-resources = { version = ">= 1.3", python = "<3.9" }
ipython = ">= 8.21.0"
jsonschema = ">= 4.18"
pyarrow = ">= 11.0.0"
pyyaml = ">= 5.3.1"
Expand Down
15 changes: 10 additions & 5 deletions src/fondant/pipeline/lightweight_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from importlib import metadata

import pyarrow as pa
from IPython import get_ipython
from IPython.core.magics.code import extract_symbols

from fondant.component import BaseComponent, Component
Expand Down Expand Up @@ -287,9 +286,15 @@ def new_getfile(_object, _old_getfile=inspect.getfile):
raise TypeError(msg)


def is_running_in_jupyter():
shell = get_ipython().__class__.__name__
return shell == "ZMQInteractiveShell"
def is_running_in_notebook():
"""Check if the code is running in a Jupyter notebook."""
try:
from IPython import get_ipython

shell = get_ipython().__class__.__name__
return shell == "ZMQInteractiveShell"
except ModuleNotFoundError:
return False


def build_python_script(component_cls: t.Type[Component]) -> str:
Expand All @@ -309,7 +314,7 @@ def build_python_script(component_cls: t.Type[Component]) -> str:
""",
)

if is_running_in_jupyter():
if is_running_in_notebook():
inspect.getfile = new_getfile
component_source = "".join(
inspect.linecache.getlines( # type: ignore[attr-defined]
Expand Down

0 comments on commit c8d543d

Please sign in to comment.