Skip to content

Commit 53fd7bb

Browse files
authored
Formatting some code and adjust formatting configs (#396)
1 parent 61ed22d commit 53fd7bb

File tree

11 files changed

+65
-22
lines changed

11 files changed

+65
-22
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore=["misc/**"]

DoodleBUGS/runtime/server.jl

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const CORS_HEADERS = [
1212
]
1313

1414
function cors_handler(handler)
15-
return function(req::HTTP.Request)
15+
return function (req::HTTP.Request)
1616
if HTTP.method(req) == "OPTIONS"
1717
return HTTP.Response(200, CORS_HEADERS)
1818
else
@@ -25,15 +25,19 @@ end
2525

2626
function health_check_handler(req::HTTP.Request)
2727
@info "Health check ping (backend reachable)"
28-
return HTTP.Response(200, ["Content-Type" => "application/json"], JSON3.write(Dict("status" => "ok")))
28+
return HTTP.Response(
29+
200,
30+
["Content-Type" => "application/json"],
31+
JSON3.write(Dict("status" => "ok")),
32+
)
2933
end
3034

3135

3236
function run_model_handler(req::HTTP.Request)
3337
logs = String[]
3438
log!(logs, "Received /api/run request")
3539
log!(logs, "Backend processing started.")
36-
40+
3741
tmp_dir = mktempdir()
3842
log!(logs, "Created temporary working directory at: $(tmp_dir)")
3943

@@ -217,12 +221,17 @@ function run_model_handler(req::HTTP.Request)
217221
cmd = `$(julia_executable) --project=$(project_dir) --threads=auto $(script_path)`
218222

219223
log!(logs, "Executing script in worker process...")
220-
timeout_s = try Int(get(settings, :timeout_s, 0)) catch; 0 end
224+
timeout_s = try
225+
Int(get(settings, :timeout_s, 0))
226+
catch
227+
;
228+
0
229+
end
221230
if timeout_s <= 0
222231
run(cmd)
223232
log!(logs, "Script execution finished.")
224233
else
225-
proc = run(cmd; wait=false)
234+
proc = run(cmd; wait = false)
226235
log!(logs, "Worker process started; enforcing timeout of $(timeout_s)s")
227236
deadline = time() + timeout_s
228237
while process_running(proc) && time() < deadline
@@ -258,21 +267,33 @@ function run_model_handler(req::HTTP.Request)
258267
Dict("name" => "payload.json", "content" => read(payload_path, String)),
259268
]
260269
if isfile(results_path)
261-
push!(files_arr, Dict("name" => "results.json", "content" => read(results_path, String)))
270+
push!(
271+
files_arr,
272+
Dict("name" => "results.json", "content" => read(results_path, String)),
273+
)
262274
end
263275

264276
# Diagnostics: log attachment sizes
265277
sizes = String[]
266278
for f in files_arr
267-
push!(sizes, string(f["name"], "=", sizeof(f["content"])) )
279+
push!(sizes, string(f["name"], "=", sizeof(f["content"])))
268280
end
269-
log!(logs, "Attaching $(length(files_arr)) files; sizes(bytes): $(join(sizes, ", "))")
281+
log!(
282+
logs,
283+
"Attaching $(length(files_arr)) files; sizes(bytes): $(join(sizes, ", "))",
284+
)
270285

