Refactor aliases

This commit is contained in:
Jonatan Kłosko 2025-02-24 14:46:26 +09:00
parent e7bf517d9f
commit 2846b73c94
42 changed files with 256 additions and 212 deletions

View file

@ -1,7 +1,8 @@
defmodule Livebook.Hubs do
alias Livebook.FileSystem
alias Livebook.Storage
alias Livebook.Hubs.{Broadcasts, Metadata, Personal, Provider, Team}
alias Livebook.Hubs
alias Livebook.Hubs.Provider
alias Livebook.Secrets.Secret
require Logger
@ -28,7 +29,7 @@ defmodule Livebook.Hubs do
@doc """
Gets a list of metadata from storage.
"""
@spec get_metadata() :: list(Metadata.t())
@spec get_metadata() :: list(Hubs.Metadata.t())
def get_metadata do
for hub <- get_hubs() do
Provider.to_metadata(hub)
@ -74,7 +75,7 @@ defmodule Livebook.Hubs do
attributes = Provider.dump(struct)
:ok = connect_hub(struct)
:ok = Storage.insert(@namespace, struct.id, Map.to_list(attributes))
:ok = Broadcasts.hub_changed(struct.id)
:ok = Hubs.Broadcasts.hub_changed(struct.id)
struct
end
@ -88,7 +89,7 @@ defmodule Livebook.Hubs do
true = Provider.type(hub) != "personal"
:ok = maybe_unset_default_hub(hub.id)
:ok = Storage.delete(@namespace, id)
:ok = Broadcasts.hub_deleted(hub.id)
:ok = Hubs.Broadcasts.hub_deleted(hub.id)
:ok = disconnect_hub(hub)
end
@ -115,7 +116,7 @@ defmodule Livebook.Hubs do
{:ok, hub} <- fetch_hub(id) do
hub
else
_ -> fetch_hub!(Personal.id())
_ -> fetch_hub!(Hubs.Personal.id())
end
end
@ -140,11 +141,11 @@ defmodule Livebook.Hubs do
end
defp to_struct(%{id: "personal-" <> _} = fields) do
Provider.load(%Personal{}, fields)
Provider.load(%Hubs.Personal{}, fields)
end
defp to_struct(%{id: "team-" <> _} = fields) do
Provider.load(Team.new(), fields)
Provider.load(Hubs.Team.new(), fields)
end
@doc """

View file

@ -103,7 +103,8 @@ defmodule Livebook.Hubs.Team do
end
defimpl Livebook.Hubs.Provider, for: Livebook.Hubs.Team do
alias Livebook.Hubs.{Team, TeamClient}
alias Livebook.Hubs.Team
alias Livebook.Hubs.TeamClient
alias Livebook.Teams.Requests
alias Livebook.FileSystem
alias Livebook.Secrets.Secret

View file

@ -5,7 +5,7 @@ defmodule Livebook.Intellisense do
# In a way, this provides the very basic features of a language
# server that Livebook uses.
alias Livebook.Intellisense.{IdentifierMatcher, SignatureMatcher, Docs}
alias Livebook.Intellisense
alias Livebook.Runtime
# Configures width used for inspect and specs formatting.
@ -57,7 +57,7 @@ defmodule Livebook.Intellisense do
"""
@spec clear_cache(node()) :: :ok
def clear_cache(node) do
IdentifierMatcher.clear_all_loaded(node)
Intellisense.IdentifierMatcher.clear_all_loaded(node)
end
@doc """
@ -114,7 +114,7 @@ defmodule Livebook.Intellisense do
"""
@spec get_signature_items(String.t(), context(), node()) :: Runtime.signature_response() | nil
def get_signature_items(hint, context, node) do
case SignatureMatcher.get_matching_signatures(hint, context, node) do
case Intellisense.SignatureMatcher.get_matching_signatures(hint, context, node) do
{:ok, [], _active_argument} ->
nil
@ -150,7 +150,7 @@ defmodule Livebook.Intellisense do
"""
@spec get_completion_items(String.t(), context(), node()) :: list(Runtime.completion_item())
def get_completion_items(hint, context, node) do
IdentifierMatcher.completion_identifiers(hint, context, node)
Intellisense.IdentifierMatcher.completion_identifiers(hint, context, node)
|> Enum.filter(&include_in_completion?/1)
|> Enum.map(&format_completion_item/1)
|> Enum.concat(extra_completion_items(hint))
@ -215,7 +215,7 @@ defmodule Livebook.Intellisense do
display_name: display_name,
documentation: documentation
}) do
subtype = Docs.get_module_subtype(module)
subtype = Intellisense.Docs.get_module_subtype(module)
kind =
case subtype do
@ -440,7 +440,7 @@ defmodule Livebook.Intellisense do
Runtime.details_response() | nil
def get_details(line, column, context, node) do
%{matches: matches, range: range} =
IdentifierMatcher.locate_identifier(line, column, context, node)
Intellisense.IdentifierMatcher.locate_identifier(line, column, context, node)
case Enum.filter(matches, &include_in_details?/1) do
[] ->
@ -554,7 +554,8 @@ defmodule Livebook.Intellisense do
path = Path.join(context.ebin_path, "#{module}.beam")
with true <- File.exists?(path),
{:ok, line} <- Docs.locate_definition(String.to_charlist(path), identifier) do
{:ok, line} <-
Intellisense.Docs.locate_definition(String.to_charlist(path), identifier) do
file = module.module_info(:compile)[:source]
%{file: to_string(file), line: line}
else

View file

@ -29,7 +29,9 @@ defmodule Livebook.Notebook do
:deployment_group_id
]
alias Livebook.Notebook.{Section, Cell, AppSettings}
alias Livebook.Notebook
alias Livebook.Notebook.Section
alias Livebook.Notebook.Cell
alias Livebook.FileSystem
alias Livebook.Utils.Graph
import Livebook.Utils, only: [access_by_id: 1]
@ -43,7 +45,7 @@ defmodule Livebook.Notebook do
autosave_interval_s: non_neg_integer() | nil,
default_language: :elixir | :erlang | :python,
output_counter: non_neg_integer(),
app_settings: AppSettings.t(),
app_settings: Notebook.AppSettings.t(),
hub_id: String.t(),
hub_secret_names: list(String.t()),
file_entries: list(file_entry()),
@ -86,7 +88,7 @@ defmodule Livebook.Notebook do
| %{
name: String.t(),
type: :file,
file: Livebook.FileSystem.File.t()
file: FileSystem.File.t()
}
| %{
name: String.t(),
@ -108,7 +110,7 @@ defmodule Livebook.Notebook do
autosave_interval_s: default_autosave_interval_s(),
default_language: :elixir,
output_counter: 0,
app_settings: AppSettings.new(),
app_settings: Notebook.AppSettings.new(),
hub_id: Livebook.Hubs.Personal.id(),
hub_secret_names: [],
file_entries: [],

View file

@ -85,11 +85,14 @@ defmodule Livebook.Session do
require Logger
alias Livebook.NotebookManager
alias Livebook.Session.{Data, FileGuard}
alias Livebook.{Utils, Notebook, Text, Runtime, LiveMarkdown, FileSystem}
alias Livebook.Users.User
alias Livebook.Notebook.{Cell, Section}
alias Livebook.Session
alias Livebook.Session.Data
alias Livebook.Notebook
alias Livebook.Notebook.Cell
alias Livebook.Notebook.Section
alias Livebook.Runtime
alias Livebook.FileSystem
alias Livebook.Users
@timeout :infinity
@main_container_ref :main_flow
@ -131,8 +134,8 @@ defmodule Livebook.Session do
app_pid: pid() | nil,
auto_shutdown_ms: non_neg_integer() | nil,
auto_shutdown_timer_ref: reference() | nil,
started_by: Livebook.Users.User.t() | nil,
deployed_by: Livebook.Users.User.t() | nil
started_by: Users.User.t() | nil,
deployed_by: Users.User.t() | nil
}
@type memory_usage ::
@ -147,7 +150,7 @@ defmodule Livebook.Session do
@typedoc """
An id assigned to every running session process.
"""
@type id :: Utils.id()
@type id :: Livebook.Utils.id()
## API
@ -228,7 +231,7 @@ defmodule Livebook.Session do
Also returns a unique client identifier representing the registered
client.
"""
@spec register_client(pid(), pid(), User.t()) :: {Data.t(), Data.client_id()}
@spec register_client(pid(), pid(), Users.User.t()) :: {Data.t(), Data.client_id()}
def register_client(pid, client_pid, user) do
GenServer.call(pid, {:register_client, client_pid, user}, @timeout)
end
@ -586,7 +589,7 @@ defmodule Livebook.Session do
pid(),
Cell.id(),
Data.cell_source_tag(),
Text.Delta.t(),
Livebook.Text.Delta.t(),
Selection.t() | nil,
Data.cell_revision()
) :: :ok
@ -978,7 +981,7 @@ defmodule Livebook.Session do
data = Data.new(notebook: notebook, origin: origin, mode: mode)
if file do
case FileGuard.lock(file, self()) do
case Session.FileGuard.lock(file, self()) do
:ok ->
{:ok, %{data | file: file}}
@ -1069,7 +1072,7 @@ defmodule Livebook.Session do
{state, client_id}
else
Process.monitor(client_pid)
client_id = Utils.random_id()
client_id = Livebook.Utils.random_id()
state = handle_operation(state, {:client_join, client_id, user})
state = put_in(state.client_pids_with_id[client_pid], client_id)
{state, client_id}
@ -1116,7 +1119,7 @@ defmodule Livebook.Session do
end
def handle_call(:register_file_init, _from, state) do
file_id = Utils.random_id()
file_id = Livebook.Utils.random_id()
file_ref = {:file, file_id}
path = registered_file_path(state.session_id, file_ref)
reply = %{file_ref: file_ref, path: path}
@ -1168,21 +1171,23 @@ defmodule Livebook.Session do
def handle_cast({:insert_section, client_pid, index}, state) do
client_id = client_id(state, client_pid)
# Include new id in the operation, so it's reproducible
operation = {:insert_section, client_id, index, Utils.random_id()}
operation = {:insert_section, client_id, index, Livebook.Utils.random_id()}
{:noreply, handle_operation(state, operation)}
end
def handle_cast({:insert_section_into, client_pid, section_id, index}, state) do
client_id = client_id(state, client_pid)
# Include new id in the operation, so it's reproducible
operation = {:insert_section_into, client_id, section_id, index, Utils.random_id()}
operation = {:insert_section_into, client_id, section_id, index, Livebook.Utils.random_id()}
{:noreply, handle_operation(state, operation)}
end
def handle_cast({:insert_branching_section_into, client_pid, section_id, index}, state) do
client_id = client_id(state, client_pid)
# Include new id in the operation, so it's reproducible
operation = {:insert_branching_section_into, client_id, section_id, index, Utils.random_id()}
operation =
{:insert_branching_section_into, client_id, section_id, index, Livebook.Utils.random_id()}
{:noreply, handle_operation(state, operation)}
end
@ -1201,7 +1206,9 @@ defmodule Livebook.Session do
def handle_cast({:insert_cell, client_pid, section_id, index, type, attrs}, state) do
client_id = client_id(state, client_pid)
# Include new id in the operation, so it's reproducible
operation = {:insert_cell, client_id, section_id, index, type, Utils.random_id(), attrs}
operation =
{:insert_cell, client_id, section_id, index, type, Livebook.Utils.random_id(), attrs}
{:noreply, handle_operation(state, operation)}
end
@ -1289,7 +1296,7 @@ defmodule Livebook.Session do
source = binary_part(cell.source, offset, size)
attrs = %{source: source}
cell_idx = index + chunk_idx
cell_id = Utils.random_id()
cell_id = Livebook.Utils.random_id()
handle_operation(
state,
@ -1424,14 +1431,14 @@ defmodule Livebook.Session do
client_id = client_id(state, client_pid)
if file do
FileGuard.lock(file, self())
Session.FileGuard.lock(file, self())
else
:ok
end
|> case do
:ok ->
if state.data.file do
FileGuard.unlock(state.data.file)
Session.FileGuard.unlock(state.data.file)
end
{:noreply, handle_operation(state, {:set_file, client_id, file})}
@ -2328,7 +2335,7 @@ defmodule Livebook.Session do
defp after_operation(state, _prev_state, {:set_notebook_name, _client_id, _name}) do
if file = state.data.file do
NotebookManager.update_notebook_name(file, state.data.notebook.name)
Livebook.NotebookManager.update_notebook_name(file, state.data.notebook.name)
end
notify_update(state)
@ -2376,7 +2383,7 @@ defmodule Livebook.Session do
defp after_operation(state, prev_state, {:client_join, client_id, user}) do
unless Map.has_key?(prev_state.data.users_map, user.id) do
Livebook.Users.subscribe(user.id)
Users.subscribe(user.id)
end
state = put_in(state.client_id_with_assets[client_id], %{})
@ -2394,7 +2401,7 @@ defmodule Livebook.Session do
user_id = prev_state.data.clients_map[client_id]
unless Map.has_key?(state.data.users_map, user_id) do
Livebook.Users.unsubscribe(user_id)
Users.unsubscribe(user_id)
end
state = delete_client_files(state, client_id)
@ -2448,7 +2455,7 @@ defmodule Livebook.Session do
_prev_state,
{:smart_cell_started, _client_id, cell_id, delta, _chunks, _js_view, _editor}
) do
unless Text.Delta.empty?(delta) do
unless Livebook.Text.Delta.empty?(delta) do
hydrate_cell_source_digest(state, cell_id, :primary)
end
@ -2746,7 +2753,7 @@ defmodule Livebook.Session do
%{ref: ref} =
Task.Supervisor.async_nolink(Livebook.TaskSupervisor, fn ->
{content, warnings} = LiveMarkdown.notebook_to_livemd(notebook)
{content, warnings} = Livebook.LiveMarkdown.notebook_to_livemd(notebook)
result = FileSystem.File.write(file, content)
{:save_finished, result, warnings, file, default?}
end)
@ -2763,7 +2770,7 @@ defmodule Livebook.Session do
{file, default?} = notebook_autosave_file(state)
if file && should_save_notebook?(state) do
{content, warnings} = LiveMarkdown.notebook_to_livemd(state.data.notebook)
{content, warnings} = Livebook.LiveMarkdown.notebook_to_livemd(state.data.notebook)
result = FileSystem.File.write(file, content)
handle_save_finished(state, result, warnings, file, default?)
else

