@@ -16,39 +16,10 @@ module WorkerSetup
1616
1717# Imports.
1818
19- import Pkg
2019import RelocatableFolders
21- import Scratch
22- import TOML
2320
24- # Package init-time.
25-
26- # To allow it to be added to a system image we make sure it is relocatable.
21+ # Support adding to a system image.
2722const QNW = RelocatableFolders. @path joinpath (@__DIR__ , " QuartoNotebookWorker" )
28- let
29- # Any content from the worker package should trigger recompilation in the
30- # runner package, for ease of development.
31- for (root, dirs, files) in walkdir (QNW)
32- for file in files
33- include_dependency (joinpath (root, file))
34- end
35- end
36- end
37-
38- # The loader environment is used to load the worker package into whatever
39- # environment that the user has started the process with.
40- const LOADER_ENV = Ref (" " )
41-
42- # Since we start a task to perform the loader env setup at package init-time we
43- # don't want that to block `using QuartoNotebookRunner` so we lock the setup
44- # task to allow prevention of starting the loader env until
45- const WORKER_SETUP_LOCK = ReentrantLock ()
46-
47- function __init__ ()
48- if ccall (:jl_generating_output , Cint, ()) == 0
49- LOADER_ENV[] = String (QNW)
50- end
51- end
5223
5324# Debugging utilities.
5425
@@ -69,53 +40,14 @@ julia> include("runtests.jl")
6940to run the test suite without having to reload the worker package.
7041"""
7142function debug (; exeflags = String[])
72- if islocked (WORKER_SETUP_LOCK)
73- error (" Worker setup is in progress. Please try again later." )
74- else
75- mktempdir () do temp_dir
76- file = joinpath (temp_dir, " setup.jl" )
77- project = LOADER_ENV[]
78- write (
79- file,
80- """
81- # Try load `Revise` first, since we want to be able to track
82- # changes in the worker package.
83- try
84- import Revise
85- catch error
86- @info "Revise not available."
87- end
88-
89- cd($(repr (QNW)) )
90-
91- pushfirst!(LOAD_PATH, $(repr (project)) )
92-
93- # Always do a `precompile` so that it's simpler to kill and
94- # restart the worker without it potentially being stale.
95- import Pkg
96- Pkg.precompile()
97-
98- import QuartoNotebookWorker
99-
100- # Attempt to import some other useful packages.
101- try
102- import Debugger
103- catch error
104- @info "Debugger not available."
105- end
106- try
107- import TestEnv
108- catch error
109- @info "TestEnv not available."
110- end
111- """ ,
112- )
113- julia = Base. julia_cmd ()[1 ]
114- cmd = ` $julia $exeflags --startup-file=no -i $file `
115- run (cmd)
116- end
43+ mktempdir () do temp_dir
44+ julia = Base. julia_cmd ()[1 ]
45+ debug_env = joinpath (temp_dir, " QuartoNotebookWorker.DEBUG" )
46+ cmd = ` $julia $exeflags --project=$debug_env --startup-file=no -i $DEBUG_STARTUP `
47+ run (addenv (cmd, " QUARTONOTEBOOKWORKER_PACKAGE" => String (QNW)))
11748 end
11849end
50+ const DEBUG_STARTUP = RelocatableFolders. @path joinpath (@__DIR__ , " debug_startup.jl" )
11951
12052"""
12153 test()
@@ -126,25 +58,12 @@ the `TestEnv` package to do so.
12658"""
12759function test (; exeflags = String[])
12860 mktempdir () do temp_dir
129- file = joinpath (temp_dir, " runtests.jl" )
130- project = LOADER_ENV[]
131- write (
132- file,
133- """
134- pushfirst!(LOAD_PATH, "@stdlib")
135- import Pkg
136- popfirst!(LOAD_PATH)
137-
138- cd($(repr (QNW)) )
139-
140- pushfirst!(LOAD_PATH, $(repr (project)) )
141- Pkg.test("QuartoNotebookWorker")
142- """ ,
143- )
14461 julia = Base. julia_cmd ()[1 ]
145- cmd = ` $julia $exeflags --startup-file=no $file `
146- run (cmd)
62+ test_env = joinpath (temp_dir, " QuartoNotebookWorker.TEST" )
63+ cmd = ` $julia $exeflags --project=$test_env --startup-file=no $TEST_STARTUP `
64+ run (addenv (cmd, " QUARTONOTEBOOKWORKER_PACKAGE" => String (QNW)))
14765 end
14866end
67+ const TEST_STARTUP = RelocatableFolders. @path joinpath (@__DIR__ , " test_startup.jl" )
14968
15069end
0 commit comments