Skip to content

Commit 0a76877

Browse files
authored
Merge pull request #319 from xinan1911/apidocs
Generate api docs for EESSI test suite
2 parents c75a8ad + 2597103 commit 0a76877

7 files changed

Lines changed: 124 additions & 6 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: deploy documentation (only on push to main branch)
33
on:
44
push:
55
branches: main
6+
# Add option to deploy manually, e.g. because there is a new EESSI test suite release and we want updated API docs
7+
workflow_dispatch:
68
# Declare default permissions as read only.
79
permissions: read-all
810
jobs:
@@ -13,12 +15,12 @@ jobs:
1315
contents: write
1416
steps:
1517
- name: checkout
16-
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
18+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
1719
with:
1820
fetch-depth: 0 # need to fetch all history to ensure correct Git revision dates in docs
1921

2022
- name: set up Python
21-
uses: actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984 # v4.3.0
23+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2224
with:
2325
python-version: '3.10'
2426

@@ -28,5 +30,23 @@ jobs:
2830
pip list | grep mkdocs
2931
mkdocs --version
3032
33+
# Make sure to also deploy auto-generated API docs for test suite
34+
# For that, we need the repo to be available under eessi/test-suite
35+
- name: checkout test suite
36+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
37+
with:
38+
repository: eessi/test-suite
39+
# Path is needed, otherwise this will overwrite the checkout action that cloned the docs repo
40+
path: test-suite/test-suite
41+
- name: generate docs for latest release
42+
run: |
43+
cd test-suite/test-suite
44+
# Make sure to fetch tags, so we can checkout a particular release
45+
git fetch --tags
46+
# This assumes we stick to a version-tagging scheme vX.Y.Z
47+
LATEST_VERSION=$(git tag | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1)
48+
# Use the latest release by default
49+
git checkout $LATEST_VERSION
50+
3151
- name: build tutorial
3252
run: make test && make deploy

.github/workflows/test.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
runs-on: ubuntu-22.04
99
steps:
1010
- name: checkout
11-
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
11+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
1212

1313
- name: set up Python
14-
uses: actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984 # v4.3.0
14+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
1515
with:
1616
python-version: '3.10'
1717

@@ -30,6 +30,25 @@ jobs:
3030
# config: '/lint/config/changelog.yml'
3131
# args: '.'
3232

33+
34+
# Make sure to also test deployment of auto-generated API docs for test suite
35+
# For that, we need the repo to be available under eessi/test-suite
36+
- name: checkout test suite
37+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
38+
with:
39+
repository: eessi/test-suite
40+
# Path is needed, otherwise this will overwrite the checkout action that cloned the docs repo
41+
path: test-suite/test-suite
42+
- name: Generate docs for latest release
43+
run: |
44+
cd test-suite/test-suite
45+
# Make sure to fetch tags, so we can checkout a particular release
46+
git fetch --tags
47+
# This assumes we stick to a version-tagging scheme vX.Y.Z
48+
LATEST_VERSION=$(git tag | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1)
49+
# Use the latest release by default
50+
git checkout $LATEST_VERSION
51+
git branch
3352
- name: install mkdocs + plugins
3453
run: |
3554
pip install -r requirements.txt

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ site/
22
venv*
33
scripts/available_software/__pycache__
44
scripts/available_software/tests/__pycache__
5-
5+
test-suite

docs/adding_software/debugging_failed_builds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ eb --easystack eessi-2023.06-eb-4.8.1-2021b.yml --robot
227227
After some time, this build fails while trying to build `Plumed`, and we can access the build log to look for clues on why it failed.
228228

