-
Notifications
You must be signed in to change notification settings - Fork 580
Description
Hi, I am opening this issue to start a discussion around migrating the documentation to a more modern solution, and a more user friendly state after discussing it with @nicholascar
Why material for mkdocs?
- Mature, actively maintained, used by many high profile python projects (fastapi, pydantic, ansible...)
- User friendly: modern and familiar look and feel with a user friendly navigation
- Contributor friendly: markdown based, good developer experience to run locally and deploy remotely
- Supported out-of-the-box, and even recommended, by readthedocs: https://docs.readthedocs.com/platform/stable/intro/mkdocs.html
Migration
I have started exploring how to migrate the documentation to mkdocs, without losing existing features:
- Reference to API docs for specific classes and functions can be done even more easily than with sphinx
- :class:
~rdflib.graph.Graphbecomes [Graph][rdflib.graph.Graph] - Or [
add()][rdflib.graph.Graph.add]
- :class:
- Deploying the reference API docs from docstring for the whole project is slightly more verbose than previously, but enable better control over how it is displayed
⚠️ by defaultmkdocstringwill not automatically create new pages for submodules of a module. Instead it will put everything in the same page- ✅ the solution is a small python script that recursively go through all submodules and create new pages for each submodule with
mkdocs-gen-files. These pages can be referenced in themkdocs.ymlnav but are never materialized in the repository, so we have control over the side navigation, while still getting all of the code automatically documented- Note that when running
mkdocsit will print the list of pages that are not referenced in the nav (in our case we are fine with it because we expect the user to access top modules through the navigation, and then navigate to submodules through the top modules page). - We could also put everything in the nav, but that might make it a bit harder to read. There are options to automatically generate the navigation through the script, but in my opinion it is too cluttered, I prefer that this is manually defined for a better display and focus. Let me know what you think
- Note that when running
- Importing a definition in a documentation page (previously done with
.. autoclass:: rdflib.term.URIRef) can be done with::: rdflib.term.URIRef.-
But with mkdocs it adds a lot more things (e.g. properties), which makes the documentation less readable. We could improve it by changing the global mkdocstring options, or applying specific options to this specific reference:
::: rdflib.term.URIRef options: show_source: false show_bases: false show_category_heading: false show_if_no_docstring: false show_root_heading: false show_root_toc_entry: false inherited_members: false -
I propose we just replace them by a link to the reference in the API doc, so if the user wants to see more about this function they just need to click. This will make the documentation more lean and readable
-
- Automated test of all code blocks in the documentation done with
pytest-markdown-docs- just run
poetry run pytest --markdown-docs - this is the only way to make sure your documentation examples are not broken (really simple and powerful concept, rust have it built-in the standard lib, it should be a default of pytest to be honest). And you get more tests for free
- For now I have not yet made sure those tests passes, it will be a future work (it is disabled by default for now)
- just run
- Update docstring to Google style:
- readable, and does not require to duplicate the type annotations (rdflib already has proper type annotations in the functions definitions)
- Compliant with PEP 257
- Well supported by modern IDEs
- Examples doc: in its current state it is quite hard to access. https://rdflib.readthedocs.io/en/stable/apidocs/examples.html only has the docstring, so users need to manually go to the various files in the
examplesfolder in the source code (there are not even links to the source code from the documentation, so the journey to get there is more complex than it should be).- Maybe that would be a good moment to make it better accessible, e.g. directly include it as code blocks in markdown? In a
Examplescategory in the top nav - Or completely review them because they kind of overlap with "regular" documentation for the main features of the lib
- Maybe that would be a good moment to make it better accessible, e.g. directly include it as code blocks in markdown? In a
Questions
- Would a migration to mkdocs be interesting for the project?
- Any remarks on the proposed plan?
- Any outstanding requests? (modifications to the docs you would like to see while we do this migration)
I just converted a handful of files to markdown, the next step will be to convert all docstring and documentation pages from rst to markdown
I have pushed the changes to this branch, I will create a PR when it will be a bit clearer which direction to take
- Setup mkdocs configuration: vemonet@ded6528
- Add automated docs tests: vemonet@8cecbaa
You can deploy it locally with:
poetry run mkdocs serveSome screenshots to give an idea of what it would look like:

