Repository navigation
Expand file tree
/
Copy pathlivebook.ex
More file actions
188 lines (146 loc) · 5.87 KB
/
Copy pathlivebook.ex
File metadata and controls
188 lines (146 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
defmodule Livebook do
@moduledoc """
Livebook is an interactive notebook system for Elixir.
This module includes the public API.
## Configuration
See `config_runtime/0` for bootstrapping the default runtime
configuration. There are several public configuration entries that
you can customize.
### Custom plugs
You can list a number of plugs to call directly before the Livebook
router
config :livebook, :plugs, [{CustomPlug, []}]
### Embedded runtime dependencies
In case you use the Embedded runtime and support installing
dependencies with `Mix.install/2`, you can make those discoverable
in the package search, by configuring a loader function:
config :livebook, Livebook.Runtime.Embedded,
load_packages: {Loader, :packages, []}
The function should return a list of entries like this:
[
%{
dependency: {:kino, "~> 0.6.1"},
description: "Interactive widgets for Livebook",
name: "kino",
url: "https://hex.pm/packages/kino",
version: "0.6.1"
}
]
### Custom explore notebooks
**Note that this is compile time configuration.**
A list of additional notebooks to include in the Explore section.
Note that the notebooks are loaded and embedded in a compiled module,
so the paths are accessed at compile time only.
config :livebook, :explore_notebooks, [
%{
# Required notebook path
path: "/path/to/notebook.livemd",
# Optional notebook identifier for URLs, as in /explore/notebooks/{slug}
# By default the slug is inferred from file name, so there is no need to set it
slug: "my-notebook"
# Optional list of images
image_paths: [
# This image can be sourced as images/myimage.jpg in the notebook
"/path/to/myimage.jpg"
],
# Optional details for the notebook card. If omitted, the notebook
# is hidden in the UI, but still accessible under /explore/notebooks/{slug}
details: %{
cover_path: "/path/to/logo.png",
description: "My custom notebook that showcases some amazing stuff."
}
},
%{
path: "/path/to/other_notebook.livemd"
}
]
"""
@doc """
Executes Livebook's `config/runtime.exs`.
If you use Livebook as a dependency, you can add the following
to your `config/runtime.exs` to trigger Livebook's `config/runtime.exs`
configuration:
Livebook.config_runtime()
"""
def config_runtime do
import Config
config :livebook, LivebookWeb.Endpoint,
secret_key_base:
Livebook.Config.secret!("LIVEBOOK_SECRET_KEY_BASE") ||
Base.encode64(:crypto.strong_rand_bytes(48))
if port = Livebook.Config.port!("LIVEBOOK_PORT") do
config :livebook, LivebookWeb.Endpoint, http: [port: port]
end
if ip = Livebook.Config.ip!("LIVEBOOK_IP") do
host = Livebook.Utils.ip_to_host(ip)
config :livebook, LivebookWeb.Endpoint, http: [ip: ip], url: [host: host]
end
cond do
password = Livebook.Config.password!("LIVEBOOK_PASSWORD") ->
config :livebook, authentication_mode: :password, password: password
Livebook.Config.boolean!("LIVEBOOK_TOKEN_ENABLED", true) ->
config :livebook, token: Livebook.Utils.random_id()
true ->
config :livebook, authentication_mode: :disabled
end
if port = Livebook.Config.port!("LIVEBOOK_IFRAME_PORT") do
config :livebook, :iframe_port, port
end
if url = Livebook.Config.iframe_url!("LIVEBOOK_IFRAME_URL") do
config :livebook, :iframe_url, url
end
if Livebook.Config.boolean!("LIVEBOOK_SHUTDOWN_ENABLED", false) do
config :livebook, :shutdown_enabled, true
end
config :livebook,
:default_runtime,
Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") ||
Livebook.Runtime.ElixirStandalone.new()
config :livebook,
:runtime_modules,
[
Livebook.Runtime.ElixirStandalone,
Livebook.Runtime.Attached
]
if home = Livebook.Config.writable_dir!("LIVEBOOK_HOME") do
config :livebook, :home, home
end
if data_path = Livebook.Config.writable_dir!("LIVEBOOK_DATA_PATH") do
config :livebook, :data_path, data_path
end
if force_ssl_host = Livebook.Config.force_ssl_host!("LIVEBOOK_FORCE_SSL_HOST") do
config :livebook, :force_ssl_host, force_ssl_host
end
config :livebook,
:cookie,
Livebook.Config.cookie!("LIVEBOOK_COOKIE") ||
Livebook.Config.cookie!("RELEASE_COOKIE") ||
Livebook.Utils.random_cookie()
if app_service_name = Livebook.Config.app_service_name!("LIVEBOOK_APP_SERVICE_NAME") do
config :livebook, :app_service_name, app_service_name
config :livebook,
:app_service_url,
Livebook.Config.app_service_url!("LIVEBOOK_APP_SERVICE_URL")
end
if update_instructions_url =
Livebook.Config.update_instructions_url!("LIVEBOOK_UPDATE_INSTRUCTIONS_URL") do
config :livebook, :update_instructions_url, update_instructions_url
end
end
@doc """
Parses the given Live Markdown document and converts it to Elixir
source code.
## Limitations
Note that the resulting script may not compile in some cases, for
example if you define a macro in one cell and import it in another
cell, it works fine in Livebook, because each cell is compiled
separately. However, when running the script it gets compiled as a
whole and consequently doing so doesn't work.
Additionally, branching sections are commented out.
"""
@spec live_markdown_to_elixir(String.t()) :: String.t()
def live_markdown_to_elixir(markdown) do
{notebook, _messages} = Livebook.LiveMarkdown.notebook_from_livemd(markdown)
Livebook.Notebook.Export.Elixir.notebook_to_elixir(notebook)
end
end