229229
## Building an individual package
230-
First, prepare the environment by following the [Starting the EESSI software environment][#starting-the-eessi-software-environment] and [Configure EasyBuild](#configure-easybuild) above.
230+
First, prepare the environment by following the [Starting the EESSI software environment](#starting-the-eessi-software-environment) and [Configure EasyBuild](#configure-easybuild) above.
231231

232232
In our [example PR](https://github.com/EESSI/software-layer/pull/360), the individual package that was added to `eessi-2023.06-eb-4.8.1-2021b.yml` was `LAMMPS-23Jun2022-foss-2021b-kokkos.eb`. To mimic the build behaviour, we'll also have to (re)use any options that are listed in the easystack file for `LAMMPS-23Jun2022-foss-2021b-kokkos.eb`, in this case the option `--from-pr 19000`. Thus, to build, we run:
233233
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Generate the code reference pages.
3+
Based off https://mkdocstrings.github.io/recipes/#automatic-code-reference-pages
4+
"""
5+
6+
import os
7+
8+
from pathlib import Path
9+
10+
import mkdocs_gen_files
11+
12+
TEST_SUITE = "test-suite/test-suite"
13+
14+
if not os.path.isdir(TEST_SUITE):
15+
raise FileNotFoundError(f"Error: {TEST_SUITE} does not exist. Please clone the eessi/test-suite in a test-suite dir.")
16+
17+
# build a navigation for the menu and a dictionary of navigations for each section
18+
nav = mkdocs_gen_files.Nav()
19+
20+
# Loop through all python files in test-suite/eessi
21+
for path in sorted(Path(f"{TEST_SUITE}/eessi/").rglob("*.py")):
22+
# Get the relative filename, without .py suffix
23+
module_path = path.relative_to(TEST_SUITE).with_suffix("")
24+
25+
# define the corresponding (relative) markdown filename
26+
doc_path = path.relative_to(TEST_SUITE).with_suffix(".md")
27+
28+
# Specify the full corresponding markdown filename, including a testsuite_api subdir
29+
# so that we don't have these API docs scattered in the root of the EESSI docs repo
30+
full_doc_path = Path("testsuite_api/", doc_path)
31+
32+
# If something is an __init__, use the directory name as the name of the python module instead of the filename
33+
parts = list(module_path.parts)
34+
if parts[-1] == "__init__":
35+
parts = parts[:-1]
36+
# Skip the __main__, if there is one. This is not part of the API
37+
elif parts[-1] == "__main__":
38+
continue
39+
40+
# Add an entry for this module to the navigation
41+
nav[parts] = doc_path.as_posix()
42+
43+
# Create the markdown file
44+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
45+
# identifier is something like eessi.foo.bar
46+
identifier = ".".join(parts)
47+
fd.write(f"::: {identifier}")
48+
49+
# This maps the generated .md file to the source .py, so that you can have an "Edit on GitHub" button
50+
# that links to the Python code
51+
mkdocs_gen_files.set_edit_path(full_doc_path, path)
52+
53+
# Create the api/summary.md file and write the full navigation tree into it so it can be used as a site sidebar
54+
with mkdocs_gen_files.open("testsuite_api/summary.md", "w") as nav_file:
55+
nav_file.writelines(nav.build_literate_nav())

mkdocs.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ nav:
5656
- Available tests: test-suite/available-tests.md
5757
- Writing tests: test-suite/writing-portable-tests.md
5858
- Release notes: test-suite/release-notes.md
59+
- API documentation: testsuite_api/
5960
# - Dashboard: test-suite/dashboard.md
6061
- Known issues and workarounds:
6162
- v2023.06: known_issues/eessi-2023.06.md
@@ -105,6 +106,24 @@ plugins:
105106
rocm.md: site_specific_config/rocm.md
106107
# Enable our custom plugin for json-ld metadata
107108
- inject_ld_json
109+
# link to any Markdown heading
110+
- autorefs
111+
# api automatics documentation
112+
- mkdocstrings:
113+
default_handler: python
114+
handlers:
115+
python:
116+
paths: [test-suite/test-suite]
117+
options:
118+
docstring_style: sphinx
119+
docstring_section_style: spacy
120+
show_source: false
121+
- gen-files:
122+
scripts:
123+
- docs/generate_eessi_testsuite_api_docs.py
124+
- literate-nav:
125+
nav_file: summary.md
126+
- section-index
108127
markdown_extensions:
109128
# enable adding HTML attributes and CSS classes
110129
- attr_list

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ mkdocs-git-revision-date-localized-plugin
55
mkdocs-toc-sidebar-plugin
66
mkdocs-macros-plugin
77
./mkdocs-ldjson-plugin
8+
mkdocs-autorefs
9+
mkdocstrings[python]
10+
mkdocs-gen-files
11+
mkdocs-literate-nav
12+
mkdocs-section-index

0 commit comments

Comments
 (0)