mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-25 04:46:04 +08:00
Update docs
This commit is contained in:
parent
4b8834c599
commit
4a0a958509
21 changed files with 46 additions and 6 deletions
|
|
@ -133,6 +133,7 @@ defmodule Livebook.Delta do
|
|||
iex> delta = %Livebook.Delta{ops: [retain: 2, insert: "hey", delete: 3]}
|
||||
iex> Livebook.Delta.to_compressed(delta)
|
||||
[2, "hey", -3]
|
||||
|
||||
"""
|
||||
@spec to_compressed(t()) :: list(Operation.compressed_t())
|
||||
def to_compressed(delta) do
|
||||
|
|
@ -146,6 +147,7 @@ defmodule Livebook.Delta do
|
|||
|
||||
iex> Livebook.Delta.from_compressed([2, "hey", -3])
|
||||
%Livebook.Delta{ops: [retain: 2, insert: "hey", delete: 3]}
|
||||
|
||||
"""
|
||||
@spec from_compressed(list(Operation.compressed_t())) :: t()
|
||||
def from_compressed(list) do
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ defmodule Livebook.Delta.Operation do
|
|||
[{:insert, "ca"}, {:insert, "t"}],
|
||||
[{:retain, 2}, {:delete, 2}]
|
||||
}
|
||||
|
||||
"""
|
||||
@spec align_heads(list(t()), list(t())) :: {list(t()), list(t())}
|
||||
def align_heads([head_a | tail_a], [head_b | tail_b]) do
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ defmodule Livebook.EctoTypes.HexColor do
|
|||
## Options
|
||||
|
||||
* `:except` - a list of colors to omit
|
||||
|
||||
"""
|
||||
def random(opts \\ []) do
|
||||
colors = [
|
||||
|
|
@ -70,6 +71,7 @@ defmodule Livebook.EctoTypes.HexColor do
|
|||
|
||||
iex> Livebook.EctoTypes.HexColor.valid?("#111")
|
||||
false
|
||||
|
||||
"""
|
||||
@spec valid?(String.t()) :: boolean()
|
||||
def valid?(hex_color), do: hex_color =~ ~r/^#[0-9a-fA-F]{6}$/
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ defprotocol Livebook.FileSystem do
|
|||
|
||||
* `:global` - if the resource is external and available
|
||||
accessible from any node
|
||||
|
||||
"""
|
||||
@spec type(t()) :: :local | :global
|
||||
def type(file_system)
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ defmodule Livebook.FileSystem.File do
|
|||
|
||||
* `:recursive` - whether to traverse all nested directories,
|
||||
defaults to `false`
|
||||
|
||||
"""
|
||||
@spec list(t(), keyword()) :: {:ok, list(t())} | {:error, FileSystem.error()}
|
||||
def list(file, opts \\ []) do
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ defmodule Livebook.Intellisense.Docs do
|
|||
* `:kinds` - a list of member kinds to limit the lookup to.
|
||||
Valid kinds are `:function`, `:macro` and `:type`. Defaults
|
||||
to all kinds
|
||||
|
||||
"""
|
||||
@spec lookup_module_members(
|
||||
module(),
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ defmodule Livebook.LiveMarkdown do
|
|||
* `:include_outputs` - whether to render cell outputs.
|
||||
Only textual outputs are included. Defaults to the
|
||||
value of `:persist_outputs` notebook attribute.
|
||||
|
||||
"""
|
||||
@spec notebook_to_livemd(Notebook.t(), keyword()) :: String.t()
|
||||
defdelegate notebook_to_livemd(notebook, opts \\ []), to: Livebook.LiveMarkdown.Export
|
||||
|
|
|
|||
|
|
@ -327,6 +327,7 @@ defprotocol Livebook.Runtime do
|
|||
|
||||
* `:runtime_broadcast_to` - the process to send runtime broadcast
|
||||
events to. Defaults to the owner
|
||||
|
||||
"""
|
||||
@spec take_ownership(t(), keyword()) :: reference()
|
||||
def take_ownership(runtime, opts \\ [])
|
||||
|
|
@ -392,6 +393,7 @@ defprotocol Livebook.Runtime do
|
|||
|
||||
* `:smart_cell_ref` - a reference of the smart cell which code is
|
||||
to be evaluated, if applicable
|
||||
|
||||
"""
|
||||
@spec evaluate_code(t(), String.t(), locator(), parent_locators(), keyword()) :: :ok
|
||||
def evaluate_code(runtime, code, locator, parent_locators, opts \\ [])
|
||||
|
|
@ -539,6 +541,7 @@ defprotocol Livebook.Runtime do
|
|||
The response is sent to the `send_to` process as
|
||||
|
||||
* `{:runtime_search_packages_response, ref, response}`.
|
||||
|
||||
"""
|
||||
@spec search_packages(t(), pid(), String.t()) :: reference()
|
||||
def search_packages(runtime, send_to, search)
|
||||
|
|
|
|||
|
|
@ -193,6 +193,7 @@ defmodule Livebook.Runtime.Dependencies do
|
|||
|
||||
iex> Livebook.Runtime.Dependencies.parse_term(~s|Enum|)
|
||||
:error
|
||||
|
||||
"""
|
||||
@spec parse_term(String.t()) :: {:ok, term()} | :error
|
||||
def parse_term(string) do
|
||||
|
|
@ -271,6 +272,7 @@ defmodule Livebook.Runtime.Dependencies do
|
|||
## Options
|
||||
|
||||
* `:api_url` - the base URL for Hex API requests. Optional
|
||||
|
||||
"""
|
||||
@spec search_hex(String.t(), keyword()) :: Livebook.Runtime.search_packages_response()
|
||||
def search_hex(search, opts \\ [])
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ defmodule Livebook.Runtime.ErlDist do
|
|||
* `:node_manager_opts` - see `Livebook.Runtime.ErlDist.NodeManager.start/1`
|
||||
|
||||
* `:runtime_server_opts` - see `Livebook.Runtime.ErlDist.RuntimeServer.start_link/1`
|
||||
|
||||
"""
|
||||
@spec initialize(node(), keyword()) :: pid()
|
||||
def initialize(node, opts \\ []) do
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ defmodule Livebook.Runtime.ErlDist.IOForwardGL do
|
|||
* `:name` - the name to register the process under. Optional.
|
||||
If the name is already used, it will be unregistered before
|
||||
starting the process and registered back when the server
|
||||
terminates.
|
||||
terminates
|
||||
|
||||
"""
|
||||
@spec start_link(keyword()) :: GenServer.on_start()
|
||||
def start_link(opts \\ []) do
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
|
||||
* `:unload_modules_on_termination` - whether to unload all
|
||||
Livebook related modules from the node on termination.
|
||||
Defaults to `true`.
|
||||
Defaults to `true`
|
||||
|
||||
* `:anonymous` - configures whether manager should
|
||||
be registered under a global name or not.
|
||||
In most cases we enforce a single manager per node
|
||||
and identify it by a name, but this can be opted-out
|
||||
from by using this option. Defaults to `false`.
|
||||
from by using this option. Defaults to `false`
|
||||
|
||||
* `:auto_termination` - whether to terminate the manager
|
||||
when the last runtime server terminates. Defaults to `true`.
|
||||
when the last runtime server terminates. Defaults to `true`
|
||||
|
||||
* `:parent_node` - indicates which node spawned the node manager.
|
||||
It is used to disconnect the node when the server terminates,
|
||||
|
|
@ -45,6 +45,7 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
|||
|
||||
* `:capture_orphan_logs` - whether to capture logs out of Livebook
|
||||
evaluator's scope. Defaults to `true`
|
||||
|
||||
"""
|
||||
def start(opts \\ []) do
|
||||
{opts, gen_opts} = split_opts(opts)
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ defmodule Livebook.Runtime.Evaluator do
|
|||
* `:on_finish` - a function to run when the evaluation is
|
||||
finished. The function receives `t:evaluation_result/0`
|
||||
as an argument
|
||||
|
||||
"""
|
||||
@spec evaluate_code(t(), String.t(), ref(), list(ref()), keyword()) :: :ok
|
||||
def evaluate_code(evaluator, code, ref, parent_refs, opts \\ []) do
|
||||
|
|
|
|||
|
|
@ -20,8 +20,12 @@ defmodule Livebook.Runtime.NodePool do
|
|||
|
||||
## Options
|
||||
|
||||
- `:name` - The name the NodePool is locally registered as. By default, it is `Livebook.Runtime.NodePool`
|
||||
- `:buffer_time` - The time that is spent before a disconnected node's name is added to pool. The default is 1 minute.
|
||||
* `:name` - The name the NodePool is locally registered as. By
|
||||
default, it is `Livebook.Runtime.NodePool`
|
||||
|
||||
* `:buffer_time` - The time that is spent before a disconnected
|
||||
node's name is added to pool. The default is 1 minute.
|
||||
|
||||
"""
|
||||
def start_link(opts) do
|
||||
name = opts[:name] || __MODULE__
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ defmodule Livebook.Runtime.StandaloneInit do
|
|||
## Options
|
||||
|
||||
* `:init_opts` - see `Livebook.Runtime.ErlDist.initialize/2`
|
||||
|
||||
"""
|
||||
@spec parent_init_sequence(node(), port(), keyword()) :: {:ok, pid()} | {:error, String.t()}
|
||||
def parent_init_sequence(child_node, port, opts \\ []) do
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> get_in(%{}, [Livebook.Utils.access_by_id(1)])
|
||||
** (RuntimeError) Livebook.Utils.access_by_id/1 expected a list, got: %{}
|
||||
|
||||
"""
|
||||
@spec access_by_id(term()) ::
|
||||
Access.access_fun(data :: struct() | map(), current_value :: term())
|
||||
|
|
@ -156,6 +157,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.valid_url?("http://")
|
||||
false
|
||||
|
||||
"""
|
||||
@spec valid_url?(String.t()) :: boolean()
|
||||
def valid_url?(url) do
|
||||
|
|
@ -176,6 +178,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.valid_cli_flags?("--arg1 \"")
|
||||
false
|
||||
|
||||
"""
|
||||
@spec valid_cli_flags?(String.t()) :: boolean()
|
||||
def valid_cli_flags?(flags) do
|
||||
|
|
@ -200,6 +203,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.upcase_first("")
|
||||
""
|
||||
|
||||
"""
|
||||
@spec upcase_first(String.t()) :: String.t()
|
||||
def upcase_first(string) do
|
||||
|
|
@ -220,6 +224,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.downcase_first("")
|
||||
""
|
||||
|
||||
"""
|
||||
@spec downcase_first(String.t()) :: String.t()
|
||||
def downcase_first(string) do
|
||||
|
|
@ -237,6 +242,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.expand_url("https://example.com/lib/file.ex?token=supersecret", "../root.ex")
|
||||
"https://example.com/root.ex?token=supersecret"
|
||||
|
||||
"""
|
||||
@spec expand_url(String.t(), String.t()) :: String.t()
|
||||
def expand_url(url, relative_path) do
|
||||
|
|
@ -263,6 +269,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.wrap_line("cat in the cup", 2)
|
||||
"cat\nin\nthe\ncup"
|
||||
|
||||
"""
|
||||
@spec wrap_line(String.t(), pos_integer()) :: String.t()
|
||||
def wrap_line(line, width) do
|
||||
|
|
@ -341,6 +348,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.split_at_last_occurrence("123", ",")
|
||||
:error
|
||||
|
||||
"""
|
||||
@spec split_at_last_occurrence(String.t(), String.pattern()) ::
|
||||
{:ok, left :: String.t(), right :: String.t()} | :error
|
||||
|
|
@ -371,6 +379,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.apply_rewind("Hola\r\nHey\r")
|
||||
"Hola\r\nHey\r"
|
||||
|
||||
"""
|
||||
@spec apply_rewind(String.t()) :: String.t()
|
||||
def apply_rewind(text) when is_binary(text) do
|
||||
|
|
@ -403,6 +412,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.cap_lines("Line 1\nLine 2", 3)
|
||||
"Line 1\nLine 2"
|
||||
|
||||
"""
|
||||
@spec cap_lines(String.t(), non_neg_integer()) :: String.t()
|
||||
def cap_lines(text, max_lines) do
|
||||
|
|
@ -540,6 +550,7 @@ defmodule Livebook.Utils do
|
|||
|
||||
iex> Livebook.Utils.ip_to_host({0, 0, 0, 0})
|
||||
"0.0.0.0"
|
||||
|
||||
"""
|
||||
@spec ip_to_host(:inet.ip_address()) :: String.t()
|
||||
def ip_to_host(ip)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ defmodule Livebook.Utils.ANSI do
|
|||
## Options
|
||||
|
||||
* `:modifiers` - a list with initial modifiers
|
||||
|
||||
"""
|
||||
@spec parse_ansi_string(String.t(), keyword()) :: {list({modifiers(), String.t()}), modifiers()}
|
||||
def parse_ansi_string(string, opts \\ []) do
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ defmodule Livebook.Utils.HTTP do
|
|||
* `body` - request body given as `{content_type, body}`
|
||||
|
||||
* `timeout` - request timeout, defaults to 10 seconds
|
||||
|
||||
"""
|
||||
@spec request(atom(), String.t(), keyword()) ::
|
||||
{:ok, status(), headers(), binary()} | {:error, term()}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ defmodule Livebook.Utils.Time do
|
|||
|
||||
iex> Livebook.Utils.Time.distance_of_time_in_words(~N[2020-06-20 18:15:00], ~N[2021-08-22 18:15:00])
|
||||
"about 14 months"
|
||||
|
||||
"""
|
||||
@spec distance_of_time_in_words(NaiveDateTime.t(), NaiveDateTime.t()) :: String.t()
|
||||
def distance_of_time_in_words(from_ndt, to_ndt)
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ defmodule LivebookWeb.CoreComponents do
|
|||
|
||||
<.live_region role="alert" />
|
||||
<.live_region role="status" />
|
||||
|
||||
"""
|
||||
def live_region(assigns) do
|
||||
~H"""
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ defmodule LivebookWeb.Helpers do
|
|||
|
||||
iex> LivebookWeb.Helpers.pluralize(3, "notebook is not persisted", "notebooks are not persisted")
|
||||
"3 notebooks are not persisted"
|
||||
|
||||
"""
|
||||
@spec pluralize(non_neg_integer(), String.t(), String.t()) :: String.t()
|
||||
def pluralize(1, singular, _plural), do: "1 #{singular}"
|
||||
|
|
@ -87,6 +88,7 @@ defmodule LivebookWeb.Helpers do
|
|||
|
||||
iex> LivebookWeb.Helpers.format_items(["wine", "tea", "coffee"])
|
||||
"wine, tea and coffee"
|
||||
|
||||
"""
|
||||
@spec format_items(list(String.t())) :: String.t()
|
||||
def format_items([]), do: ""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue