Skip to content

Migrate documentation to mkdocs #3128

@vemonet

Description

@vemonet

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.Graph becomes [Graph][rdflib.graph.Graph]
    • Or [add()][rdflib.graph.Graph.add]
  • 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 default mkdocstring will 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 the mkdocs.yml nav 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 mkdocs it 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
  • 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)
  • 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 examples folder 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 Examples category in the top nav
    • Or completely review them because they kind of overlap with "regular" documentation for the main features of the lib

Questions

  1. Would a migration to mkdocs be interesting for the project?
  2. Any remarks on the proposed plan?
  3. 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

You can deploy it locally with:

poetry run mkdocs serve

Some screenshots to give an idea of what it would look like:

Image

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions