Skip to content

Commit 5068875

Browse files
committed
formatter
1 parent 29475c1 commit 5068875

17 files changed

+572
-416
lines changed

.JuliaFormatter.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
whitespace_in_kwargs = false
3+
trailing_comma = true

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"julia.format.ops": false,
88
"julia.format.iterOps": false,
99
"julia.format.tuples": false,
10-
"editor.formatOnSave": false
10+
"editor.formatOnSave": true
1111
}

src/Actions.jl

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
import Pluto: Pluto, without_pluto_file_extension, generate_html, @asynclog
32
using Base64
43
using SHA
54
using FromFile
65

7-
@from "./MoreAnalysis.jl" import bound_variable_connections_graph
6+
@from "./MoreAnalysis.jl" import bound_variable_connections_graph
87
@from "./Export.jl" import try_get_exact_pluto_version, try_fromcache, try_tocache
98
@from "./Types.jl" import NotebookSession, RunningNotebook, FinishedNotebook
109
@from "./Configuration.jl" import PlutoDeploySettings
@@ -14,52 +13,47 @@ function path_hash(path)
1413
myhash(read(path))
1514
end
1615

17-
showall(xs) = Text(join(string.(xs),"\n"))
16+
showall(xs) = Text(join(string.(xs), "\n"))
1817

1918

2019
###
2120
# Shutdown
22-
function process(s::NotebookSession{String,Nothing,<:Any};
23-
server_session::Pluto.ServerSession,
24-
settings::PlutoDeploySettings,
25-
output_dir::AbstractString,
26-
start_dir::AbstractString,
27-
progress,
28-
)::NotebookSession
29-
30-
21+
function process(
22+
s::NotebookSession{String,Nothing,<:Any};
23+
server_session::Pluto.ServerSession,
24+
settings::PlutoDeploySettings,
25+
output_dir::AbstractString,
26+
start_dir::AbstractString,
27+
progress,
28+
)::NotebookSession
29+
30+
3131
if s.run isa RunningNotebook
3232
Pluto.SessionActions.shutdown(server_session, s.run.notebook)
3333
end
3434

3535
try
36-
remove_static_export(s.path;
37-
settings,
38-
output_dir,
39-
)
36+
remove_static_export(s.path; settings, output_dir)
4037
catch e
41-
@warn "Failed to remove static export files" s.path exception=(e,catch_backtrace())
38+
@warn "Failed to remove static export files" s.path exception =
39+
(e, catch_backtrace())
4240
end
43-
41+
4442
@info "### ✓ $(progress) Shutdown complete" s.path
4543

46-
NotebookSession(;
47-
path=s.path,
48-
current_hash=nothing,
49-
desired_hash=nothing,
50-
run=nothing,
51-
)
44+
NotebookSession(; path=s.path, current_hash=nothing, desired_hash=nothing, run=nothing)
5245
end
5346

5447
###
5548
# Launch
56-
function process(s::NotebookSession{Nothing,String,<:Any};
57-
server_session::Pluto.ServerSession,
58-
settings::PlutoDeploySettings,
59-
output_dir::AbstractString,
60-
start_dir::AbstractString,
61-
progress,
62-
)::NotebookSession
49+
function process(
50+
s::NotebookSession{Nothing,String,<:Any};
51+
server_session::Pluto.ServerSession,
52+
settings::PlutoDeploySettings,
53+
output_dir::AbstractString,
54+
start_dir::AbstractString,
55+
progress,
56+
)::NotebookSession
6357