View file

@ -41,9 +41,13 @@ defmodule Livebook.Session.Data do
:app_data
]
alias Livebook.{Notebook, Text, Runtime, FileSystem, Hubs}
alias Livebook.Notebook
alias Livebook.Notebook.Cell
alias Livebook.Notebook.Section
alias Livebook.Text
alias Livebook.FileSystem
alias Livebook.Runtime
alias Livebook.Users.User
alias Livebook.Notebook.{Cell, Section, AppSettings}
alias Livebook.Utils.Graph
alias Livebook.Secrets.Secret
@ -244,7 +248,7 @@ defmodule Livebook.Session.Data do
| {:rename_file_entry, client_id(), name :: String.t(), new_name :: String.t()}
| {:delete_file_entry, client_id(), String.t()}
| {:allow_file_entry, client_id(), String.t()}
| {:set_app_settings, client_id(), AppSettings.t()}
| {:set_app_settings, client_id(), Notebook.AppSettings.t()}
| {:set_deployed_app_slug, client_id(), String.t()}
| {:app_deactivate, client_id()}
| {:app_shutdown, client_id()}
@ -295,8 +299,8 @@ defmodule Livebook.Session.Data do
%{status: %{execution: :executing, lifecycle: :active}}
end
hub = Hubs.fetch_hub!(notebook.hub_id)
hub_secrets = Hubs.get_secrets(hub)
hub = Livebook.Hubs.fetch_hub!(notebook.hub_id)
hub_secrets = Livebook.Hubs.get_secrets(hub)
startup_secrets =
for secret <- Livebook.Secrets.get_startup_secrets(),
@ -1029,7 +1033,7 @@ defmodule Livebook.Session.Data do
end
def apply_operation(data, {:set_notebook_hub, _client_id, id}) do
with {:ok, hub} <- Hubs.fetch_hub(id) do
with {:ok, hub} <- Livebook.Hubs.fetch_hub(id) do
data
|> with_actions()
|> set_notebook_hub(hub)
@ -1947,7 +1951,7 @@ defmodule Livebook.Session.Data do
| hub_id: hub.id,
teams_enabled: is_struct(hub, Livebook.Hubs.Team)
},
hub_secrets: Hubs.get_secrets(hub)
hub_secrets: Livebook.Hubs.get_secrets(hub)
)
end

