Skip to content

ipython_cell_storage

cleanup_cells()

Remove the temporary directory with all of the files

Source code in lineapy/editors/ipython_cell_storage.py
10
11
12
13
14
15
16
17
def cleanup_cells():
    """
    Remove the temporary directory with all of the files
    """
    global _temp_dir
    if _temp_dir:
        _temp_dir.cleanup()
        _temp_dir = None

get_cell_path(cell)

Return the path to the temporary file for the given cell. This is used for both generating the file and accessing the file.

Source code in lineapy/editors/ipython_cell_storage.py
20
21
22
23
24
25
26
27
28
29
30
31
def get_cell_path(cell: JupyterCell) -> Path:
    """
    Return the path to the temporary file for the given cell.
    This is used for both generating the file and accessing the file.
    """
    global _temp_dir
    if not _temp_dir:
        _temp_dir = TemporaryDirectory("linea_ipython")

    return (
        Path(_temp_dir.name) / f"{cell.session_id}_{cell.execution_count}.py"
    )

get_location_path(location)

Currently, this function is used exclusively for accurate error reporting (e.g., when there is an exception, such as 1/0). Without providing a file path, the errors will show up as "?" in both IPython and CLI executions.

We had add the get_cell_path as a special case because the file location is managed separately by us (not the user provided file path).

Source code in lineapy/editors/ipython_cell_storage.py
34
35
36
37
38
39
40
41
42
43
44
45
46
def get_location_path(location: SourceCodeLocation) -> Path:
    """
    Currently, this function is used exclusively for accurate error reporting
    (e.g., when there is an exception, such as `1/0`).
    Without providing a file path, the errors will show up as "?" in both
    IPython and CLI executions.

    We had add the `get_cell_path` as a special case because the file location
    is managed separately by us (not the user provided file path).
    """
    if isinstance(location, JupyterCell):
        return get_cell_path(location)
    return location

Was this helpful?

Help us improve docs with your feedback!