6458
path = s.path
6559
abs_path = joinpath(start_dir, path)
@@ -71,7 +65,7 @@ function process(s::NotebookSession{Nothing,String,<:Any};
7165
if new_hash != s.desired_hash
7266
@warn "Notebook file does not have desired hash. This probably means that the file changed too quickly. Continuing and hoping for the best!" s.path new_hash s.desired_hash
7367
end
74-
68+
7569
keep_running = settings.SliderServer.enabled
7670
skip_cache = keep_running || path settings.Export.ignore_cache
7771

@@ -80,10 +74,7 @@ function process(s::NotebookSession{Nothing,String,<:Any};
8074
run = if cached_state !== nothing
8175
@info "Loaded from cache, skipping notebook run" s.path new_hash
8276
original_state = cached_state
83-
FinishedNotebook(;
84-
path,
85-
original_state,
86-
)
77+
FinishedNotebook(; path, original_state)
8778
else
8879
try
8980
# open and run the notebook
@@ -100,27 +91,23 @@ function process(s::NotebookSession{Nothing,String,<:Any};
10091
bond_connections = bound_variable_connections_graph(notebook)
10192
@info "Bond connections" s.path showall(collect(bond_connections))
10293

103-
RunningNotebook(;
104-
path,
105-
notebook,
106-
original_state,
107-
bond_connections,
108-
)
94+
RunningNotebook(; path, notebook, original_state, bond_connections)
10995
else
110-
FinishedNotebook(;
111-
path,
112-
original_state,
113-
)
96+
FinishedNotebook(; path, original_state)
11497
end
11598
catch e
11699
(e isa InterruptException) || rethrow(e)
117-
@error "$(progress) Failed to run notebook!" path exception=(e,catch_backtrace())
100+
@error "$(progress) Failed to run notebook!" path exception =
101+
(e, catch_backtrace())
118102
# continue
119103
nothing
120104
end
121105
end
122106

123-
generate_static_export(path, run.original_state, jl_contents;
107+
generate_static_export(
108+
path,
109+
run.original_state,
110+
jl_contents;
124111
settings,
125112
start_dir,
126113
output_dir,
@@ -138,30 +125,32 @@ end
138125

139126
###
140127
# Update if needed
141-
function process(s::NotebookSession{String,String,<:Any};
142-
server_session::Pluto.ServerSession,
143-
settings::PlutoDeploySettings,
144-
output_dir::AbstractString,
145-
start_dir::AbstractString,
146-
progress,
147-
)::NotebookSession
128+
function process(
129+
s::NotebookSession{String,String,<:Any};
130+
server_session::Pluto.ServerSession,
131+
settings::PlutoDeploySettings,
132+
output_dir::AbstractString,
133+
start_dir::AbstractString,
134+
progress,
135+
)::NotebookSession
148136

149137
if s.current_hash != s.desired_hash
150138
@info "Updating notebook... will shut down and relaunch" s.path
151-
139+
152140
# Simple way to update: shut down notebook and start new one
153141
if s.run isa RunningNotebook
154142
Pluto.SessionActions.shutdown(server_session, s.run.notebook)
155143
end
156144

157145
@info "Shutdown complete" s.path
158146

159-
result = process(NotebookSession(;
160-
path=s.path,
161-
current_hash=nothing,
162-
desired_hash=s.desired_hash,
163-
run=nothing,
164-
);
147+
result = process(
148+
NotebookSession(;
149+
path=s.path,
150+
current_hash=nothing,
151+
desired_hash=s.desired_hash,
152+
run=nothing,
153+
);
165154
server_session,
166155
settings,
167156
output_dir,
@@ -200,7 +189,14 @@ Core Action: Generate static export for a Pluto Notebook
200189
4. baked_state: Whether to export pluto state within the html or in a separate file.
201190
5. pluto_cdn_root: URL where pluto will go to find the static frontend assets
202191
"""
203-
function generate_static_export(path, original_state, jl_contents; settings, output_dir, start_dir)
192+
function generate_static_export(
193+
path,
194+
original_state,
195+
jl_contents;
196+
settings,
197+
output_dir,
198+
start_dir,
199+
)
204200
pluto_version = try_get_exact_pluto_version()
205201
export_jl_path = let
206202
relative_to_notebooks_dir = path
@@ -221,7 +217,9 @@ function generate_static_export(path, original_state, jl_contents; settings, out
221217
mkpath(dirname(export_statefile_path))
222218

223219

224-
slider_server_running_somewhere = settings.Export.slider_server_url !== nothing || (settings.SliderServer.serve_static_export_folder && settings.SliderServer.enabled)
220+
slider_server_running_somewhere =
221+
settings.Export.slider_server_url !== nothing ||
222+
(settings.SliderServer.serve_static_export_folder && settings.SliderServer.enabled)
225223

226224
notebookfile_js = if settings.Export.offer_binder || slider_server_running_somewhere
227225
if settings.Export.baked_notebookfile
@@ -235,10 +233,7 @@ function generate_static_export(path, original_state, jl_contents; settings, out
235233
slider_server_url_js = if slider_server_running_somewhere
236234
abs_path = joinpath(start_dir, path)
237235
url_of_root = relpath(start_dir, dirname(abs_path)) # e.g. "." or "../../.."
238-
repr(something(
239-
settings.Export.slider_server_url,
240-
url_of_root
241-
))
236+
repr(something(settings.Export.slider_server_url, url_of_root))
242237
else
243238
"undefined"
244239
end
@@ -263,13 +258,16 @@ function generate_static_export(path, original_state, jl_contents; settings, out
263258
html_contents = generate_html(;
264259
pluto_cdn_root=settings.Export.pluto_cdn_root,
265260
version=pluto_version,
266-
notebookfile_js, statefile_js,
267-
slider_server_url_js, binder_url_js,
268-
disable_ui=settings.Export.disable_ui
261+
notebookfile_js,
262+
statefile_js,
263+
slider_server_url_js,
264+
binder_url_js,
265+
disable_ui=settings.Export.disable_ui,
269266
)
270267
write(export_html_path, html_contents)
271268

272-
if (settings.Export.offer_binder || settings.Export.slider_server_url !== nothing) && !settings.Export.baked_notebookfile
269+
if (settings.Export.offer_binder || settings.Export.slider_server_url !== nothing) &&
270+
!settings.Export.baked_notebookfile
273271
write(export_jl_path, jl_contents)
274272
end
275273

@@ -297,7 +295,8 @@ function remove_static_export(path; settings, output_dir)
297295
tryrm(export_statefile_path)
298296
end
299297
tryrm(export_html_path)
300-
if (settings.Export.offer_binder || settings.Export.slider_server_url !== nothing) && !settings.Export.baked_notebookfile
298+
if (settings.Export.offer_binder || settings.Export.slider_server_url !== nothing) &&
299+
!settings.Export.baked_notebookfile
301300
tryrm(export_jl_path)
302301
end
303302
end

src/Configuration.jl

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,71 @@ using FromFile
99

1010

1111
@extract_docs @option struct SliderServerSettings
12-
enabled::Bool=true
12+
enabled::Bool = true
1313
"List of notebook files to skip. Provide paths relative to `start_dir`. *If `Export.enabled` is `true` (default), then only paths in `SliderServer_exclude ∩ Export_exclude` will be skipped, paths in `setdiff(SliderServer_exclude, Export_exclude)` will be shut down after exporting.*"
14-
exclude::Vector=String[]
14+
exclude::Vector = String[]
1515
"Port to run the HTTP server on."
16-
port::Integer=2345
16+
port::Integer = 2345
1717
"""Often set to `"0.0.0.0"` on a server."""
18-
host::Any="127.0.0.1"
19-
simulated_lag::Real=0
18+
host::Any = "127.0.0.1"
19+
simulated_lag::Real = 0
2020
"Besides handling slider server request, should we also run a static file server of the export output folder? Set to `false` if you are serving the HTML files in another way, e.g. using GitHub Pages, and, for some reason, you do not want to *also* serve the HTML files using this serve."
21-
serve_static_export_folder::Bool=true
21+
serve_static_export_folder::Bool = true
2222
"Watch the input directory for file changes, and update the slider server sessions automatically. Only takes effect when running the slider server. More info in the README."
23-
watch_dir::Bool=true
23+
watch_dir::Bool = true
2424
end
2525

2626
@extract_docs @option struct ExportSettings
2727
"Generate static HTML files? This setting can only be `false` if you are also running a slider server."
28-
enabled::Bool=true
28+
enabled::Bool = true
2929
"Folder to write generated HTML files to (will create directories to preserve the input folder structure). The behaviour of the default value depends on whether you are running the slider server, or just exporting. If running the slider server, we use a temporary directory; otherwise, we use `start_dir` (i.e. we generate each HTML file in the same folder as the notebook file)."
30-
output_dir::Union{Nothing,String}=nothing
30+
output_dir::Union{Nothing,String} = nothing
3131
"List of notebook files to skip. Provide paths relative to `start_dir`."
32-
exclude::Vector{String}=String[]
32+
exclude::Vector{String} = String[]
3333
"List of notebook files that should always re-run, skipping the `cache_dir` system. Provide paths relative to `start_dir`."
34-
ignore_cache::Vector=String[]
35-
pluto_cdn_root::Union{Nothing,String}=nothing
34+
ignore_cache::Vector = String[]
35+
pluto_cdn_root::Union{Nothing,String} = nothing
3636
"base64-encode the state object and write it inside the .html file. If `false`, a separate `.plutostate` file is generated. A separate statefile allows us to show a loading bar in pluto while the statefile is loading, but it can complicate setup in some environments."
37-
baked_state::Bool=true
38-
baked_notebookfile::Bool=true
37+
baked_state::Bool = true
38+
baked_notebookfile::Bool = true
3939
"Hide all buttons and toolbars in Pluto to make it look like an article."
40-
disable_ui::Bool=true
40+
disable_ui::Bool = true
4141
"""Show a "Run on Binder" button on the notebooks."""
42-
offer_binder::Bool=true
42+
offer_binder::Bool = true
4343
"e.g. `https://mybinder.org/v2/gh/mitmath/18S191/e2dec90`. Defaults to a binder repo that runs the correct version of Pluto -- https://github.com/fonsp/pluto-on-binder. TODO docs"
44-
binder_url::Union{Nothing,String}=nothing
44+
binder_url::Union{Nothing,String} = nothing
4545
"""If 1) you are using this setup to export HTML files for notebooks, AND 2) you are running the slider server **on another setup/computer**, then this setting should be the URL pointing to the slider server, e.g. `"https://sliderserver.mycoolproject.org/"`. For example, you need this if you use GitHub Actions and GitHub Pages to generate HTML files, with a slider server on DigitalOcean. === If you only have *one* server for both the static exports and the slider server, and people will read notebooks directly on your server, then the default value `nothing` will work: it will automatically make the HTML files use their current domain for the slider server."""
46-
slider_server_url::Union{Nothing,String}=nothing
46+
slider_server_url::Union{Nothing,String} = nothing
4747
"If provided, use this directory to read and write cached notebook states. Caches will be indexed by the hash of the notebook file, but you need to take care to invalidate the cache when Pluto or this export script updates. Useful in combination with https://github.com/actions/cache, see https://github.com/JuliaPluto/static-export-template for an example."
48-
cache_dir::Union{Nothing,String}=nothing
48+
cache_dir::Union{Nothing,String} = nothing
4949
"Automatically generate an `index.html` file, listing all the exported notebooks (only if no `index.jl` or `index.html` file exists already)."
50-
create_index::Bool=true
50+
create_index::Bool = true
5151
end
5252

5353
@option struct PlutoDeploySettings
54-
SliderServer::SliderServerSettings=SliderServerSettings()
55-
Export::ExportSettings=ExportSettings()
56-
Pluto::Pluto.Configuration.Options=Pluto.Configuration.Options()
54+
SliderServer::SliderServerSettings = SliderServerSettings()
55+
Export::ExportSettings = ExportSettings()
56+
Pluto::Pluto.Configuration.Options = Pluto.Configuration.Options()
5757
end
5858

59-
function get_configuration(toml_path::Union{Nothing,String}=nothing; kwargs...)::PlutoDeploySettings
59+
function get_configuration(
60+
toml_path::Union{Nothing,String}=nothing;
61+
kwargs...,
62+
)::PlutoDeploySettings
6063
# we set `Pluto_server_notebook_path_suggestion=joinpath(homedir(),"")` to because the default value for this setting changes when the pwd changes. This causes our run_git_directory to exit... Not necessary for Pluto 0.17.3 and up.
6164
if !isnothing(toml_path) && isfile(toml_path)
62-
Configurations.from_toml(PlutoDeploySettings, toml_path; Pluto_server_notebook_path_suggestion=joinpath(homedir(),""), kwargs...)
65+
Configurations.from_toml(
66+
PlutoDeploySettings,
67+
toml_path;
68+
Pluto_server_notebook_path_suggestion=joinpath(homedir(), ""),
69+
kwargs...,
70+
)
6371
else
64-
Configurations.from_kwargs(PlutoDeploySettings; Pluto_server_notebook_path_suggestion=joinpath(homedir(),""), kwargs...)
72+
Configurations.from_kwargs(
73+
PlutoDeploySettings;
74+
Pluto_server_notebook_path_suggestion=joinpath(homedir(), ""),
75+
kwargs...,
76+
)
6577
end
6678
end
6779

0 commit comments

Comments
 (0)