Skip to content

Commit 3a3a1ad

Browse files
authored
Merge pull request #16 from openscm/FORD_play
Added documentation of the Fortran back-end/API using [ford](https://forddocs.readthedocs.io/en/stable/). Integrated the generated FORD docs into MkDocs so that the overall documentation is unified, searchable, and easy to navigate. The combined result looks solid.
2 parents c17a0cb + 669b40d commit 3a3a1ad

File tree

14 files changed

+211
-2
lines changed

14 files changed

+211
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ jobs:
3939
with:
4040
python-version: ${{ matrix.python-version }}
4141
uv-dependency-install-flags: "--all-extras --group docs"
42+
- name: Install Graphviz
43+
run: |
44+
sudo apt-get update
45+
sudo apt-get install -y graphviz
4246
- name: docs
4347
run: |
4448
uv run --no-sync mkdocs build --strict

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ docs/fgen/api/*
1717
!docs/fgen/api/.gitkeep
1818
docs/fgen-runtime/api/*
1919
!docs/fgen-runtime/api/.gitkeep
20+
docs/fortran-api/*
21+
!docs/fortran-api/.gitkeep
2022

2123
# Databases
2224
*.db

changelog/16.docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added documentation of the Fortran back-end/API using [ford](https://forddocs.readthedocs.io/en/stable/)

docs/NAVIGATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ See https://oprypin.github.io/mkdocs-literate-nav/
1313
- [Dependency pinning and testing](further-background/dependency-pinning-and-testing.md)
1414
- [Development](development.md)
1515
- [API reference](api/example_fgen_basic/)
16+
- [Fortran API](fortran-api/home.html)
1617
- [Changelog](changelog.md)

docs/development.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ Try and keep your merge requests as small as possible
3131
This makes life much easier for reviewers
3232
which allows contributions to be accepted at a faster rate.
3333

34+
## Using uv with a compiled package
35+
36+
Using uv with a compiled package is a bit more painful.
37+
Whenever you do `uv run` or `uv sync` or similar,
38+
uv tries to install the compiled package as an editable package.
39+
This can then cause issues on later calls to `uv run` or `uv sync`
40+
as having compiled packages as editable packages doesn't really work
41+
(you get errors like
42+
`ImportError: re-building the <package-name> meson-python editable wheel package failed`).
43+
The way around this is to:
44+
45+
1. use the `--no-editable` flag with `uv sync`
46+
so that uv doesn't do an editable install
47+
1. use the `--no-sync` flag with `uv run`
48+
(and any other command that takes this flag)
49+
so that `uv` doesn't try and re-build packages
50+
1. use the `--reinstall-package` flag with `uv run`
51+
whenever you want to be sure that the latest changes
52+
will be used for running a command
53+
(yes, this makes running things slower,
54+
but slower and reliable is better than broken)
55+
56+
We include these flags in our `Makefile` and GitHub workflows
57+
if you want to see them in use.
58+
59+
If you forget and run `uv run ...` in your terminal.
60+
The easiest solution seems to be to delete your virtual environment entirely and start again.
61+
We haven't found a way to get out of an accidental editable install.
62+
3463
## Language
3564

3665
We use British English for our development.

docs/fortran-api/.gitkeep

Whitespace-only changes.

docs/gen_fortran_api.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Drive Ford to create Fortran API docs
3+
"""
4+
5+
from __future__ import annotations
6+
7+
import shutil
8+
import subprocess
9+
from pathlib import Path
10+
11+
import mkdocs_gen_files
12+
13+
REPO_ROOT = Path(__file__).parents[1]
14+
15+
FORD_OUTPUT_DIR = Path("docs") / "fortran-api"
16+
17+
ford = shutil.which("ford")
18+
if ford is None:
19+
msg = "Could not find FORD executable"
20+
raise AssertionError(msg)
21+
22+
subprocess.run( # noqa: S603
23+
[ford, "ford_config.md", "--output_dir", str(FORD_OUTPUT_DIR)],
24+
check=True,
25+
)
26+
27+
# Copy files across using mkdocs_gen_files
28+
# so it knows to include the files in the final docs.
29+
for entry in (REPO_ROOT / FORD_OUTPUT_DIR).rglob("*"):
30+
if not entry.is_file():
31+
continue
32+
33+
with open(entry, "rb") as fh:
34+
contents = fh.read()
35+
36+
target_file = entry.relative_to(REPO_ROOT / "docs")
37+
with mkdocs_gen_files.open(target_file, "wb") as fh:
38+
fh.write(contents)
39+
40+
if target_file.name == "index.html":
41+
# Also create a home.html file which we can point to from `NAVIGATION.md`.
42+
# I don't know why just pointing to `index.html` doesn't work,
43+
# but it doesn't (maybe cause `index.html` is a special name?).
44+
target_file = target_file.parent / "home.html"
45+
46+
with mkdocs_gen_files.open(target_file, "wb") as fh:
47+
fh.write(contents)
48+
49+
# # If we want to move back to using literate-nav for maanging our navigation,
50+
# # also for the Fortran bits, we'll need something like the below
51+
# # and adjustments to the existing `NAVIGATION.md`.
52+
# with mkdocs_gen_files.open(
53+
# (FORD_OUTPUT_DIR).relative_to("docs") / "NAVIGATION.md", "w"
54+
# ) as fh:
55+
# fh.writelines("* [example_fgen_basic](home.html)")
56+
57+
# Remove the ford files (which were just copied)
58+
shutil.rmtree(REPO_ROOT / FORD_OUTPUT_DIR)
59+
60+
# Put back the gitkeep file
61+
gitkeep = REPO_ROOT / FORD_OUTPUT_DIR / ".gitkeep"
62+
gitkeep.parent.mkdir()
63+
gitkeep.touch()

docs/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
---8<--- "README.md:description"
2+
3+
## API docs
4+
5+
Our Python API is documented in [API][example_fgen_basic_1].
6+
The Fortran API is documented in [Fortran API](./fortran-api/).
7+
At present, the Fortran API docs are a sub-website so you can navigate to them
8+
but there are no buttons to navigate back to the main docs page
9+
(so you have to instead return yourself by re-entering the URL
10+
or pressing back, sorry, we hope to improve this in future).

environment-docs-conda-base.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ dependencies:
99
- pip
1010
- gcc
1111
- gfortran
12+
- graphviz

ford_config.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
project: Example fgen - basic
3+
author: TODO align this with pyproject.toml
4+
src_dir: src
5+
graph: true
6+
---
7+
8+
API docs for Fortran components!

0 commit comments

Comments
 (0)