Skip to content

Commit 1480be1

Browse files
committed
Documentation improvements: build method, docstrings, and cross-references
docs/make.jl: - Changed from Pkg.activate/instantiate to pushfirst!(LOAD_PATH, ...) for faster builds src/Exceptions/types.jl: - Added $(TYPEDEF) macro to ExtensionError and SolverFailure - Simplified docstrings to focus on core functionality - Moved constructor throws to # Throws section - Consolidated examples and removed redundant sections - Added cross-references to related exception types src/Extensions/Extensions.jl: - Added example code blocks for CoveragePostprocessingTag, AbstractTestRunnerTag, TestRunnerTag - Fixed cross-references from CTBase.* to CTBase.Extensions.* docs/: - Updated guide files and index - Added getting-started.md - Updated Project.toml and README.md All tests pass: 1161/1161 Documentation builds successfully
1 parent ea408a8 commit 1480be1

20 files changed

Lines changed: 469 additions & 489 deletions

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
23
Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
34
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
45
MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"

docs/README.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,29 @@ The documentation is built using [Documenter.jl](https://github.com/JuliaDocs/Do
88

99
## Building the Documentation
1010

11-
There are several ways to build the documentation locally.
12-
13-
### 1. Terminal One-Liner (Recommended)
14-
15-
From the root of the `CTBase.jl` repository, run:
11+
From the root of the repository:
1612

1713
```bash
18-
julia --project=docs/ -e 'using Pkg; Pkg.develop(path=pwd()); include("docs/make.jl"); Pkg.rm("CTBase")'
14+
julia --project=. docs/make.jl
1915
```
2016

21-
This command:
22-
- Activates the `docs` project environment.
23-
- Temporarily "develops" the current package so changes are reflected in the build.
24-
- Executes `make.jl` to build the site.
25-
- Cleans up the `docs` environment by removing the temporary link to `CTBase`.
26-
27-
### 2. Manual REPL Build
17+
`make.jl` prepends both `docs/` and the package root to `LOAD_PATH`, so the package
18+
project is picked up automatically — no `Pkg.develop` step needed.
2819

29-
If you prefer working inside the Julia REPL:
20+
### Draft mode (fast link validation)
3021

31-
```julia
32-
# 1. Activate the docs project
33-
using Pkg
34-
Pkg.activate("docs/")
22+
Set `draft = true` at the top of `docs/make.jl` to skip `@repl`/`@example` block
23+
execution. This is much faster when iterating on cross-references and page structure:
3524

36-
# 2. Add CTBase in development mode (if not already done)
37-
Pkg.develop(path=pwd())
38-
39-
# 3. Build the documentation
40-
include("docs/make.jl")
25+
```bash
26+
# edit docs/make.jl: draft = true (line 16)
27+
julia --project=. docs/make.jl
4128
```
4229

30+
!!! note "warnonly"
31+
`make.jl` uses `warnonly=[:cross_references]`, so cross-reference warnings do not
32+
abort the build. Other errors (missing pages, broken `@repl` blocks) still fail.
33+
4334
## Viewing the Documentation
4435

4536
After a successful build, the generated HTML files are located in `docs/build/`. You can open `index.html` in your browser:
@@ -54,7 +45,7 @@ xdg-open docs/build/index.html
5445

5546
## Directory Structure
5647

57-
- `src/`: Contains the manual markdown files (Introduction, Tutorials, etc.).
48+
- `src/`: Contains the manual markdown files (Introduction, Getting Started, Guides, etc.).
5849
- `make.jl`: The main build script for Documenter.
5950
- `api_reference.jl`: Contains the logic for automatic API reference generation. It extracts docstrings from the source code and creates temporary markdown files.
6051
- `build/`: The directory where the static website is generated (ignored by git).

docs/make.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Pkg
2-
Pkg.activate(@__DIR__)
3-
Pkg.develop(PackageSpec(; path=joinpath(@__DIR__, "..")))
4-
Pkg.instantiate()
1+
# to run the documentation generation:
2+
# julia --project=. docs/make.jl
3+
pushfirst!(LOAD_PATH, joinpath(@__DIR__))
4+
pushfirst!(LOAD_PATH, joinpath(@__DIR__, ".."))
55

66
using Documenter
77
using CTBase
@@ -54,7 +54,7 @@ with_api_reference(src_dir) do api_pages
5454
makedocs(;
5555
draft=draft,
5656
remotes=nothing, # Disable remote links. Needed for DocumenterReference
57-
warnonly=true,
57+
warnonly=[:cross_references],
5858
sitename="CTBase.jl",
5959
format=Documenter.HTML(;
6060
repolink="https://" * repo_url,
@@ -67,6 +67,7 @@ with_api_reference(src_dir) do api_pages
6767
),
6868
pages=[
6969
"Introduction" => "index.md",
70+
"Getting Started" => "getting-started.md",
7071
"User Guides" => [
7172
"Descriptions" => joinpath("guide", "descriptions.md"),
7273
"Exceptions" => joinpath("guide", "exceptions.md"),

docs/src/getting-started.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
```@meta
2+
CurrentModule = CTBase
3+
```
4+
5+
# Getting Started
6+
7+
## Installation
8+
9+
CTBase.jl is typically installed as a dependency of another package in the ecosystem
10+
(e.g. [OptimalControl.jl](https://github.com/control-toolbox/OptimalControl.jl)).
11+
To install it directly:
12+
13+
```julia
14+
import Pkg
15+
Pkg.add("CTBase")
16+
```
17+
18+
**Requires Julia ≥ 1.10.**
19+
20+
## Mental Model
21+
22+
CTBase is the **base layer** of the control-toolbox ecosystem.
23+
It provides infrastructure shared by every package above it.
24+
25+
Three things to keep in mind:
26+
27+
1. **No top-level exports.** `using CTBase` loads the package but brings no symbols
28+
into scope. Every symbol is accessed via its qualified path:
29+
```julia
30+
CTBase.Descriptions.add # ✓ always works
31+
CTBase.Exceptions.NotImplemented
32+
```
33+
2. **Submodule-first API.** The public API lives in named submodules
34+
(`Descriptions`, `Exceptions`, `Extensions`, `Core`, `Unicode`).
35+
You can bring a submodule's exports into scope explicitly:
36+
```julia
37+
using CTBase.Exceptions # brings IncorrectArgument, NotImplemented, … into scope
38+
```
39+
3. **Extension-backed features.** `run_tests`, `postprocess_coverage`, and
40+
`automatic_reference_documentation` require loading the matching weak dependency
41+
(`Test`, `Coverage`, `Documenter` respectively) before they become active.
42+
43+
## 5-Minute Walkthrough
44+
45+
### Working with Descriptions
46+
47+
A *description* is a `Tuple` of `Symbol`s that declaratively identifies an algorithm
48+
or configuration. Catalogues collect known descriptions; `complete` resolves a partial
49+
description to an exact one.
50+
51+
```@repl walkthrough
52+
using CTBase
53+
54+
# Build a catalogue
55+
descs = CTBase.Descriptions.add((), (:euler, :explicit))
56+
descs = CTBase.Descriptions.add(descs, (:euler, :implicit))
57+
descs = CTBase.Descriptions.add(descs, (:runge_kutta, :explicit))
58+
59+
# Partial completion: find the unique entry containing :implicit
60+
CTBase.Descriptions.complete(:implicit; descriptions=descs)
61+
62+
# Ambiguous completion raises AmbiguousDescription
63+
try
64+
CTBase.Descriptions.complete(:euler; descriptions=descs)
65+
catch e
66+
println(typeof(e))
67+
end
68+
```
69+
70+
For more, see the **[Descriptions guide](guide/descriptions.md)**.
71+
72+
### Working with Exceptions
73+
74+
CTBase defines a typed exception hierarchy rooted at
75+
[`CTBase.Exceptions.CTException`](@ref).
76+
Each type carries structured context fields for actionable error messages.
77+
78+
```@repl walkthrough
79+
# IncorrectArgument — invalid input value
80+
try
81+
throw(CTBase.Exceptions.IncorrectArgument(
82+
"state dimension must be positive";
83+
got="0",
84+
expected="n > 0",
85+
suggestion="Pass a positive integer for the state dimension",
86+
))
87+
catch e
88+
println(e)
89+
end
90+
91+
# NotImplemented — interface stub
92+
try
93+
throw(CTBase.Exceptions.NotImplemented(
94+
"solve! is not implemented";
95+
required_method="solve!(::MyStrategy, ocp)",
96+
suggestion="Import the package that provides this strategy",
97+
))
98+
catch e
99+
println(typeof(e))
100+
end
101+
```
102+
103+
For more, see the **[Exceptions guide](guide/exceptions.md)**.
104+
105+
## Next Steps
106+
107+
| Topic | Guide |
108+
|:---|:---|
109+
| Descriptions catalogue and completion | [Descriptions](guide/descriptions.md) |
110+
| Exception hierarchy and best practices | [Exceptions](guide/exceptions.md) |
111+
| Modular test runner setup | [Test Runner](guide/test-runner.md) |
112+
| Coverage report generation | [Coverage](guide/coverage.md) |
113+
| Auto-generated API reference | [API Documentation](guide/api-documentation.md) |
114+
| Full API reference | API Reference (left sidebar) |

docs/src/guide/api-documentation.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
```@meta
2+
CurrentModule = CTBase
3+
```
4+
15
# API Documentation Guide
26

37
This guide explains how to set up automated API reference documentation generation using the **DocumenterReference** extension of `CTBase.jl`. This is particularly useful for maintaining comprehensive and up-to-date API documentation as your codebase evolves.
48

59
## Overview
610

7-
The `DocumenterReference` extension provides the `CTBase.automatic_reference_documentation()` function, which automatically generates API reference pages from your Julia source code. It:
11+
The `DocumenterReference` extension provides the [`CTBase.automatic_reference_documentation`](@ref) function, which automatically generates API reference pages from your Julia source code. It:
812

913
- Extracts docstrings from your modules
1014
- Separates public and private APIs

docs/src/guide/coverage.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
```@meta
2+
CurrentModule = CTBase
3+
```
4+
15
# Coverage Post-processing Guide
26

37
This guide explains how to generate human-readable and machine-parseable coverage reports using the **CoveragePostprocessing** extension of `CTBase.jl`.
@@ -25,14 +29,15 @@ To generate actionable coverage reports, we use a dedicated `coverage.jl` script
2529
pushfirst!(LOAD_PATH, @__DIR__)
2630

2731
using Pkg
28-
using CTBase # Provides postprocess_coverage
32+
using CTBase # Provides CTBase.postprocess_coverage
2933
using Coverage
3034

3135
# This function:
3236
# 1. Aggregates coverage data.
3337
# 2. Generates an LCOV file (coverage/lcov.info).
3438
# 3. Generates a markdown summary (coverage/cov_report.md).
3539
# 4. Archives used .cov files to keep the directory clean.
40+
# See: CTBase.postprocess_coverage
3641
CTBase.postprocess_coverage(;
3742
root_dir=dirname(@__DIR__) # Point to the package root
3843
)

0 commit comments

Comments
 (0)