-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to markdown based API and linting error docs #2758
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
068e24a
add working generate-api-doc.sh script
mashehu 8b61207
optimize script
mashehu 59214f5
merge api docs actions to one and trigger action on website repo
mashehu 018ce82
add missing remark script
mashehu 3ef8990
[automated] Update CHANGELOG.md
nf-core-bot 5543bc4
add outdir option to generate script
mashehu baef8a0
fix index pages
mashehu 7350e32
update path for remark script
mashehu e275dff
don't update members in api docs
mashehu 3711b74
remove typo
mashehu 4186bcb
just copy files over and then go back to current branch
mashehu 808dc68
fix for lower level emphasis terms
mashehu afa0cf0
add debugging
mashehu c0b6e19
handle emphasis before the rest
mashehu 8f40d4a
remove debugging
mashehu 0f33118
convert the whole heading to code
mashehu 714a1aa
tidy up remark code
mashehu 5dd018d
fix one more index page
mashehu fac45e7
use different remark logic
mashehu eb8d992
Merge branch 'switch-to-md-api-docs' of github.com:mashehu/tools into…
mashehu 2c11e4b
fix api index page
mashehu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: nf-core/tools dev API docs | ||
# Run on push and PR to test that docs build | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
paths: | ||
- nf_core/**/*.py | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
inputs: | ||
ref_name: | ||
description: "The branch or tag to build the API docs for" | ||
required: true | ||
default: "dev" | ||
|
||
# Cancel if a newer run is started | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
api-docs: | ||
name: trigger API docs build on website repo | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: trigger API docs build | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.nf_core_bot_auth_token }} | ||
script: | | ||
await github.rest.actions.createWorkflowDispatch({ | ||
owner: 'nf-core', | ||
repo: 'website', | ||
workflow_id: 'add-tools-api-docs.yml', | ||
ref: 'main' | ||
inputs: { | ||
"ref_name": ${{ inputs.ref_name || github.ref_name }} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# API Reference | ||
|
||
```{toctree} | ||
:caption: 'Tests:' | ||
:glob: true | ||
:maxdepth: 2 | ||
:maxdepth: 1 | ||
|
||
* | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# environment_yml | ||
|
||
```{eval-rst} | ||
.. automethod:: nf_core.modules.lint.ModuleLint.environment_yml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# Module lint tests | ||
|
||
```{toctree} | ||
:caption: 'Tests:' | ||
:glob: true | ||
:maxdepth: 2 | ||
:maxdepth: 1 | ||
|
||
* | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# Pipeline lint tests | ||
|
||
```{toctree} | ||
:caption: 'Tests:' | ||
:glob: true | ||
:maxdepth: 2 | ||
:maxdepth: 1 | ||
|
||
* | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# Subworkflow lint tests | ||
|
||
```{toctree} | ||
:caption: 'Tests:' | ||
:glob: true | ||
:maxdepth: 2 | ||
:maxdepth: 1 | ||
|
||
* | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
|
||
# allow --force option and also a --release option (which takes a release name, or "all") | ||
force=false | ||
releases=() | ||
|
||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-f | --force ) | ||
force=true | ||
;; | ||
-r | --release ) | ||
shift | ||
releases+=("$1") | ||
;; | ||
-o | --output ) | ||
shift | ||
output_dir="$1" | ||
;; | ||
* ) | ||
echo "Invalid argument: $1" | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
|
||
# Set the output directory if not set | ||
if [[ -z "$output_dir" ]]; then | ||
output_dir="../src/content/tools/docs" | ||
fi | ||
|
||
# if no release is specified, use all releases | ||
if [[ ${#releases[@]} -eq 0 ]]; then | ||
releases=($(git tag)) | ||
# add 'dev' to the list of releases | ||
releases+=("dev") | ||
fi | ||
|
||
# Loop through each release | ||
for release in "${releases[@]}"; do | ||
# Checkout the release | ||
git checkout "$release" | ||
echo "_________________________" | ||
echo "Generating docs for release: $release" | ||
echo "_________________________" | ||
git checkout docs/api | ||
pip install -r docs/api/requirements.txt --quiet | ||
# add the napoleon extension to the sphinx conf.py | ||
gsed -i 's/^extensions = \[/extensions = \[\n "sphinx_markdown_builder",/' docs/api/_src/conf.py | ||
|
||
# run docs/api/make_lint_md.py if it exists | ||
# if [[ -f "docs/api/make_lint_md.py" ]]; then | ||
# python docs/api/make_lint_md.py | ||
# fi | ||
|
||
find nf_core -name "*.py" | while IFS= read -r file; do | ||
# echo "Processing $file" | ||
|
||
# replace ..tip:: with note in the python docstrings due to missing directive in the markdown builder | ||
gsed -i 's/^\(\s*\)\.\. tip::/\1\.\. note::/g' "$file" | ||
|
||
done | ||
|
||
# fix syntax in lint/merge_markers.py | ||
gsed -i 's/>>>>>>> or <<<<<<</``>>>>>>>`` or ``<<<<<<<``/g' nf_core/lint/merge_markers.py | ||
# remove markdown files if --force is set | ||
if [[ "$force" = true ]]; then | ||
echo -e "\n\e[31mRemoving $output_dir/$release because of '--force'\e[0m" | ||
rm -rf "$output_dir/$release" | ||
fi | ||
sphinx-build -b markdown docs/api/_src "$output_dir/$release" | ||
|
||
# undo all changes | ||
git restore . | ||
|
||
git checkout - | ||
# replace :::{seealso} with :::tip in the markdown files | ||
find "$output_dir/$release" -name "*.md" -exec gsed -i 's/:::{seealso}/:::tip/g' {} \; | ||
i=1 | ||
sp="/-\|" # spinner | ||
find "$output_dir/$release" -name "*.md" | while IFS= read -r file; do | ||
# echo "Processing $file" | ||
printf "\b${sp:i++%${#sp}:1}" | ||
node docs/api/remark.mjs "$file" | ||
done | ||
# remove empty files | ||
find "$output_dir/$release" -name "*.md" -size 0 -delete | ||
# remove `.doctrees` directory | ||
rm -rf "$output_dir/$release/.doctrees" | ||
# run pre-commit to fix any formatting issues on the generated markdown files | ||
pre-commit run --files "$output_dir/$release" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import fs from "fs"; | ||
import { remark } from "remark"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
function remarkDirectives() { | ||
return transformer; | ||
|
||
function transformer(tree) { | ||
visit(tree, "heading", visitor); | ||
visit(tree, "link", visitor); | ||
} | ||
|
||
function visitor(node, index, parent) { | ||
if (node.depth === 4) { | ||
if (["note", "warning"].includes(node.children[0].value?.toLowerCase())) { | ||
const type = node.children[0].value.toLowerCase(); | ||
parent.children.splice(index, 1); | ||
parent.children[index].children[0].value = `:::${type}\n${parent.children[index].children[0].value}`; | ||
// if second to list parent.children[index].children ends with ":", check if the next node is a code block, if so, add the code block as a child to the current node | ||
if (parent.children[index].children.slice(-1)[0]?.value?.trim().endsWith(":")) { | ||
if (parent.children[index + 1].type === "code") { | ||
parent.children[index].children.slice(-1)[0].value += "\n"; | ||
parent.children[index].children.push(parent.children[index + 1]); | ||
parent.children.splice(index + 1, 1); | ||
} | ||
} | ||
parent.children[index].children.push({ type: "text", value: "\n:::" }); | ||
} else if (node.children[0].type === "emphasis") { | ||
node.children[0].children.map((child) => { | ||
if (child.type === "text") { | ||
child.type = "inlineCode"; | ||
child.value = child.value?.trim() + "{:python}"; | ||
} | ||
}); | ||
// convert the rest of the heading to inline code | ||
node.children.slice(1).map((child) => { | ||
if (child.type === "text") { | ||
child.type = "inlineCode"; | ||
child.value = child.value?.trim() + "{:python}"; | ||
} | ||
if (child.type === "link") { | ||
child.children.map((child) => { | ||
if (child.type === "text") { | ||
child.type = "inlineCode"; | ||
child.value = child.value?.trim() + "{:python}"; | ||
} | ||
}); | ||
} | ||
}); | ||
} else if (node.children[0].type !== "inlineCode") { | ||
node.children[0] = { | ||
type: "inlineCode", | ||
value: node.children[0].value?.trim() + "{:python}", | ||
}; | ||
} | ||
} else if (node.depth === 3) { | ||
node.children.map((child) => { | ||
if (child.type === "text") { | ||
child.type = "inlineCode"; | ||
child.value = child.value?.trim() + "{:python}"; | ||
} | ||
if (child.type === "link") { | ||
child.children.map((child) => { | ||
if (child.type === "text") { | ||
child.type = "inlineCode"; | ||
child.value = child.value?.trim() + "{:python}"; | ||
} | ||
}); | ||
} | ||
if (child.type === "emphasis") { | ||
child.children.map((child) => { | ||
if (child.type === "text") { | ||
child.type = "inlineCode"; | ||
child.value = child.value?.trim() + "{:python}"; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
if (node.type === "link") { | ||
node.url = node.url.replace(".md", ""); | ||
} | ||
} | ||
} | ||
|
||
let markdown = fs.readFileSync(process.argv[2]); | ||
|
||
remark() | ||
.use(remarkDirectives) | ||
.process(markdown, function (err, file) { | ||
if (err) throw err; | ||
fs.writeFileSync(process.argv[2], String(file)); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this workflow located? I can't find it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in this PR: https://github.com/nf-core/website/pull/2268/files#diff-dfae69a640999485f051208d7f3555435d4302d04a60f6224818a7aa48f98e10