-
Notifications
You must be signed in to change notification settings - Fork 126
/
make_work.jl
217 lines (191 loc) · 7.05 KB
/
make_work.jl
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
# This file is included by docs/make.jl and by a helper function
# in src/utils/docs.jl
#
module BuildDoc
using Documenter, DocumenterCitations
include("documenter_helpers.jl")
include("citation_style.jl")
# Overwrite printing to make the header not full of redundant nonsense
# Turns
# Hecke.Order - Method
# into
# Order - Method
# To remove the '-'
# Documenter.Utilities.print_signature(io::IO, signature) = print(io, signature)
# To remove the "Method", "Type", "Module" use the following
# Documenter.Utilities.doccat(b::Base.Docs.Binding, ::Type) = ""
# doccat(::Type) = ""
# doccat(::Module) = ""
# Remove the module prefix
Base.print(io::IO, b::Base.Docs.Binding) = print(io, b.var)
# When we read a `doc.main` from an experimental package, we need to equip all
# its entries with a prefix to fit with our docs. The doc.main of an
# experimental package will contain paths relative to
# `experimental/PACKAGE_NAME/docs/src`. When generating the docs a symlink is
# set in `docs/src/Experimental/PACKAGE_NAME` pointing to
# `experimental/PACKAGE_NAME/docs/src`. Hence the paths in `doc.main` need to
# get the prefix `Experimental/PACKAGE_NAME`.
#
# Example:
# 1. cat experimental/PlaneCurve/docs/doc.main:
# [
# "plane_curves.md",
# ]
# after `add_prefix_to_experimental_docs` becomes
# [
# "Experimental/PlaneCurve/plane_curves.md",
# ]
#
# 2. cat experimental/FTheoryTools/docs/doc.main
# [
# "F-Theory Tools" => [
# "introduction.md",
# "weierstrass.md",
# "tate.md",
# ],
# ]
# after `add_prefix_to_experimental_docs` becomes
# [
# "F-Theory Tools" => [
# "Experimental/FTheoryTools/introduction.md",
# "Experimental/FTheoryTools/weierstrass.md",
# "Experimental/FTheoryTools/tate.md",
# ],
# ]
#
# Since the entries of a `doc.main` vary in type, we have split this up into
# three functions.
add_prefix_to_experimental_docs(Oscar::Module, docs::String, prefix::String) = joinpath(prefix, docs)
add_prefix_to_experimental_docs(Oscar::Module, docs::Pair{String,String}, prefix::String) = Pair{String,String}(docs.first, add_prefix_to_experimental_docs(Oscar, docs.second, prefix))
add_prefix_to_experimental_docs(Oscar::Module, docs::Pair{String, Vector{T}}, prefix::String) where T = Pair{String, Vector{T}}(docs.first, add_prefix_to_experimental_docs(Oscar, docs.second, prefix))
add_prefix_to_experimental_docs(Oscar::Module, docs::Vector{T}, prefix::String) where T = T[add_prefix_to_experimental_docs(Oscar, entry, prefix) for entry in docs]
function setup_experimental_package(Oscar::Module, package_name::String)
doc_main_path = joinpath(Oscar.oscardir, "experimental", package_name, "docs/doc.main")
if !isfile(doc_main_path)
return []
end
# Assumes that a symbolic link from `experimental/package_name/docs/src`
# to `docs/src/Experimental/package_name` has been created (or there is no
# documentation for this package)
if !ispath(joinpath(Oscar.oscardir, "docs/src/Experimental", package_name))
return []
end
# Read doc.main of package
exp_s = read(doc_main_path, String)
exp_doc = eval(Meta.parse(exp_s))
# Prepend path
prefix = "Experimental/" * package_name * "/"
result = add_prefix_to_experimental_docs(Oscar, exp_doc, prefix)
return result
end
function doit(
Oscar::Module;
warnonly=false,
local_build::Bool=false,
doctest::Union{Bool,Symbol}=true,
)
# include the list of pages, performing substitutions
s = read(joinpath(Oscar.oscardir, "docs", "doc.main"), String)
doc = eval(Meta.parse(s))
# Link experimental docs to `docs/src` and collect the documentation pages
Oscar.link_experimental_docs()
collected = Any["Experimental/intro.md"]
for pkg in Oscar.exppkgs
pkgdocs = setup_experimental_package(Oscar, pkg)
if length(pkgdocs) > 0
append!(collected, pkgdocs)
end
end
push!(doc, ("Experimental" => collected))
# Load the bibliography
bib = CitationBibliography(
joinpath(Oscar.oscardir, "docs", "oscar_references.bib"); style=oscar_style
)
# Copy documentation from Hecke, Nemo, AbstractAlgebra
other_packages = [
(Oscar.Hecke, Oscar.heckedir),
(Oscar.Nemo, Oscar.nemodir),
(Oscar.AbstractAlgebra, Oscar.aadir),
]
for (pkg, pkgdir) in other_packages
srcbase = normpath(pkgdir, "docs", "src")
dstbase = normpath(Oscar.oscardir, "docs", "src", string(nameof(pkg)))
# clear the destination directory first
rm(dstbase; recursive=true, force=true)
for (root, dirs, files) in walkdir(srcbase)
for dir in dirs
d = normpath(dstbase, relpath(root, srcbase), dir)
mkpath(d)
end
for file in files
# HACK: delete Hecke's bibliography, to avoid warnings of the
# form "Warning: 'Eis95' is not unique" which actually turn into
# errors down the road
if file == "references.md"
continue
end
src = normpath(root, file)
dst = normpath(dstbase, relpath(root, srcbase), file)
if endswith(file, ".md")
symlink(src, dst)
else
cp(src, dst; force=true)
end
chmod(dst, 0o644)
end
end
end
function get_rev(uuid::Base.UUID)
deps = Documenter.Pkg.dependencies()
@assert haskey(deps, uuid)
if !isnothing(deps[uuid].git_revision)
return deps[uuid].git_revision
else
return "v$(deps[uuid].version)"
end
end
aarev = get_rev(Base.PkgId(Oscar.AbstractAlgebra).uuid)
nemorev = get_rev(Base.PkgId(Oscar.Nemo).uuid)
heckerev = get_rev(Base.PkgId(Oscar.Hecke).uuid)
singularrev = get_rev(Base.PkgId(Oscar.Singular).uuid)
cd(joinpath(Oscar.oscardir, "docs")) do
DocMeta.setdocmeta!(Oscar, :DocTestSetup, Oscar.doctestsetup(); recursive=true)
DocMeta.setdocmeta!(Oscar.Hecke, :DocTestSetup, :(using Hecke); recursive=true)
DocMeta.setdocmeta!(Oscar.AbstractAlgebra, :DocTestSetup, :(using AbstractAlgebra); recursive=true)
DocMeta.setdocmeta!(Oscar.Nemo, :DocTestSetup, :(using Nemo); recursive=true)
if doctest !== false
Documenter.doctest(Oscar, fix = doctest === :fix)
end
makedocs(;
format=Documenter.HTML(;
prettyurls=!local_build,
collapselevel=1,
size_threshold=409600,
size_threshold_warn=204800,
size_threshold_ignore=["manualindex.md"],
),
sitename="Oscar.jl",
modules=[Oscar, Oscar.Hecke, Oscar.Nemo, Oscar.AbstractAlgebra, Oscar.Singular],
clean=true,
doctest=false,
warnonly=warnonly,
checkdocs=:none,
pages=doc,
remotes=Dict(
Oscar.aadir => (Remotes.GitHub("Nemocas", "AbstractAlgebra.jl"), aarev),
Oscar.nemodir => (Remotes.GitHub("Nemocas", "Nemo.jl"), nemorev),
Oscar.heckedir => (Remotes.GitHub("thofma", "Hecke.jl"), heckerev),
Oscar.singulardir => (Remotes.GitHub("oscar-system", "Singular.jl"), singularrev),
),
plugins=[bib],
)
end
# remove the copied documentation again
for (pkg, pkgdir) in other_packages
dstbase = normpath(Oscar.oscardir, "docs", "src", string(nameof(pkg)))
rm(dstbase; recursive=true, force=true)
end
end
end # module BuildDoc
using .BuildDoc