View file

@ -6,14 +6,14 @@ defmodule Livebook.Sessions do
# propagated using `Livebook.Tracker`, which serves as an ephemeral
# distributed database for the `%Session{}` structs.
alias Livebook.{Session, Utils}
alias Livebook.Session
@doc """
Spawns a new `Session` process with the given options.
"""
@spec create_session(keyword()) :: {:ok, Session.t()} | {:error, any()}
def create_session(opts \\ []) do
id = Utils.random_node_aware_id()
id = Livebook.Utils.random_node_aware_id()
opts = Keyword.put(opts, :id, id)
@ -47,7 +47,7 @@ defmodule Livebook.Sessions do
:error ->
boot_id = Livebook.Config.random_boot_id()
case Utils.node_from_node_aware_id(id) do
case Livebook.Utils.node_from_node_aware_id(id) do
# The local tracker server doesn't know about this session,
# but it may not have propagated yet, so we extract the session
# node from id and ask the corresponding tracker directly

View file

@ -4,7 +4,9 @@ defmodule Livebook.Teams do
alias Livebook.Hubs
alias Livebook.Hubs.Team
alias Livebook.Hubs.TeamClient
alias Livebook.Teams.{Agent, AppDeployment, DeploymentGroup, Org, Requests}
alias Livebook.Teams
alias Livebook.Teams.Org
alias Livebook.Teams.Requests
import Ecto.Changeset,
only: [add_error: 3, apply_action: 2, apply_action!: 2, get_field: 2]
@ -154,22 +156,22 @@ defmodule Livebook.Teams do
@doc """
Returns an `%Ecto.Changeset{}` for tracking deployment group changes.
"""
@spec change_deployment_group(DeploymentGroup.t(), map()) :: Ecto.Changeset.t()
def change_deployment_group(%DeploymentGroup{} = deployment_group, attrs \\ %{}) do
DeploymentGroup.changeset(deployment_group, attrs)
@spec change_deployment_group(Teams.DeploymentGroup.t(), map()) :: Ecto.Changeset.t()
def change_deployment_group(%Teams.DeploymentGroup{} = deployment_group, attrs \\ %{}) do
Teams.DeploymentGroup.changeset(deployment_group, attrs)
end
@doc """
Creates a Deployment Group.
"""
@spec create_deployment_group(Team.t(), map()) ::
{:ok, DeploymentGroup.t()}
{:ok, Teams.DeploymentGroup.t()}
| {:error, Ecto.Changeset.t()}
| {:transport_error, String.t()}
def create_deployment_group(%Team{} = team, attrs) do
changeset = DeploymentGroup.changeset(%DeploymentGroup{}, attrs)
changeset = Teams.DeploymentGroup.changeset(%Teams.DeploymentGroup{}, attrs)
with {:ok, %DeploymentGroup{} = deployment_group} <- apply_action(changeset, :insert) do
with {:ok, %Teams.DeploymentGroup{} = deployment_group} <- apply_action(changeset, :insert) do
case Requests.create_deployment_group(team, deployment_group) do
{:ok, %{"id" => id}} ->
{:ok, %{deployment_group | id: to_string(id)}}
@ -189,7 +191,7 @@ defmodule Livebook.Teams do
@doc """
Gets a list of deployment groups for a given Hub.
"""
@spec get_deployment_groups(Team.t()) :: list(DeploymentGroup.t())
@spec get_deployment_groups(Team.t()) :: list(Teams.DeploymentGroup.t())
def get_deployment_groups(team) do
TeamClient.get_deployment_groups(team.id)
end
@ -197,11 +199,11 @@ defmodule Livebook.Teams do
@doc """
Creates a new app deployment.
"""
@spec deploy_app(Team.t(), AppDeployment.t()) ::
@spec deploy_app(Team.t(), Teams.AppDeployment.t()) ::
:ok
| {:error, Ecto.Changeset.t()}
| {:transport_error, String.t()}
def deploy_app(%Team{} = team, %AppDeployment{} = app_deployment) do
def deploy_app(%Team{} = team, %Teams.AppDeployment{} = app_deployment) do
case Requests.deploy_app(team, app_deployment) do
{:ok, %{"id" => _id}} ->
:ok
@ -220,7 +222,7 @@ defmodule Livebook.Teams do
@doc """
Gets a list of app deployments for a given Hub.
"""
@spec get_app_deployments(Team.t()) :: list(AppDeployment.t())
@spec get_app_deployments(Team.t()) :: list(Teams.AppDeployment.t())
def get_app_deployments(team) do
TeamClient.get_app_deployments(team.id)
end
@ -228,7 +230,7 @@ defmodule Livebook.Teams do
@doc """
Gets a list of agents for a given Hub.
"""
@spec get_agents(Team.t()) :: list(Agent.t())
@spec get_agents(Team.t()) :: list(Teams.Agent.t())
def get_agents(team) do
TeamClient.get_agents(team.id)
end
@ -236,7 +238,7 @@ defmodule Livebook.Teams do
@doc """
Gets a list of environment variables for a given Hub.
"""
@spec get_environment_variables(Team.t()) :: list(Agent.t())
@spec get_environment_variables(Team.t()) :: list(Teams.Agent.t())
def get_environment_variables(team) do
TeamClient.get_environment_variables(team.id)
end

View file