271286
response_body = Dict(
272287
"success" => true,
273-
"results" => (haskey(results_content, :summary) ? results_content[:summary] : (haskey(results_content, :results) ? results_content[:results] : Any[])),
274-
"summary" => (haskey(results_content, :summary) ? results_content[:summary] : Any[]),
275-
"quantiles" => (haskey(results_content, :quantiles) ? results_content[:quantiles] : Any[]),
288+
"results" => (
289+
haskey(results_content, :summary) ? results_content[:summary] :
290+
(haskey(results_content, :results) ? results_content[:results] : Any[])
291+
),
292+
"summary" =>
293+
(haskey(results_content, :summary) ? results_content[:summary] : Any[]),
294+
"quantiles" => (
295+
haskey(results_content, :quantiles) ? results_content[:quantiles] : Any[]
296+
),
276297
"logs" => logs,
277298
"files" => files_arr,
278299
)
@@ -293,21 +314,34 @@ function run_model_handler(req::HTTP.Request)
293314
push!(files_arr, Dict("name" => "model.bugs", "content" => model_code))
294315
end
295316
if @isdefined(run_script_content)
296-
push!(files_arr, Dict("name" => "run_script.jl", "content" => run_script_content))
317+
push!(
318+
files_arr,
319+
Dict("name" => "run_script.jl", "content" => run_script_content),
320+
)
297321
end
298322
if @isdefined(payload_path) && isfile(payload_path)
299-
push!(files_arr, Dict("name" => "payload.json", "content" => read(payload_path, String)))
323+
push!(
324+
files_arr,
325+
Dict("name" => "payload.json", "content" => read(payload_path, String)),
326+
)
300327
end
301328
if @isdefined(results_path) && isfile(results_path)
302-
push!(files_arr, Dict("name" => "results.json", "content" => read(results_path, String)))
329+
push!(
330+
files_arr,
331+
Dict("name" => "results.json", "content" => read(results_path, String)),
332+
)
303333
end
304334
error_response = Dict(
305335
"success" => false,
306336
"error" => sprint(showerror, e),
307337
"logs" => logs,
308338
"files" => files_arr,
309339
)
310-
return HTTP.Response(500, ["Content-Type" => "application/json"], JSON3.write(error_response))
340+
return HTTP.Response(
341+
500,
342+
["Content-Type" => "application/json"],
343+
JSON3.write(error_response),
344+
)
311345
finally
312346
# Clean up temp directory in background with retries to avoid EBUSY on Windows
313347
@async safe_rmdir(tmp_dir)
@@ -327,11 +361,11 @@ end
327361
Remove directory tree with retries and backoff. Resilient to transient EBUSY on Windows.
328362
Intended to be called in a background task.
329363
"""
330-
function safe_rmdir(path::AbstractString; retries::Int=6, sleep_s::Float64=0.25)
331-
for _ in 1:retries
364+
function safe_rmdir(path::AbstractString; retries::Int = 6, sleep_s::Float64 = 0.25)
365+
for _ = 1:retries
332366
try
333367
GC.gc()
334-
rm(path; recursive=true, force=true)
368+
rm(path; recursive = true, force = true)
335369
return
336370
catch e
337371
msg = sprint(showerror, e)

JuliaBUGS/.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
style="blue"
22
always_use_return=false
3+
short_to_long_function_def=false

JuliaBUGS/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "JuliaBUGS"
22
uuid = "ba9fb4c0-828e-4473-b6a1-cd2560fee5bf"
3-
version = "0.10.2"
3+
version = "0.10.3"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

JuliaBUGS/src/BUGSExamples/Volume_2/08_Cervix.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ model
4747
}
4848
"""
4949

50+
#! format: off
5051
data = (N = 2044,
5152
d = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5253
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -439,6 +440,7 @@ data = (N = 2044,
439440
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
440441
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
441442
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
443+
#! format: on
442444

443445
inits = (beta0C = 0, beta = 0, q = 0.5, phi = [0.5 0.5; 0.5 0.5])
444446
inits_alternative = (beta0C = 1.0, beta = 1.0, q = 0.75, phi = [0.15 0.15; 0.15 0.15])

JuliaBUGS/src/BUGSExamples/Volume_2/11_Schools.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ model
7070
}
7171
"""
7272

73+
#! format: off
7374
data = (N = 1978, M = 38, mn = [0, 0, 0],
7475
prec = [0.0001 0 0; 0 0.0001 0; 0 0 0.0001],
7576
R = [0.1 0.005 0.005; 0.005 0.1 0.005; 0.005 0.005 0.1],
@@ -1573,6 +1574,7 @@ inits_alternative = (theta = 0.1, phi = 0, gamma = [1.0, 1.0, 1.0],
15731574
0 0 0
15741575
0 0 0
15751576
0 0 0])
1577+
#! format: on
15761578

15771579
reference_results = (
15781580
var"beta[1]" = (mean = 2.589E-4, std = 9.8E-5),

JuliaBUGS/src/BUGSExamples/Volume_2/16_Stagnant.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ reference_results = (
5252
)
5353

5454
stagnant = Example(
55-
name, model_def, original, data, inits, inits_alternative, reference_results)
55+
name, model_def, original, data, inits, inits_alternative, reference_results)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

JuliaBUGS/src/BUGSExamples/Volume_3/09_Hips4.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ model_def = @bugs begin
9292
for t in 2:N
9393
for s in 1:S
9494
var"pi"[
95-
n, k, t, s] = inprod(
95+
n, k, t, s] = inprod(
9696
var"pi"[n, k, t - 1, :], Lambda[n, k, t, :, s])
9797
end
9898
end

0 commit comments

Comments
 (0)