Skip to content

Commit 2c82ced

Browse files
authored
Merge pull request #229 from JuliaDocs/sp/better-env-handling
feat: run all package ops and doc builds in separate processes
2 parents 61b0dea + 74e5473 commit 2c82ced

File tree

7 files changed

+134
-74
lines changed

7 files changed

+134
-74
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
version:
19-
- '1.8'
2019
- '1.9'
2120
- '1.10'
21+
- '1.11'
2222
os:
2323
- ubuntu-latest
2424
arch:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
2323

2424
[compat]
2525
AbstractTrees = "0.4"
26-
Documenter = "0.24, 0.25, 0.26, 0.27"
26+
Documenter = "0.24, 0.25, 0.26, 0.27, 1"
2727
GitHub = "5.1, 5.2, 5.3, 5.4"
2828
GitForge = "0.4"
2929
GithubMarkdown = "0.2"

src/DocumentationGenerator.jl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,36 @@ function try_install_package(packagespec, envdir)
2929
return success
3030
end
3131

32-
function try_use_package(packagespec)
32+
function julia()
33+
return ```
34+
$(first(Base.julia_cmd()))
35+
--startup-file=no
36+
--compiled-modules=$(VERSION >= v"1.11" ? "existing" : "no")
37+
$(VERSION >= v"1.9" ? "--pkgimages=$(VERSION >= v"1.11" ? "existing" : "no")" : [])
38+
```
39+
end
40+
41+
function try_use_package(packagespec, envdir)
3342
pkg_sym = Symbol(packagespec.name)
3443

35-
pkg_module = try
36-
@eval(Main, (using $pkg_sym; $pkg_sym))
44+
cmd = ```
45+
$(julia())
46+
--project="$(envdir)"
47+
-e "using $(pkg_sym)"
48+
```
49+
50+
succeeded = try
51+
success(pipeline(addenv(cmd, "JULIA_LOAD_PATH" => nothing); stdout=stdout, stderr=stderr))
3752
catch err
38-
@error("`using $(pkg_sym) did not succeed.`", exception=err)
39-
nothing
53+
@error "using $pkgname issue" exception=(err, catch_backtrace())
54+
false
55+
end
56+
57+
if !succeeded
58+
@error("`using $(pkg_sym) did not succeed.`")
4059
end
4160

42-
return pkg_module
61+
return succeeded
4362
end
4463