@ -1,5 +1,5 @@
defmodule Livebook.Teams.Broadcasts do
alias Livebook.Teams.{Agent, AppDeployment, DeploymentGroup}
alias Livebook.Teams
@type broadcast :: :ok | {:error, term()}
@ -70,56 +70,56 @@ defmodule Livebook.Teams.Broadcasts do
@doc """
Broadcasts under `#{@deployment_groups_topic}` topic when hub received a new deployment group.
"""
@spec deployment_group_created(DeploymentGroup.t()) :: broadcast()
def deployment_group_created(%DeploymentGroup{} = deployment_group) do
@spec deployment_group_created(Teams.DeploymentGroup.t()) :: broadcast()
def deployment_group_created(%Teams.DeploymentGroup{} = deployment_group) do
broadcast(@deployment_groups_topic, {:deployment_group_created, deployment_group})
end
@doc """
Broadcasts under `#{@deployment_groups_topic}` topic when hub received an updated deployment group.
"""
@spec deployment_group_updated(DeploymentGroup.t()) :: broadcast()
def deployment_group_updated(%DeploymentGroup{} = deployment_group) do
@spec deployment_group_updated(Teams.DeploymentGroup.t()) :: broadcast()
def deployment_group_updated(%Teams.DeploymentGroup{} = deployment_group) do
broadcast(@deployment_groups_topic, {:deployment_group_updated, deployment_group})
end
@doc """
Broadcasts under `#{@deployment_groups_topic}` topic when hub received a deleted deployment group.
"""
@spec deployment_group_deleted(DeploymentGroup.t()) :: broadcast()
def deployment_group_deleted(%DeploymentGroup{} = deployment_group) do
@spec deployment_group_deleted(Teams.DeploymentGroup.t()) :: broadcast()
def deployment_group_deleted(%Teams.DeploymentGroup{} = deployment_group) do
broadcast(@deployment_groups_topic, {:deployment_group_deleted, deployment_group})
end
@doc """
Broadcasts under `#{@app_deployments_topic}` topic when hub received to start a new app deployment.
"""
@spec app_deployment_started(AppDeployment.t()) :: broadcast()
def app_deployment_started(%AppDeployment{} = app_deployment) do
@spec app_deployment_started(Teams.AppDeployment.t()) :: broadcast()
def app_deployment_started(%Teams.AppDeployment{} = app_deployment) do
broadcast(@app_deployments_topic, {:app_deployment_started, app_deployment})
end
@doc """
Broadcasts under `#{@app_deployments_topic}` topic when hub received to stop an app deployment.
"""
@spec app_deployment_stopped(AppDeployment.t()) :: broadcast()
def app_deployment_stopped(%AppDeployment{} = app_deployment) do
@spec app_deployment_stopped(Teams.AppDeployment.t()) :: broadcast()
def app_deployment_stopped(%Teams.AppDeployment{} = app_deployment) do
broadcast(@app_deployments_topic, {:app_deployment_stopped, app_deployment})
end
@doc """
Broadcasts under `#{@agents_topic}` topic when hub received a new agent.
"""
@spec agent_joined(Agent.t()) :: broadcast()
def agent_joined(%Agent{} = agent) do
@spec agent_joined(Teams.Agent.t()) :: broadcast()
def agent_joined(%Teams.Agent{} = agent) do
broadcast(@agents_topic, {:agent_joined, agent})
end
@doc """
Broadcasts under `#{@agents_topic}` topic when hub received a deleted agent.
"""
@spec agent_left(Agent.t()) :: broadcast()
def agent_left(%Agent{} = agent) do
@spec agent_left(Teams.Agent.t()) :: broadcast()
def agent_left(%Teams.Agent{} = agent) do
broadcast(@agents_topic, {:agent_left, agent})
end

View file

@ -2,8 +2,8 @@ defmodule Livebook.Teams.DeploymentGroup do
use Ecto.Schema
import Ecto.Changeset
alias Livebook.Secrets.Secret
alias Livebook.Teams.{AgentKey, EnvironmentVariable}
alias Livebook.Secrets
alias Livebook.Teams
@type t :: %__MODULE__{
id: String.t() | nil,
@ -13,9 +13,9 @@ defmodule Livebook.Teams.DeploymentGroup do
clustering: :auto | :dns | nil,
hub_id: String.t() | nil,
teams_auth: boolean(),
secrets: Ecto.Schema.has_many(Secret.t()),
agent_keys: Ecto.Schema.has_many(AgentKey.t()),
environment_variables: Ecto.Schema.has_many(EnvironmentVariable.t())
secrets: Ecto.Schema.has_many(Secrets.Secret.t()),
agent_keys: Ecto.Schema.has_many(Teams.AgentKey.t()),
environment_variables: Ecto.Schema.has_many(Teams.EnvironmentVariable.t())
}
@primary_key {:id, :string, autogenerate: false}
@ -27,9 +27,9 @@ defmodule Livebook.Teams.DeploymentGroup do
field :url, :string
field :teams_auth, :boolean, default: true
has_many :secrets, Secret
has_many :agent_keys, AgentKey
has_many :environment_variables, EnvironmentVariable
has_many :secrets, Secrets.Secret
has_many :agent_keys, Teams.AgentKey
has_many :environment_variables, Teams.EnvironmentVariable
end
def changeset(deployment_group, attrs \\ %{}) do

View file

@ -4,26 +4,25 @@ defmodule Livebook.Teams.Requests do
alias Livebook.Hubs.Team
alias Livebook.Secrets.Secret
alias Livebook.Teams
alias Livebook.Teams.{AppDeployment, DeploymentGroup, Org}
@error_message "Something went wrong, try again later or please file a bug if it persists"
@doc """
Send a request to Livebook Team API to create a new org.
"""
@spec create_org(Org.t()) ::
@spec create_org(Teams.Org.t()) ::
{:ok, map()} | {:error, map() | String.t()} | {:transport_error, String.t()}
def create_org(org) do
post("/api/v1/org-request", %{name: org.name, key_hash: Org.key_hash(org)})
post("/api/v1/org-request", %{name: org.name, key_hash: Teams.Org.key_hash(org)})
end
@doc """
Send a request to Livebook Team API to join an org.
"""
@spec join_org(Org.t()) ::
@spec join_org(Teams.Org.t()) ::
{:ok, map()} | {:error, map() | String.t()} | {:transport_error, String.t()}
def join_org(org) do
post("/api/v1/org-request/join", %{name: org.name, key_hash: Org.key_hash(org)})
post("/api/v1/org-request/join", %{name: org.name, key_hash: Teams.Org.key_hash(org)})
end
@doc """
@ -166,7 +165,7 @@ defmodule Livebook.Teams.Requests do
@doc """
Send a request to Livebook Team API to create a deployment group.
"""
@spec create_deployment_group(Team.t(), DeploymentGroup.t()) ::
@spec create_deployment_group(Team.t(), Teams.DeploymentGroup.t()) ::
{:ok, map()} | {:error, map() | String.t()} | {:transport_error, String.t()}
def create_deployment_group(team, deployment_group) do
params = %{
@ -183,7 +182,7 @@ defmodule Livebook.Teams.Requests do
@doc """
Send a request to Livebook Team API to deploy an app.
"""
@spec deploy_app(Team.t(), AppDeployment.t()) ::
@spec deploy_app(Team.t(), Teams.AppDeployment.t()) ::
{:ok, map()} | {:error, map() | String.t()} | {:transport_error, String.t()}
def deploy_app(team, app_deployment) do
secret_key = Teams.derive_key(team.teams_key)
@ -204,7 +203,7 @@ defmodule Livebook.Teams.Requests do
@doc """
Send a request to Livebook Team API to download an app revision.
"""
@spec download_revision(Team.t(), AppDeployment.t()) ::
@spec download_revision(Team.t(), Teams.AppDeployment.t()) ::
{:ok, binary()} | {:error, map() | String.t()} | {:transport_error, String.t()}
def download_revision(team, app_deployment) do
params = %{id: app_deployment.id, deployment_group_id: app_deployment.deployment_group_id}

View file

@ -30,8 +30,10 @@ defmodule Livebook.Text.Delta do
defstruct ops: []
alias Livebook.Text.{Delta, JS}
alias Livebook.Text.Delta.{Operation, Transformation}
alias Livebook.Text
alias Livebook.Text.Delta
alias Livebook.Text.Delta.Operation
alias Livebook.Text.Delta.Transformation
@typedoc """
Delta carries a list of consecutive operations.
@ -195,7 +197,7 @@ defmodule Livebook.Text.Delta do
end
defp do_apply([{:retain, n} | ops], result, string) do
{left, right} = JS.split_at(string, n)
{left, right} = Text.JS.split_at(string, n)
do_apply(ops, <<result::binary, left::binary>>, right)
end
@ -204,7 +206,7 @@ defmodule Livebook.Text.Delta do
end
defp do_apply([{:delete, n} | ops], result, string) do
do_apply(ops, result, JS.slice(string, n))
do_apply(ops, result, Text.JS.slice(string, n))
end
defp do_apply([], result, string) do
@ -220,9 +222,9 @@ defmodule Livebook.Text.Delta do
string1
|> String.myers_difference(string2)
|> Enum.reduce(Delta.new(), fn
{:eq, string}, delta -> Delta.retain(delta, JS.length(string))
{:eq, string}, delta -> Delta.retain(delta, Text.JS.length(string))
{:ins, string}, delta -> Delta.insert(delta, string)
{:del, string}, delta -> Delta.delete(delta, JS.length(string))
{:del, string}, delta -> Delta.delete(delta, Text.JS.length(string))
end)
|> Delta.trim()
end

