2021-06-09 22:24:02 +08:00
|
|
|
defmodule Livebook.Runtime.NoopRuntime do
|
|
|
|
# A runtime that doesn't do any actual evaluation,
|
|
|
|
# thus not requiring any underlying resources.
|
|
|
|
|
2023-05-31 05:17:33 +08:00
|
|
|
defstruct [:started, :trace_to]
|
2021-06-09 22:24:02 +08:00
|
|
|
|
2023-05-31 05:17:33 +08:00
|
|
|
def new(trace_to \\ nil) do
|
|
|
|
%__MODULE__{started: false, trace_to: trace_to}
|
2022-04-02 02:13:37 +08:00
|
|
|
end
|
2021-06-09 22:24:02 +08:00
|
|
|
|
|
|
|
defimpl Livebook.Runtime do
|
2022-04-02 02:13:37 +08:00
|
|
|
def describe(_runtime) do
|
|
|
|
[{"Type", "Noop"}]
|
|
|
|
end
|
|
|
|
|
|
|
|
def connect(runtime), do: {:ok, %{runtime | started: true}}
|
|
|
|
def connected?(runtime), do: runtime.started
|
|
|
|
def take_ownership(_, _), do: make_ref()
|
|
|
|
def disconnect(runtime), do: {:ok, %{runtime | started: false}}
|
|
|
|
def duplicate(_), do: Livebook.Runtime.NoopRuntime.new()
|
|
|
|
|
2023-06-02 20:49:06 +08:00
|
|
|
def evaluate_code(_, _, _, _, _, _ \\ []), do: :ok
|
2021-07-16 00:19:36 +08:00
|
|
|
def forget_evaluation(_, _), do: :ok
|
2021-06-09 22:24:02 +08:00
|
|
|
def drop_container(_, _), do: :ok
|
2023-09-28 17:02:04 +08:00
|
|
|
def handle_intellisense(_, _, _, _, _), do: make_ref()
|
2022-02-28 20:53:33 +08:00
|
|
|
|
2023-02-06 22:50:48 +08:00
|
|
|
def read_file(_, path) do
|
|
|
|
case File.read(path) do
|
|
|
|
{:ok, binary} -> {:ok, binary}
|
|
|
|
{:error, reason} -> {:error, "failed to read the file, got: #{inspect(reason)}"}
|
|
|
|
end
|
|
|
|
end
|
2023-02-02 01:49:12 +08:00
|
|
|
|
|
|
|
def transfer_file(_runtime, path, _file_id, callback) do
|
|
|
|
callback.(path)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2023-08-18 04:13:39 +08:00
|
|
|
def relabel_file(_runtime, _file_id, _new_file_id), do: :ok
|
|
|
|
|
2023-05-31 05:17:33 +08:00
|
|
|
def revoke_file(runtime, file_id) do
|
|
|
|
trace(runtime, :revoke_file, [file_id])
|
|
|
|
:ok
|
|
|
|
end
|
2023-01-05 04:44:04 +08:00
|
|
|
|
2022-03-05 20:19:42 +08:00
|
|
|
def start_smart_cell(_, _, _, _, _), do: :ok
|
2022-11-09 21:40:44 +08:00
|
|
|
def set_smart_cell_parent_locators(_, _, _), do: :ok
|
2022-02-28 20:53:33 +08:00
|
|
|
def stop_smart_cell(_, _), do: :ok
|
2022-04-02 02:13:37 +08:00
|
|
|
|
|
|
|
def fixed_dependencies?(_), do: false
|
|
|
|
|
|
|
|
def add_dependencies(_runtime, code, dependencies) do
|
2022-12-03 23:23:43 +08:00
|
|
|
Livebook.Runtime.Dependencies.add_dependencies(code, dependencies)
|
2022-04-02 02:13:37 +08:00
|
|
|
end
|
|
|
|
|
2023-05-09 22:49:02 +08:00
|
|
|
def has_dependencies?(_runtime, _dependencies), do: true
|
|
|
|
|
2023-07-22 02:11:11 +08:00
|
|
|
def snippet_definitions(_runtime) do
|
|
|
|
Livebook.Runtime.Definitions.snippet_definitions()
|
|
|
|
end
|
2023-05-09 22:49:02 +08:00
|
|
|
|
2022-04-30 23:14:10 +08:00
|
|
|
def search_packages(_, _, _), do: make_ref()
|
2022-08-26 04:24:24 +08:00
|
|
|
|
2023-01-03 19:24:22 +08:00
|
|
|
def disable_dependencies_cache(_), do: :ok
|
|
|
|
|
2022-08-26 04:24:24 +08:00
|
|
|
def put_system_envs(_, _), do: :ok
|
2022-09-17 01:22:27 +08:00
|
|
|
def delete_system_envs(_, _), do: :ok
|
2023-05-31 05:17:33 +08:00
|
|
|
|
2024-03-05 13:10:32 +08:00
|
|
|
def restore_transient_state(runtime, transient_state) do
|
|
|
|
trace(runtime, :restore_transient_state, [transient_state])
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2024-03-27 22:25:42 +08:00
|
|
|
def register_clients(_, _), do: :ok
|
|
|
|
def unregister_clients(_, _), do: :ok
|
|
|
|
|
2023-05-31 05:17:33 +08:00
|
|
|
defp trace(runtime, fun, args) do
|
|
|
|
if runtime.trace_to do
|
|
|
|
send(runtime.trace_to, {:runtime_trace, fun, args})
|
|
|
|
end
|
|
|
|
end
|
2021-06-09 22:24:02 +08:00
|
|
|
end
|
|
|
|
end
|