-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_reference.jl
More file actions
330 lines (314 loc) · 15.2 KB
/
api_reference.jl
File metadata and controls
330 lines (314 loc) · 15.2 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# ==============================================================================
# CTModels API Reference Generator
# ==============================================================================
#
# This module provides functions to generate API reference documentation
# for CTModels.jl, following the pattern established in CTBase.jl.
#
# ==============================================================================
"""
generate_api_reference(src_dir::String, ext_dir::String)
Generate the API reference documentation for CTModels.
Returns the list of pages.
"""
function generate_api_reference(src_dir::String, ext_dir::String)
# Helper to build absolute paths
src(files...) = [abspath(joinpath(src_dir, f)) for f in files]
ext(files...) = [abspath(joinpath(ext_dir, f)) for f in files]
# Symbols to exclude from documentation
EXCLUDE_SYMBOLS = Symbol[
:include,
:eval,
Symbol("@pack_PreModel"),
Symbol("@pack_PreModel!"),
Symbol("@unpack_PreModel"),
:is_empty,
:time_ns,
]
CTModelsPlots = Base.get_extension(CTModels, :CTModelsPlots)
CTModelsJSON = Base.get_extension(CTModels, :CTModelsJSON)
CTModelsJLD = Base.get_extension(CTModels, :CTModelsJLD)
pages = [
# ───────────────────────────────────────────────────────────────────
# Utils
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.Utils => src(
joinpath("Utils", "Utils.jl"),
joinpath("Utils", "macros.jl"),
joinpath("Utils", "interpolation.jl"),
joinpath("Utils", "matrix_utils.jl"),
joinpath("Utils", "function_utils.jl"),
),
],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="Utils",
title_in_menu="Utils",
filename="api_utils",
),
# ───────────────────────────────────────────────────────────────────
# OCP - Types
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.OCP => src(
joinpath("OCP", "aliases.jl"),
joinpath("OCP", "Types", "components.jl"),
joinpath("OCP", "Types", "model.jl"),
joinpath("OCP", "Types", "solution.jl"),
),
],
external_modules_to_document=[CTModels],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="OCP - Types",
title_in_menu="OCP Types",
filename="api_ocp_types",
),
# ───────────────────────────────────────────────────────────────────
# OCP - Components
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.OCP => src(
joinpath("OCP", "Components", "state.jl"),
joinpath("OCP", "Components", "control.jl"),
joinpath("OCP", "Components", "variable.jl"),
joinpath("OCP", "Components", "times.jl"),
joinpath("OCP", "Components", "dynamics.jl"),
joinpath("OCP", "Components", "objective.jl"),
joinpath("OCP", "Components", "constraints.jl"),
),
],
external_modules_to_document=[CTModels],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="OCP - Components",
title_in_menu="OCP Components",
filename="api_ocp_components",
),
# ───────────────────────────────────────────────────────────────────
# OCP - Building
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.OCP => src(
joinpath("OCP", "Building", "model.jl"),
joinpath("OCP", "Building", "solution.jl"),
joinpath("OCP", "Building", "interpolation_helpers.jl"),
joinpath("OCP", "Building", "discretization_utils.jl"),
joinpath("OCP", "Building", "dual_model.jl"),
joinpath("OCP", "Building", "definition.jl"),
),
],
external_modules_to_document=[CTModels],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="OCP - Building",
title_in_menu="OCP Building",
filename="api_ocp_building",
),
# ───────────────────────────────────────────────────────────────────
# OCP - Core & Validation
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.OCP => src(
joinpath("OCP", "Core", "defaults.jl"),
joinpath("OCP", "Core", "time_dependence.jl"),
joinpath("OCP", "Validation", "name_validation.jl"),
),
],
external_modules_to_document=[CTModels],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="OCP - Core & Validation",
title_in_menu="OCP Core",
filename="api_ocp_core",
),
# ───────────────────────────────────────────────────────────────────
# Display
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.Display => src(
joinpath("Display", "Display.jl"),
joinpath("Display", "print.jl"),
),
CTModelsPlots => ext(
"CTModelsPlots.jl",
"plot.jl",
"plot_utils.jl",
"plot_default.jl",
),
],
external_modules_to_document=[Plots],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="Display, Plots",
title_in_menu="Display, Plots",
filename="api_display",
),
# ───────────────────────────────────────────────────────────────────
# Serialization
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.Serialization => src(
joinpath("Serialization", "Serialization.jl"),
joinpath("Serialization", "export_import.jl"),
joinpath("Serialization", "types.jl"),
),
CTModelsJSON => ext("CTModelsJSON.jl"),
CTModelsJLD => ext("CTModelsJLD.jl"),
],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="Serialization, JSON & JLD2",
title_in_menu="Serialization, JSON & JLD2",
filename="api_serialization",
),
# ───────────────────────────────────────────────────────────────────
# InitialGuess
# ───────────────────────────────────────────────────────────────────
CTBase.automatic_reference_documentation(;
subdirectory=".",
primary_modules=[
CTModels.InitialGuess => src(
joinpath("InitialGuess", "InitialGuess.jl"),
joinpath("InitialGuess", "types.jl"),
joinpath("InitialGuess", "api.jl"),
joinpath("InitialGuess", "builders.jl"),
joinpath("InitialGuess", "state.jl"),
joinpath("InitialGuess", "control.jl"),
joinpath("InitialGuess", "variable.jl"),
joinpath("InitialGuess", "validation.jl"),
joinpath("InitialGuess", "utils.jl"),
),
],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=true,
title="InitialGuess",
title_in_menu="InitialGuess",
filename="api_initial_guess",
),
]
# ───────────────────────────────────────────────────────────────────
# Extensions (conditional)
# ───────────────────────────────────────────────────────────────────
# # CTModelsPlots extension
# CTModelsPlots = Base.get_extension(CTModels, :CTModelsPlots)
# if !isnothing(CTModelsPlots)
# push!(
# pages,
# CTBase.automatic_reference_documentation(;
# subdirectory=".",
# primary_modules=[
# CTModelsPlots => ext("plot.jl", "plot_utils.jl", "plot_default.jl")
# ],
# external_modules_to_document=[CTModels],
# exclude=EXCLUDE_SYMBOLS,
# public=true,
# private=true,
# title="CTModelsPlots",
# title_in_menu="Plots Extension",
# filename="api_plots_extension",
# ),
# )
# end
# # CTModelsJSON extension
# CTModelsJSON = Base.get_extension(CTModels, :CTModelsJSON)
# if !isnothing(CTModelsJSON)
# push!(
# pages,
# CTBase.automatic_reference_documentation(;
# subdirectory=".",
# primary_modules=[CTModelsJSON => ext("CTModelsJSON.jl")],
# external_modules_to_document=[CTModels],
# exclude=EXCLUDE_SYMBOLS,
# public=true,
# private=true,
# title="CTModelsJSON",
# title_in_menu="JSON Extension",
# filename="api_json_extension",
# ),
# )
# end
# # CTModelsJLD extension
# CTModelsJLD = Base.get_extension(CTModels, :CTModelsJLD)
# if !isnothing(CTModelsJLD)
# push!(
# pages,
# CTBase.automatic_reference_documentation(;
# subdirectory=".",
# primary_modules=[CTModelsJLD => ext("CTModelsJLD.jl")],
# external_modules_to_document=[CTModels],
# exclude=EXCLUDE_SYMBOLS,
# public=true,
# private=true,
# title="CTModelsJLD",
# title_in_menu="JLD2 Extension",
# filename="api_jld_extension",
# ),
# )
# end
return pages
end
"""
with_api_reference(f::Function, src_dir::String, ext_dir::String)
Generates the API reference, executes `f(pages)`, and cleans up generated files.
"""
function with_api_reference(f::Function, src_dir::String, ext_dir::String)
pages = generate_api_reference(src_dir, ext_dir)
try
f(pages)
finally
# Clean up generated files
# The pages are Pairs: "Title" => "filename.md" (relative to build? no, relative to src)
# automatic_reference_documentation returns "filename" which is relative to docs/src if subdirectory="."
# We need to reconstruct the full path to delete them.
# Assuming they are in docs/src (which is where makedocs runs from?)
# Wait, makedocs options say subdirectory=".".
# Typically automatic_reference_documentation writes to joinpath(@__DIR__, "src", subdirectory, filename.md) ??
# I need to check where automatic_reference_documentation writes.
# Assuming we are running from docs/ (where make.jl is).
# Let's assume the files are in `docs/src`.
docs_src = abspath(joinpath(@__DIR__, "src"))
function cleanup_pages(pages)
for p in pages
content = last(p)
if content isa AbstractString
# file path
filename = content
fname = endswith(filename, ".md") ? filename : filename * ".md"
full_path = joinpath(docs_src, fname)
if isfile(full_path)
rm(full_path)
println("Removed temporary API doc: $full_path")
end
elseif content isa Vector
# nested pages
cleanup_pages(content)
end
end
end
cleanup_pages(pages)
end
end