View file

@ -1,7 +1,9 @@
defmodule LivebookWeb.SessionController do
use LivebookWeb, :controller
alias Livebook.{Sessions, Session, FileSystem}
alias Livebook.Sessions
alias Livebook.Session
alias Livebook.FileSystem
alias LivebookWeb.CodecHelpers
def show_file(conn, %{"id" => id, "name" => name}) do

View file

@ -4,7 +4,6 @@ defmodule LivebookWeb.HomeLive do
import LivebookWeb.SessionHelpers
alias LivebookWeb.LayoutComponents
alias Livebook.{Sessions, Notebook}
on_mount LivebookWeb.SidebarHook
@ -16,8 +15,8 @@ defmodule LivebookWeb.HomeLive do
Livebook.NotebookManager.subscribe_starred_notebooks()
end
sessions = Sessions.list_sessions() |> Enum.filter(&(&1.mode == :default))
notebook_infos = Notebook.Learn.visible_notebook_infos() |> Enum.take(3)
sessions = Livebook.Sessions.list_sessions() |> Enum.filter(&(&1.mode == :default))
notebook_infos = Livebook.Notebook.Learn.visible_notebook_infos() |> Enum.take(3)
starred_notebooks = Livebook.NotebookManager.starred_notebooks()
{:ok,

View file

@ -5,8 +5,6 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
import LivebookWeb.SessionHelpers
import LivebookWeb.HTMLHelpers
alias Livebook.{Session, Notebook}
@impl true
def mount(socket) do
{:ok, assign(socket, order_by: "date")}
@ -329,8 +327,8 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
def handle_event("fork_session", %{"id" => session_id}, socket) do
session = Enum.find(socket.assigns.sessions, &(&1.id == session_id))
%{files_dir: files_dir} = session
data = Session.get_data(session.pid)
notebook = Notebook.forked(data.notebook)
data = Livebook.Session.get_data(session.pid)
notebook = Livebook.Notebook.forked(data.notebook)
origin =
if data.file do
@ -349,7 +347,7 @@ defmodule LivebookWeb.HomeLive.SessionListComponent do
def handle_event("disconnect_runtime", %{"id" => session_id}, socket) do
session = Enum.find(socket.assigns.sessions, &(&1.id == session_id))
Session.disconnect_runtime(session.pid)
Livebook.Session.disconnect_runtime(session.pid)
{:noreply, socket}
end

View file

@ -4,7 +4,7 @@ defmodule LivebookWeb.OpenLive do
import LivebookWeb.SessionHelpers
alias LivebookWeb.LayoutComponents
alias Livebook.{Sessions, Notebook, FileSystem}
alias Livebook.FileSystem
on_mount LivebookWeb.SidebarHook
@ -15,7 +15,7 @@ defmodule LivebookWeb.OpenLive do
Livebook.NotebookManager.subscribe_recent_notebooks()
end
sessions = Sessions.list_sessions() |> Enum.filter(&(&1.mode == :default))
sessions = Livebook.Sessions.list_sessions() |> Enum.filter(&(&1.mode == :default))
recent_notebooks = Livebook.NotebookManager.recent_notebooks()
show_autosave_note? =
@ -158,11 +158,11 @@ defmodule LivebookWeb.OpenLive do
def handle_params(%{"url" => url}, _url, socket)
when socket.assigns.live_action == :public_import do
origin = Notebook.ContentLoader.url_to_location(url)
origin = Livebook.Notebook.ContentLoader.url_to_location(url)
files_url = Livebook.Utils.expand_url(url, "files/")
origin
|> Notebook.ContentLoader.fetch_content_from_location()
|> Livebook.Notebook.ContentLoader.fetch_content_from_location()
|> case do
{:ok, content} ->
socket = import_source(socket, content, origin: origin, files_source: {:url, files_url})

View file

@ -3,8 +3,6 @@ defmodule LivebookWeb.OpenLive.UrlComponent do
import Ecto.Changeset
alias Livebook.{Utils, Notebook}
@impl true
def mount(socket) do
{:ok, assign(socket, changeset: changeset(), error_message: nil)}
@ -84,11 +82,11 @@ defmodule LivebookWeb.OpenLive.UrlComponent do
|> apply_action(:insert)
|> case do
{:ok, data} ->
origin = Notebook.ContentLoader.url_to_location(data.url)
origin = Livebook.Notebook.ContentLoader.url_to_location(data.url)
files_url = Livebook.Utils.expand_url(data.url, "files/")
origin
|> Notebook.ContentLoader.fetch_content_from_location()
|> Livebook.Notebook.ContentLoader.fetch_content_from_location()
|> case do
{:ok, content} ->
opts = [origin: origin, files_source: {:url, files_url}]
@ -98,7 +96,7 @@ defmodule LivebookWeb.OpenLive.UrlComponent do
{:error, message} ->
assign(socket,
changeset: changeset(data),
error_message: Utils.upcase_first(message)
error_message: Livebook.Utils.upcase_first(message)
)
end

View file

@ -4,7 +4,9 @@ defmodule LivebookWeb.SessionLive do
import LivebookWeb.SessionHelpers
import LivebookWeb.FileSystemComponents
alias Livebook.{Session, Text, Notebook, Runtime}
alias Livebook.Session
alias Livebook.Text
alias Livebook.Notebook
alias Livebook.Notebook.Cell
on_mount LivebookWeb.SidebarHook
@ -598,7 +600,7 @@ defmodule LivebookWeb.SessionLive do
node = Enum.find(socket.private.data.runtime_connected_nodes, &(Atom.to_string(&1) == node))
if node do
Runtime.disconnect_node(socket.private.data.runtime, node)
Livebook.Runtime.disconnect_node(socket.private.data.runtime, node)
end
{:noreply, socket}
@ -647,7 +649,14 @@ defmodule LivebookWeb.SessionLive do
parent_locators = Session.parent_locators_for_cell(data, cell)
node = intellisense_node(cell)
ref = Runtime.handle_intellisense(data.runtime, self(), request, parent_locators, node)
ref =
Livebook.Runtime.handle_intellisense(
data.runtime,
self(),
request,
parent_locators,
node
)
{:reply, %{"ref" => inspect(ref)}, socket}
else
@ -1606,7 +1615,7 @@ defmodule LivebookWeb.SessionLive do
defp example_snippet_definition_by_name(data, name) do
data.runtime
|> Runtime.snippet_definitions()
|> Livebook.Runtime.snippet_definitions()
|> Enum.find_value(:error, &(&1.type == :example && &1.name == name && {:ok, &1}))
end
@ -1619,7 +1628,7 @@ defmodule LivebookWeb.SessionLive do
has_dependencies? =
dependencies == [] or
Runtime.has_dependencies?(socket.private.data.runtime, dependencies)
Livebook.Runtime.has_dependencies?(socket.private.data.runtime, dependencies)
cond do
has_dependencies? ->
@ -1628,7 +1637,7 @@ defmodule LivebookWeb.SessionLive do
:error -> socket
end
Runtime.fixed_dependencies?(socket.private.data.runtime) ->
Livebook.Runtime.fixed_dependencies?(socket.private.data.runtime) ->
put_flash(socket, :error, "This runtime doesn't support adding dependencies")
true ->
@ -1746,7 +1755,7 @@ defmodule LivebookWeb.SessionLive do
defp handlers_for_file_entry(file_entry, runtime) do
handlers =
for definition <- Runtime.snippet_definitions(runtime),
for definition <- Livebook.Runtime.snippet_definitions(runtime),
definition.type == :file_action,
do: %{definition: definition, cell_type: :code}
@ -1814,14 +1823,14 @@ defmodule LivebookWeb.SessionLive do
dirty: data.dirty,
persistence_warnings: data.persistence_warnings,
runtime: data.runtime,
runtime_metadata: Runtime.describe(data.runtime),
runtime_metadata: Livebook.Runtime.describe(data.runtime),
runtime_status: data.runtime_status,
runtime_connect_info: data.runtime_connect_info,
runtime_connected_nodes: Enum.sort(data.runtime_connected_nodes),
smart_cell_definitions: Enum.sort_by(data.smart_cell_definitions, & &1.name),
example_snippet_definitions:
data.runtime
|> Runtime.snippet_definitions()
|> Livebook.Runtime.snippet_definitions()
|> Enum.filter(&(&1.type == :example))
|> Enum.sort_by(& &1.name),
global_status: global_status(data),

View file

@ -3,8 +3,6 @@ defmodule LivebookWeb.SessionLive.AttachedRuntimeComponent do
import Ecto.Changeset
alias Livebook.{Session, Runtime}
@impl true
def mount(socket) do
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Attached) do
@ -39,7 +37,7 @@ defmodule LivebookWeb.SessionLive.AttachedRuntimeComponent do
defp changeset(runtime, attrs \\ %{}) do
data =
case runtime do
%Runtime.Attached{node: node, cookie: cookie} ->
%Livebook.Runtime.Attached{node: node, cookie: cookie} ->
%{name: Atom.to_string(node), cookie: Atom.to_string(cookie)}
_ ->
@ -118,9 +116,9 @@ defmodule LivebookWeb.SessionLive.AttachedRuntimeComponent do
{:ok, data} ->
node = String.to_atom(data.name)
cookie = String.to_atom(data.cookie)
runtime = Runtime.Attached.new(node, cookie)
Session.set_runtime(socket.assigns.session.pid, runtime)
Session.connect_runtime(socket.assigns.session.pid)
runtime = Livebook.Runtime.Attached.new(node, cookie)
Livebook.Session.set_runtime(socket.assigns.session.pid, runtime)
Livebook.Session.connect_runtime(socket.assigns.session.pid)
{:noreply, socket}
{:error, changeset} ->

