Skip to content

Commit

Permalink
Merge pull request LineaLabs#564 from LineaLabs/jupyter-cleanup
Browse files Browse the repository at this point in the history
Remove stopping ipython code
  • Loading branch information
saulshanabrook committed Apr 1, 2022
2 parents f9dc48a + 215b0c5 commit 42b090c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 125 deletions.
34 changes: 2 additions & 32 deletions lineapy/editors/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ class CellsExecutedState:
# If set, we should update this display on every cell execution.
visualize_display_handle: Optional[DisplayHandle] = field(default=None)

# This is set to true, if `stop()` is called in the cell
# to signal that at the end of this cell we should stop tracing.
# We don't stop immediately, so we can return the proper value from the cell
should_stop: bool = field(default=False)

def create_visualize_display_object(self) -> DisplayObject:
"""
Returns a jupyter display object for the visualization.
Expand Down Expand Up @@ -158,7 +153,6 @@ def _end_cell() -> object:
res = STATE.tracer.executor.get_value(last_node.id)
else:
res = None
_optionally_stop(STATE)
return res


Expand Down Expand Up @@ -193,36 +187,12 @@ def visualize(*, live=False) -> None:


def stop() -> None:
"""
Tell the tracer to stop after this cell
"""
global STATE

if not STATE:
return

if not isinstance(STATE, CellsExecutedState):
raise RuntimeError("Cannot stop executing if we haven't started yet.")
STATE.should_stop = True


def _optionally_stop(cells_executed_state: CellsExecutedState) -> None:
"""
Stop tracing if the `stop()` was called in the cell and should_stop was set.
"""
global STATE

# If stop was triggered during in this cell, clean up
if not cells_executed_state.should_stop:
return
STATE = None
ipython: InteractiveShell = get_ipython() # type: ignore
ipython.input_transformers_post.remove(input_transformer_post)
cells_executed_state.tracer.db.close()
# Remove the cells we stored
if isinstance(STATE, CellsExecutedState):
STATE.tracer.db.close()
cleanup_cells()
# Reset the exception handling
InteractiveShell._get_exc_info = original_get_exc_info


# Save the original get_exc_info so that we can call it in our custom one
Expand Down
81 changes: 0 additions & 81 deletions tests/notebook/test_stop.ipynb

This file was deleted.

12 changes: 0 additions & 12 deletions tests/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ def test_result(run_cell):
assert run_cell("a") == 10


def test_stop(run_cell):
assert run_cell("import lineapy") is None
assert run_cell("lineapy.editors.ipython.stop()") is None
assert run_cell("10") == 10


def test_stop2(run_cell):
assert run_cell("import lineapy") is None
assert run_cell("lineapy.stop()") is None
assert run_cell("10") == 10


def test_slice(run_cell):
assert run_cell("import lineapy") is None
assert run_cell("a = [1, 2, 3]") is None
Expand Down

0 comments on commit 42b090c

Please sign in to comment.