4564
function build_package_docs(packagespec::Pkg.Types.PackageSpec, buildpath, registry; src_prefix="", href_prefix="")
@@ -73,7 +92,7 @@ function build_documentation(
7392
packages;
7493
processes::Int = 8,
7594
sleeptime = 0.5,
76-
juliacmd = first(Base.julia_cmd()),
95+
juliacmd = julia(),
7796
basepath = joinpath(@__DIR__, ".."),
7897
envpath = normpath(joinpath(@__DIR__, "..")),
7998
filter_versions = last,
@@ -293,14 +312,10 @@ function start_builder(package, version;
293312
Pkg.develop(path=docgen_path)
294313
Pkg.add("Pkg")
295314
## api_url needs to be set to "-", since empty string should not be passed as CLI argument
296-
pkgimagesopt = VERSION >= v"1.9" ? "--pkgimages=no" : ""
297315
cmd = ```
298316
$(juliacmd)
299317
--project=$(Base.active_project())
300318
--color=no
301-
--compiled-modules=no
302-
$(isempty(pkgimagesopt) ? [] : pkgimagesopt)
303-
-O0
304319
$workerfile
305320
$uuid
306321
$name

src/builders.jl

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function build_local_docs(packagespec, buildpath, uri, pkgroot = nothing; gitdir
103103
pkgfile = Base.find_package(pkgname)
104104
pkgroot = normpath(joinpath(pkgfile, "..", ".."))
105105
end
106-
mod = try_use_package(packagespec)
106+
could_use_pkg = try_use_package(packagespec, envdir)
107107

108108
# actual Documenter docs
109109
try
@@ -119,7 +119,7 @@ function build_local_docs(packagespec, buildpath, uri, pkgroot = nothing; gitdir
119119
"doctype" => gitdirdocs ? "git-repo" : "documenter",
120120
"documenter_errored" => documenter_errored,
121121
"installable" => true,
122-
"using_failed" => mod == nothing,
122+
"using_failed" => !could_use_pkg,
123123
"success" => true
124124
)
125125
else
@@ -139,22 +139,22 @@ function build_local_docs(packagespec, buildpath, uri, pkgroot = nothing; gitdir
139139

140140
# fallback docs (readme & docstrings)
141141
return mktempdir() do docsdir
142-
output = build_readme_docs(pkgname, pkgroot, docsdir, mod, src_prefix, href_prefix)
142+
output = build_readme_docs(pkgname, pkgroot, docsdir, src_prefix, href_prefix, could_use_pkg)
143143
if output !== nothing
144144
cp(output, buildpath, force = true)
145145
return Dict(
146146
"doctype" => "fallback_autodocs",
147147
"documenter_errored" => documenter_errored,
148148
"installable" => true,
149-
"using_failed" => mod == nothing,
149+
"using_failed" => !could_use_pkg,
150150
"success" => true
151151
)
152152
end
153153
return Dict(
154154
"doctype" => "fallback_autodocs",
155155
"documenter_errored" => documenter_errored,
156156
"installable" => true,
157-
"using_failed" => mod == nothing,
157+
"using_failed" => !could_use_pkg,
158158
"success" => false
159159
)
160160
end
@@ -206,11 +206,9 @@ function build_documenter(packagespec, docdir)
206206
_, builddir = fix_makefile(makefile)
207207
pkgimagesopt = VERSION >= v"1.9" ? "--pkgimages=no" : ""
208208
cmd = ```
209-
$(first(Base.julia_cmd()))
209+
$(julia())
210210
--project="$(docdir)"
211-
--compiled-modules=no
212211
$(isempty(pkgimagesopt) ? [] : pkgimagesopt)
213-
-O0
214212
$(rundcocumenter)
215213
$(pkgdir)
216214
$(makefile)
@@ -231,51 +229,84 @@ function build_documenter(packagespec, docdir)
231229
end
232230
end
233231

234-
function build_readme_docs(pkgname, pkgroot, docsdir, mod, src_prefix, href_prefix)
232+
function build_readme_docs(pkgname, pkgroot, docsdir, src_prefix, href_prefix, could_use_pkg)
235233
@info("Generating readme-only fallback docs.")
236234

237235
if pkgroot === nothing || !ispath(pkgroot)
238236
@error("Julia could not find the package directory. Aborting.")
239237
return
240238
end
241239

242-
pkgloads = mod !== nothing
243-
244240
readme = find_readme(pkgroot)
245241
doc_src = joinpath(docsdir, "src")
246242
mkpath(doc_src)
247243
index = joinpath(doc_src, "index.md")
248244

249245
render_html(readme, index, src_prefix, href_prefix; documenter = true)
250246

247+
pages = ["Readme" => "index.md"]
248+
249+
if could_use_pkg
250+
@info("Deploying `autodocs`.")
251+
add_autodocs(doc_src, Symbol(pkgname))
252+
push!(pages, "Docstrings" => "autodocs.md")
253+
end
254+
251255
if !isfile(index)
252256
open(index, "w") do io
253257
println(io, """
254258
# $pkgname
255259
""")
260+
261+
if !could_use_pkg
262+
println(io, """
263+
> No documentation or readme found for this package.
264+
""")
265+
end
256266
end
257267
end
258268

259-
pages = ["Readme" => "index.md"]
260-
modules = :(Module[Module()])
269+
makejl_str = """
270+
using Pkg
271+
Pkg.add(name="Documenter", version="1")
272+
Pkg.develop(path="$(pkgroot)")
261273
262-
if pkgloads
263-
@info("Deploying `autodocs`.")
264-
add_autodocs(doc_src, mod)
265-
push!(pages, "Docstrings" => "autodocs.md")
266-
modules = :(Module[$mod])
267-
end
268-
269-
@eval Module() begin
270-
const Documenter = $Documenter
271-
using .Documenter
272-
makedocs(
273-
format = Documenter.HTML(),
274-
sitename = "$($pkgname).jl",
275-
modules = $(modules),
276-
root = $(docsdir),
277-
pages = $(pages)
278-
)
274+
using Documenter
275+
using $(pkgname)
276+
277+
makedocs(
278+
format = Documenter.HTML(),
279+
sitename = "$(pkgname).jl",
280+
modules = [$(pkgname)],
281+
root = "$(docsdir)",
282+
pages = $(pages),
283+
remotes = nothing,
284+
repo = "",
285+
doctest = false
286+
)
287+
"""
288+
289+
makejl_path = joinpath(docsdir, "make.jl")
290+
291+
open(makejl_path, "w") do io
292+
println(io, makejl_str)
293+
end
294+
295+
cmd = ```
296+
$(julia())
297+
--project="$(docsdir)"
298+
$(makejl_path)
299+
```
300+
301+
succeeded = try
302+
success(pipeline(addenv(cmd, "JULIA_LOAD_PATH" => nothing); stdout=stdout, stderr=stderr))
303+
catch err
304+
@error "autodocs $pkgname issue" exception=(err, catch_backtrace())
305+
false
306+
end
307+
308+
if !succeeded
309+
@error("Failed to generate readme autodocs for $pkgname")
279310
end
280311

281312
build_dir = joinpath(docsdir, "build")
@@ -308,11 +339,10 @@ function find_readme(pkgroot)
308339
end
309340

310341
function add_autodocs(docsdir, mod)
311-
module_list = join((string(m) for m in submodules(mod)), ", ")
312342
open(joinpath(docsdir, "autodocs.md"), "w") do io
313343
println(io, """
314344
```@autodocs
315-
Modules = [$module_list]
345+
Modules = [$mod]
316346
```
317347
""")
318348
end

src/rundocumenter.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,37 @@ let anonymous_module = Module()
2727
end
2828
Pkg.status()
2929

30-
documenter_version = v"0.24.10"
30+
documenter_version = v"1.8.1"
3131
try
3232
manifest = joinpath(docsdir, "Manifest.toml")
3333
if isfile(manifest)
3434
pm = TOML.parsefile(manifest)
35-
global documenter_version = VersionNumber(first(pm["Documenter"])["version"])
35+
if VersionNumber(get(pm, "manifest_format", "1.0")) > v"1"
36+
deps = pm["deps"]
37+
else
38+
deps = pm
39+
end
40+
if haskey(deps, "Documenter")
41+
documenter_version = VersionNumber(first(deps["Documenter"])["version"])
42+
else
43+
@warn("Documenter not found in `$(manifest). Defaulting to $(documenter_version).")
44+
end
3645
else
3746
@warn("No Mainfest.toml found at `$(manifest)`. Defaulting to $(documenter_version).")
3847
end
3948
catch err
4049
@error(exception = err)
4150
end
4251

43-
@info("Detected Documenter version $(documenter_version).")
52+
@info("Using Documenter version $(documenter_version).")
4453

4554
expr, bpath = fix_makefile(makefile, documenter_version)
4655

4756
@info("`cd`ing to `$(docsdir)` and setting `tls[:SOURCE_PATH]` to `$(makefile)`.")
4857
task_local_storage()[:SOURCE_PATH] = makefile
4958
cd(docsdir) do
5059
@info("Evaluating the following `make` expr:")
51-
@info(expr)
60+
println(stderr, "\n------------------\n", expr, "\n------------------\n")
5261
Base.eval(Main, expr)
5362
end
5463
end

src/utils/rewrite.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Takes in the path to a Documenter.jl-compatible `make.jl` file and
2424
2525
Return a tuple of `new_make_expr, buildpath`.
2626
"""
27-
function fix_makefile(makefile, documenter_version = v"0.24")
27+
function fix_makefile(makefile, documenter_version = v"1.8.1")
2828
# default output path:
2929
buildpath = joinpath(dirname(makefile), "build")
3030
should_break = false
@@ -56,7 +56,7 @@ function fix_makefile(makefile, documenter_version = v"0.24")
5656
fixkwarg = argument -> begin
5757
if Meta.isexpr(argument, :kw)
5858
name, arg = argument.args
59-
# assure that we generate HTML
59+
# ensure that we generate HTML
6060
if name == :format
6161
has_fmt = true
6262
if Meta.isexpr(arg, :call) && arg.args[1] == :(Documenter.HTML) && !(html isa QuoteNode)
@@ -123,25 +123,22 @@ function fix_makefile(makefile, documenter_version = v"0.24")
123123
if !has_fmt
124124
push!(new_args, Expr(:kw, :format, html))
125125
end
126-
127126
if !has_linkcheck
128127
push!(new_args, Expr(:kw, :linkcheck, false))
129128
end
130-
131129
if !has_doctest
132130
push!(new_args, Expr(:kw, :doctest, false))
133131
end
134-
135132
if !has_root
136133
push!(new_args,Expr(:kw, :root, dirname(makefile)))
137134
end
138-
if !has_remotes
135+
if !has_remotes && documenter_version >= v"1"
139136
push!(new_args, Expr(:kw, :remotes, nothing))
140137
end
141138
if !has_repo
142139
push!(new_args, Expr(:kw, :repo, ""))
143140
end
144-
if !has_warnonly
141+
if !has_warnonly && documenter_version >= v"1"
145142
push!(new_args, Expr(:kw, :warnonly, true))
146143
end
147144

0 commit comments

Comments
 (0)