View file

@ -1,8 +1,6 @@
defmodule LivebookWeb.SessionLive.EmbeddedRuntimeComponent do
use LivebookWeb, :live_component
alias Livebook.{Session, Runtime}
@impl true
def mount(socket) do
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Embedded) do
@ -36,15 +34,15 @@ defmodule LivebookWeb.SessionLive.EmbeddedRuntimeComponent do
"""
end
defp label(%Runtime.Embedded{}, :connecting), do: "Connecting..."
defp label(%Runtime.Embedded{}, :connected), do: "Reconnect"
defp label(%Livebook.Runtime.Embedded{}, :connecting), do: "Connecting..."
defp label(%Livebook.Runtime.Embedded{}, :connected), do: "Reconnect"
defp label(_runtime, _runtime_status), do: "Connect"
@impl true
def handle_event("init", _params, socket) do
runtime = Runtime.Embedded.new()
Session.set_runtime(socket.assigns.session.pid, runtime)
Session.connect_runtime(socket.assigns.session.pid)
runtime = Livebook.Runtime.Embedded.new()
Livebook.Session.set_runtime(socket.assigns.session.pid, runtime)
Livebook.Session.connect_runtime(socket.assigns.session.pid)
{:noreply, socket}
end
end

View file

@ -3,8 +3,6 @@ defmodule LivebookWeb.SessionLive.FlyRuntimeComponent do
import Ecto.Changeset
alias Livebook.{Session, Runtime}
@impl true
def mount(socket) do
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Fly) do
@ -52,7 +50,7 @@ defmodule LivebookWeb.SessionLive.FlyRuntimeComponent do
is_map_key(socket.assigns, :config_defaults) ->
socket
is_struct(assigns.runtime, Runtime.Fly) ->
is_struct(assigns.runtime, Livebook.Runtime.Fly) ->
%{config: config} = assigns.runtime
config_defaults =
@ -516,14 +514,14 @@ defmodule LivebookWeb.SessionLive.FlyRuntimeComponent do
def handle_event("init", %{}, socket) do
config = build_config(socket)
runtime = Runtime.Fly.new(config)
Session.set_runtime(socket.assigns.session.pid, runtime)
Session.connect_runtime(socket.assigns.session.pid)
runtime = Livebook.Runtime.Fly.new(config)
Livebook.Session.set_runtime(socket.assigns.session.pid, runtime)
Livebook.Session.connect_runtime(socket.assigns.session.pid)
{:noreply, socket}
end
def handle_event("disconnect", %{}, socket) do
Session.disconnect_runtime(socket.assigns.session.pid)
Livebook.Session.disconnect_runtime(socket.assigns.session.pid)
{:noreply, socket}
end
@ -628,7 +626,7 @@ defmodule LivebookWeb.SessionLive.FlyRuntimeComponent do
end
defp reconnecting?(app_name, runtime) do
match?(%Runtime.Fly{config: %{app_name: ^app_name}}, runtime)
match?(%Livebook.Runtime.Fly{config: %{app_name: ^app_name}}, runtime)
end
defp cpu_kind_options() do

View file

@ -3,8 +3,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
import Ecto.Changeset
alias Livebook.{Session, Runtime}
alias Livebook.K8s.{Pod, PVC}
alias Livebook.K8s
@kubeconfig_pipeline Application.compile_env(:livebook, :k8s_kubeconfig_pipeline)
@ -31,7 +30,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
pvc_action: nil,
pvc_name: nil,
docker_tag: hd(Livebook.Config.docker_images()).tag,
pod_template: %{template: Pod.default_pod_template(), error_message: nil},
pod_template: %{template: K8s.Pod.default_pod_template(), error_message: nil},
save_config_payload: nil
)}
end
@ -62,7 +61,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
is_map_key(socket.assigns, :config_defaults) ->
socket
is_struct(assigns.runtime, Runtime.K8s) ->
is_struct(assigns.runtime, Livebook.Runtime.K8s) ->
%{config: config} = assigns.runtime
config_defaults =
@ -457,7 +456,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
def handle_event("new_pvc", %{}, socket) do
pvc_action = %{
type: :new,
changeset: PVC.changeset(),
changeset: K8s.PVC.changeset(),
storage_classes: storage_classes(socket.assigns),
status: :initial,
error: nil
@ -469,7 +468,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
def handle_event("validate_pvc", %{"pvc" => pvc}, socket) do
changeset =
pvc
|> PVC.changeset()
|> K8s.PVC.changeset()
|> Map.replace!(:action, :validate)
{:noreply, assign_nested(socket, :pvc_action, changeset: changeset)}
@ -481,7 +480,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
def handle_event("create_pvc", %{"pvc" => pvc}, socket) do
pvc
|> PVC.changeset()
|> K8s.PVC.changeset()
|> apply_action(:insert)
|> case do
{:ok, applied_pvc} ->
@ -517,14 +516,14 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
def handle_event("init", %{}, socket) do
config = build_config(socket)
runtime = Runtime.K8s.new(config)
Session.set_runtime(socket.assigns.session.pid, runtime)
Session.connect_runtime(socket.assigns.session.pid)
runtime = Livebook.Runtime.K8s.new(config)
Livebook.Session.set_runtime(socket.assigns.session.pid, runtime)
Livebook.Session.connect_runtime(socket.assigns.session.pid)
{:noreply, socket}
end
def handle_event("disconnect", %{}, socket) do
Session.disconnect_runtime(socket.assigns.session.pid)
Livebook.Session.disconnect_runtime(socket.assigns.session.pid)
{:noreply, socket}
end
@ -624,12 +623,12 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
end
defp reconnecting?(namespace, runtime) do
match?(%Runtime.K8s{config: %{namespace: ^namespace}}, runtime)
match?(%Livebook.Runtime.K8s{config: %{namespace: ^namespace}}, runtime)
end
defp create_pvc(socket, pvc) do
namespace = socket.assigns.namespace
manifest = PVC.manifest(pvc, namespace)
manifest = K8s.PVC.manifest(pvc, namespace)
kubeconfig = socket.assigns.kubeconfig
socket
@ -719,7 +718,7 @@ defmodule LivebookWeb.SessionLive.K8sRuntimeComponent do
with {:parse, {:ok, pod_template}} <-
{:parse, YamlElixir.read_from_string(pod_template_yaml)},
{:validate, :ok} <- {:validate, Pod.validate_pod_template(pod_template, namespace)} do
{:validate, :ok} <- {:validate, K8s.Pod.validate_pod_template(pod_template, namespace)} do
assign(socket, :pod_template, %{template: pod_template_yaml, error_message: nil})
else
{:parse, {:error, error}} ->

View file

@ -1,11 +1,11 @@
defmodule LivebookWeb.SessionLive.PersistenceComponent do
use LivebookWeb, :live_component
alias Livebook.{Sessions, Session, LiveMarkdown, FileSystem}
alias Livebook.FileSystem
@impl true
def mount(socket) do
sessions = Sessions.list_sessions()
sessions = Livebook.Sessions.list_sessions()
running_files = for session <- sessions, session.file, do: session.file
{:ok, assign(socket, running_files: running_files)}
end
@ -74,7 +74,7 @@ defmodule LivebookWeb.SessionLive.PersistenceComponent do
id="persistence_file_select"
file={@draft_file}
hub={@hub}
extnames={[LiveMarkdown.extension()]}
extnames={[Livebook.LiveMarkdown.extension()]}
running_files={@running_files}
on_submit={JS.push("save", target: @myself)}
target={{__MODULE__, @id}}
@ -154,7 +154,7 @@ defmodule LivebookWeb.SessionLive.PersistenceComponent do
end
def handle_event("stop_saving", %{}, socket) do
Session.set_file(socket.assigns.session.pid, nil)
Livebook.Session.set_file(socket.assigns.session.pid, nil)
{:noreply, push_patch(socket, to: ~p"/sessions/#{socket.assigns.session.id}")}
end
@ -166,16 +166,16 @@ defmodule LivebookWeb.SessionLive.PersistenceComponent do
draft_file = normalize_file(draft_file)
if draft_file != saved_file do
Session.set_file(assigns.session.pid, draft_file)
Livebook.Session.set_file(assigns.session.pid, draft_file)
end
diff = map_diff(new_attrs, attrs)
if diff != %{} do
Session.set_notebook_attributes(assigns.session.pid, diff)
Livebook.Session.set_notebook_attributes(assigns.session.pid, diff)
end
Session.save_sync(assigns.session.pid)
Livebook.Session.save_sync(assigns.session.pid)
push_patch(socket, to: return_to(assigns))
end
@ -207,7 +207,7 @@ defmodule LivebookWeb.SessionLive.PersistenceComponent do
end
defp normalize_file(file) do
FileSystem.File.ensure_extension(file, LiveMarkdown.extension())
FileSystem.File.ensure_extension(file, Livebook.LiveMarkdown.extension())
end
defp savable?(draft_file, saved_file, running_files) do

View file

@ -3,8 +3,6 @@ defmodule LivebookWeb.SessionLive.StandaloneRuntimeComponent do
import Ecto.Changeset
alias Livebook.{Session, Runtime}
@impl true
def mount(socket) do
unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Standalone) do
@ -39,7 +37,7 @@ defmodule LivebookWeb.SessionLive.StandaloneRuntimeComponent do
defp changeset(runtime, attrs \\ %{}) do
data =
case runtime do
%Runtime.Standalone{erl_flags: erl_flags} ->
%Livebook.Runtime.Standalone{erl_flags: erl_flags} ->
%{erl_flags: erl_flags}
_ ->
@ -116,9 +114,9 @@ defmodule LivebookWeb.SessionLive.StandaloneRuntimeComponent do
|> apply_action(:insert)
|> case do
{:ok, data} ->
runtime = Runtime.Standalone.new(erl_flags: data.erl_flags)
Session.set_runtime(socket.assigns.session.pid, runtime)
Session.connect_runtime(socket.assigns.session.pid)
runtime = Livebook.Runtime.Standalone.new(erl_flags: data.erl_flags)
Livebook.Session.set_runtime(socket.assigns.session.pid, runtime)
Livebook.Session.connect_runtime(socket.assigns.session.pid)
{:noreply, socket}
{:error, changeset} ->

View file

@ -1,7 +1,9 @@
defmodule Livebook.AppTest do
use ExUnit.Case, async: true
alias Livebook.{App, Notebook, Utils}
alias Livebook.App
alias Livebook.Notebook
alias Livebook.Utils
describe "startup" do
test "eagerly starts a session in single-session mode" do

View file

@ -4,7 +4,8 @@ defmodule Livebook.NotebookTest do
import Livebook.TestHelpers
alias Livebook.Notebook
alias Livebook.Notebook.{Section, Cell}
alias Livebook.Notebook.Section
alias Livebook.Notebook.Cell
describe "fetch_cell_sibling/3" do
test "returns error given invalid cell id" do

View file

@ -2,7 +2,8 @@ defmodule Livebook.Runtime.ErlDist.NodeManagerTest do
use ExUnit.Case, async: true
alias Livebook.Runtime
alias Livebook.Runtime.ErlDist.{NodeManager, RuntimeServer}
alias Livebook.Runtime.ErlDist.NodeManager
alias Livebook.Runtime.ErlDist.RuntimeServer
test "terminates when the last runtime server terminates" do
# We use a standalone runtime, so that we have an isolated node

View file

@ -1,7 +1,8 @@
defmodule Livebook.Runtime.ErlDist.RuntimeServerTest do
use ExUnit.Case, async: true
alias Livebook.Runtime.ErlDist.{NodeManager, RuntimeServer}
alias Livebook.Runtime.ErlDist.NodeManager
alias Livebook.Runtime.ErlDist.RuntimeServer
setup ctx do
{:ok, runtime_server_pid} = NodeManager.start_runtime_server(node(), ctx[:opts] || [])

View file

@ -4,7 +4,8 @@ defmodule Livebook.Session.DataTest do
import Livebook.TestHelpers
alias Livebook.Session.Data
alias Livebook.{Text, Notebook}
alias Livebook.Text
alias Livebook.Notebook
alias Livebook.Text.Delta
alias Livebook.Users.User

View file

@ -7,9 +7,9 @@ defmodule Livebook.SessionTest do
import Livebook.TestHelpers
alias Livebook.{Session, Text, Runtime, Utils, Notebook, FileSystem, Apps, App}
alias Livebook.Notebook.{Section, Cell}
alias Livebook.Notebook.Section
alias Livebook.Notebook.Cell
alias Livebook.Session.Data
alias Livebook.NotebookManager
@eval_meta %{
errored: false,
@ -366,7 +366,7 @@ defmodule Livebook.SessionTest do
wait_for_session_update(session.pid)
assert %{name: "New notebook name"} =
NotebookManager.recent_notebooks() |> Enum.find(&(&1.file == file))
Livebook.NotebookManager.recent_notebooks() |> Enum.find(&(&1.file == file))
end
end
@ -565,7 +565,7 @@ defmodule Livebook.SessionTest do
wait_for_session_update(session.pid)
assert NotebookManager.recent_notebooks() |> Enum.any?(&(&1.file == file))
assert Livebook.NotebookManager.recent_notebooks() |> Enum.any?(&(&1.file == file))
end
end
@ -849,7 +849,7 @@ defmodule Livebook.SessionTest do
start_session(file: file)
assert NotebookManager.recent_notebooks() |> Enum.any?(&(&1.file == file))
assert Livebook.NotebookManager.recent_notebooks() |> Enum.any?(&(&1.file == file))
end
end

View file

@ -1,7 +1,8 @@
defmodule Livebook.SessionsTest do
use ExUnit.Case, async: true
alias Livebook.{Sessions, Session}
alias Livebook.Sessions
alias Livebook.Session
describe "create_session/0" do
test "starts a new session process under the sessions supervisor" do

View file

@ -1,8 +1,10 @@
defmodule Livebook.TeamsTest do
use Livebook.TeamsIntegrationCase, async: true
alias Livebook.{FileSystem, Notebook, Teams, Utils}
alias Livebook.Teams.Org
alias Livebook.FileSystem
alias Livebook.Notebook
alias Livebook.Teams
alias Livebook.Utils
setup do
Livebook.Hubs.Broadcasts.subscribe([:connection, :file_systems, :secrets])
@ -36,7 +38,7 @@ defmodule Livebook.TeamsTest do
describe "join_org/1" do
test "returns the device flow data to confirm the org creation", %{user: user, node: node} do
org = build(:org)
key_hash = Org.key_hash(org)
key_hash = Teams.Org.key_hash(org)
teams_org = :erpc.call(node, TeamsRPC, :create_org, [[name: org.name]])
@ -74,7 +76,7 @@ defmodule Livebook.TeamsTest do
describe "get_org_request_completion_data/1" do
test "returns the org data when it has been confirmed", %{node: node, user: user} do
teams_key = Org.teams_key()
teams_key = Teams.Org.teams_key()
key_hash = :crypto.hash(:sha256, teams_key) |> Base.url_encode64(padding: false)
org_request =
@ -117,7 +119,7 @@ defmodule Livebook.TeamsTest do
end
test "returns the org request awaiting confirmation", %{node: node} do
teams_key = Org.teams_key()
teams_key = Teams.Org.teams_key()
key_hash = :crypto.hash(:sha256, teams_key) |> Base.url_encode64(padding: false)
org_request =
@ -145,7 +147,7 @@ defmodule Livebook.TeamsTest do
test "returns error when org request expired", %{node: node} do
now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
expires_at = NaiveDateTime.add(now, -5000)
teams_key = Org.teams_key()
teams_key = Teams.Org.teams_key()
key_hash = :crypto.hash(:sha256, teams_key) |> Base.url_encode64(padding: false)
org_request =

View file

@ -4,7 +4,9 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
import Phoenix.LiveViewTest
import Livebook.SessionHelpers
alias Livebook.{FileSystem, Sessions, Session}
alias Livebook.FileSystem
alias Livebook.Sessions
alias Livebook.Session
setup do
{:ok, session} = Sessions.create_session(notebook: Livebook.Notebook.new())

View file

@ -3,7 +3,10 @@ defmodule LivebookWeb.SessionControllerTest do
require Phoenix.LiveViewTest
alias Livebook.{Sessions, Session, Notebook, FileSystem}
alias Livebook.Sessions
alias Livebook.Session
alias Livebook.Notebook
alias Livebook.FileSystem
describe "show_file" do
test "returns not found when the given session does not exist", %{conn: conn} do

View file

@ -4,7 +4,10 @@ defmodule LivebookWeb.AppLiveTest do
import Phoenix.LiveViewTest
import Livebook.AppHelpers
alias Livebook.{App, Apps, Notebook, Utils}
alias Livebook.App
alias Livebook.Apps
alias Livebook.Notebook
alias Livebook.Utils
describe "single-session app" do
test "redirects to the current session page", %{conn: conn} do

View file

@ -5,7 +5,10 @@ defmodule LivebookWeb.AppSessionLiveTest do
import Livebook.TestHelpers
import Livebook.AppHelpers
alias Livebook.{App, Apps, Notebook, Utils}
alias Livebook.App
alias Livebook.Apps
alias Livebook.Notebook
alias Livebook.Utils
test "shows a nonexisting message if the session does not exist", %{conn: conn} do
slug = Utils.random_short_id()

View file

@ -5,7 +5,10 @@ defmodule LivebookWeb.AppsDashboardLiveTest do
import Livebook.TestHelpers
import Livebook.AppHelpers
alias Livebook.{App, Apps, Notebook, Utils}
alias Livebook.App
alias Livebook.Apps
alias Livebook.Notebook
alias Livebook.Utils
test "updates UI when app is deployed and terminated", %{conn: conn} do
slug = Utils.random_short_id()

View file

@ -5,7 +5,8 @@ defmodule LivebookWeb.HomeLiveTest do
import Livebook.SessionHelpers
import Livebook.TestHelpers
alias Livebook.{Sessions, Session}
alias Livebook.Sessions
alias Livebook.Session
test "disconnected and connected render", %{conn: conn} do
{:ok, view, disconnected_html} = live(conn, ~p"/")

View file

@ -3,7 +3,9 @@ defmodule LivebookWeb.OpenLiveTest do
import Phoenix.LiveViewTest
alias Livebook.{Sessions, Session, FileSystem}
alias Livebook.Sessions
alias Livebook.Session
alias Livebook.FileSystem
describe "file selection" do
test "does not mention autosaving if disabled", %{conn: conn} do

View file

@ -5,7 +5,7 @@ defmodule LivebookWeb.SessionLiveTest do
import Livebook.TestHelpers
import Phoenix.LiveViewTest
alias Livebook.{Sessions, Session, Settings, Runtime, Users, FileSystem}
alias Livebook.{Sessions, Session, Settings, Runtime, FileSystem}
alias Livebook.Notebook.Cell
setup do
@ -1777,7 +1777,7 @@ defmodule LivebookWeb.SessionLiveTest do
assert render(view) =~ "Jake Peralta"
Users.broadcast_change(%{user1 | name: "Raymond Holt"})
Livebook.Users.broadcast_change(%{user1 | name: "Raymond Holt"})
assert_receive {:operation, {:update_user, _client_id, _user}}
refute render(view) =~ "Jake Peralta"

View file

@ -6,7 +6,9 @@ defmodule LivebookWeb.ProxyPlugTest do
require Phoenix.LiveViewTest
import Livebook.AppHelpers
alias Livebook.{Notebook, Session, Sessions}
alias Livebook.Notebook
alias Livebook.Session
alias Livebook.Sessions
describe "session" do
test "returns error when session doesn't exist", %{conn: conn} do

View file

@ -1,6 +1,6 @@
defmodule Livebook.SessionHelpers do
alias Livebook.{Hubs, Session, Sessions}
alias Livebook.Secrets.Secret
alias Livebook.Session
alias Livebook.Secrets
import ExUnit.Assertions
import Phoenix.LiveViewTest
@ -34,7 +34,7 @@ defmodule Livebook.SessionHelpers do
def bypass_url(port), do: "http://localhost:#{port}"
def close_session_by_id(session_id) do
{:ok, session} = Sessions.fetch_session(session_id)
{:ok, session} = Livebook.Sessions.fetch_session(session_id)
Session.close(session.pid)
end
@ -68,7 +68,7 @@ defmodule Livebook.SessionHelpers do
refute secret in secrets
end
def hub_label(%Secret{hub_id: id}), do: hub_label(Hubs.fetch_hub!(id))
def hub_label(%Secrets.Secret{hub_id: id}), do: hub_label(Livebook.Hubs.fetch_hub!(id))
def hub_label(hub), do: "#{hub.hub_emoji} #{hub.hub_name}"
defp secret_selector(secret) do