Skip to content

Convert docs from sphinx to mkdocs - #2140

Open
sydduckworth wants to merge 130 commits into
asdf-format:mainfrom
sydduckworth:convert-docs-to-mkdocs
Open

sydduckworth wants to merge 130 commits into
asdf-format:mainfrom
sydduckworth:convert-docs-to-mkdocs

Conversation

@sydduckworth

@sydduckworth sydduckworth commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Description

Closes #2167

  • Switched docs build backend from Sphinx to Properdocs (maintained fork of mkdocs)
  • Converted all RST files to markdown
  • Updated towncrier to ingest and output markdown instead of RST
  • Added a docs/.hooks/ directory which contains custom mkdocs hooks:
    • toctree.py - implements similar functionality to the Sphinx toctree directive, although currently limited to a single file. Will hopefully be removed in future PRs as we update the docs structure.
    • strip_doctest_flags.py - finds and removes doctest flags (e.g. # doctest: +SKIP) from code blocks.
    • export_legacy_labels.py - injects Sphinx-style doc labels into objects.inv to maintain compatibility with downstream projects that reference our docs.
  • Added docs/.overrides directory:
    • main.html - Updates page layout to add announcement banner with links at top and add RTD version integration
    • partials/copyright.html - Generates copyright string with current year during build
    • macros/ - Functions and variables for use in templating via mkdocs-macros
      • towncrier.py - Adds macro function that runs towncrier to generate a new changelog section with any pending changes and inserts it at the current location (returns an empty string if there are no pending changes).
      • extlink.py - Implements similar functionality to Sphinx's extlinks plugin by registering new macros that expand to external project URLs. Also implements linkcheck-like functionality to verify links are valid.

Changes to Documentation Structure

  • Now all public modules are automatically discovered and documentation is generated in the api/ subtree, which is not part of site navigation. The "User API" and "Developer API" pages then manually link desired API pages.
    • Currently we're only auto-generating public modules (modules with no leading _ in their path), but we could easily do this for all modules if we wanted
  • The API docs now document dunder methods of classes. I think this is potentially fine since dunder methods do provide useful information about what operations the class supports, although it does clutter the docs a bit.
    • This is because of how the "public" filter works for mkdocstrings-python
    • If we want to filter out dunder methods we can do so with a simple custom Griffe extension.
  • Mkdocstrings exports an objects.inv sphinx inventory, but only for the py domain. This means that any other projects that are using Sphinx std domain refs to ASDF will need to be updated.
  • Once the PR is merged we will want to enable the following redirects so that existing links to the docs continue to work:
    • HTML to clean URL (*.html -> */)
    • /asdf/* -> /*

Changes to Build Process

  • For local development use nox docs -- serve to launch a local docs server which automatically reloads when files are changed.
  • The changelog page is now automatically updated during the build to incorporate any pending changes, this eliminates the need to run towncrier build --keep.

Zensical Compatibility

mkdocs-material reaches end of life on May 5th, 2027. The intended replacement (for both it and mkdocs as a whole) is Zensical. Zensical is still in early development but is expected to reach 1.0 in November.

I've tested building the docs with Zensical. Other than the compatibility issues listed below, everything works:

  • We currently use a few custom hooks, which Zensical does not support. They plan to add a "modules" API in the future.
    • strip_doctest_flags can be converted to a Superfences custom formatter, which Zensical supports. For now it's more convenient to leave it as a hook.
    • toctree can hopefully be removed in the future as we move away from the old Sphinx docs structure.
    • Any other custom functionality we need in the future can probably be implemented as a markdown extension, a superfences formatter, or a mkdocs-macros macro.
  • Zensical uses MiniJinja for templating which is a more limited subset of Jinja than provided by Mkdocs. In particular, we use the template variable build_date_utc to define the copyright string in the footer, which Zensical currently doesn't support.
    • I added a comment in copyright.hml describing a workaround I found which I confirmed works with Zensical.
  • Currently the git-revision-date-localized plugin isn't supported. Support for it is on Zensical's roadmap and if not this plugin can just be removed.
  • We use the config option absolute_links: relative_to_docs for cleaner reference paths that don't depend on the current file (e.g. if we're in a subdirectory it's nicer to write /changelog.md than to write ../changelog.md). Zensical currently seems to treat these as relative paths instead. It's unclear if this is intentional, a missing feature, or a bug. Worst case, it would be easy to convert the absolute links to relative links.

Worth noting that there is also materialx, which is a fork of mkdocs-material that will receive ongoing support. I didn't go with materialx over material initially because materialx is only maintained by a single person, but it is at least an option if we really don't want to use Zensical.

AI Disclosure

No AI tools used

Tasks

  • run prek on your machine
  • run pytest on your machine
  • Does this PR add new features and / or change user-facing code / API? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • update relevant docstrings and / or docs/ page
    • for any new features, add unit tests
news fragment change types...
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: bug fix
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.general.rst: infrastructure or miscellaneous change

@sydduckworth

sydduckworth commented Nov 6, 2026 •

Copy link
Copy Markdown
Member Author

@embray yeah we definitely got out over our skis a bit on this one with the "how" vs "why" 😅

I added a write-up here that should provide some additional background: #2167

Comment thread docs/CITATION.md Resolved
Comment thread docs/features/index.md Resolved

@braingram braingram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for working on this. I've gone through most of the configuration changes, the general structure and intersphinx links. I started accumulating comments but realized it will be easier to handle these requests via PR(s) against the source branch. I'm going to submit the comments so they're not lost and open a PR against the source branch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up PR I think the docs could be improved by:

  • replacing the toctree uses with text describing the referenced information
  • removing this toctree hook

Comment thread docs/.overrides/macros/extlink.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching for the uses in the docs I find 11 links handled by this plugin (1 for pytest, 1 for stdatamodels, 9 for asdf-standard).

Let's replace the custom extlinks with standard markdown links or simple macros and remove this file.

For the asdf-standard links a macro can be added to the config:

extra:
  asdf_standard_docs: https://www.asdf-format.org/projects/asdf-standard/en/latest

and links replaced with (for example)

[here]({{ asdf_standard_docs }}/generated/stsci.edu/asdf/unit/quantity-1.1.0.html)

which is more familiar syntax compared to:

{{ asdf_standard('here', 'generated/stsci.edu/asdf/unit/quantity-1.1.0') }}

I could be convinced that even the simple macro isn't worthwhile for 9 links.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only advantage of the macro is that it validates the links.
We should consider adding some hook or something that just checks external links.

Also, for asdf-standard mind if I turn on the "Clean URL to HTML" redirect in RTD? That way we can omit the .html on the links which makes the source more compact.

@embray

embray commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@embray yeah we definitely got out over our skis a bit on this one with the "how" vs "why" 😅

I added a write-up here that should provide some additional background: #2158

Sorry I missed it earlier. You linked to #2158 but I see now your writeup was actually on #2167 which I didn't find before. I'll look at it now.

Comment thread noxfile.py Resolved
Comment thread docs/arrays.md Resolved

@braingram braingram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the first round of content review. I used gpt6.1 sol to compare old and new docs then reviewed and filtered the findings myself. I'll send you the full report separately.

Comment thread docs/arrays.md Resolved
Comment thread docs/arrays.md Resolved
Comment thread docs/arrays.md Resolved
Comment thread docs/arrays.md Resolved
Comment thread docs/asdf_tool.md Resolved
Comment thread docs/extending/schemas.md Resolved
Comment thread docs/developer/index.md Resolved
Comment thread docs/overview.md

## Creating Files

--8<-- "README.md:create-file"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something isn't quite right with this snippet. With the PR it's showing a file with ASDF_STANDARD 1.2.0:
https://asdf-website--2140.org.readthedocs.build/projects/asdf/en/2140/overview.html#creating-files
on main it shows a file with ASDF_STANDARD 1.6.0:
https://www.asdf-format.org/projects/asdf/en/latest/asdf/overview.html#creating-files
Would you give this a look and sort out how to restore the contents shown on main?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Sphinx docs it copies a snippet from the readme which is followed by the YAML block with ASDF_STANDARD 1.2.0, but instead of including that part it then has an almost identical YAML block with a few small metadata differences, such as having ASDF_STANDARD 1.6.0.

I got rid of the duplicated code block in overview.md and had it just use the one that's already in the readme. If you want I could update the code block in the readme to match overview.md.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix the inventory version here (or elsewhere in the configurate). It currently shows version 0.0.0:

>> head -n 3 site/objects.inv
# Sphinx inventory version 2
# Project: asdf
# Version: 0.0.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not related (but not sure where to comment) but the intersphinx inventory also does not list the asdf module.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the mkdocstrings code it appears that it doesn't actually set the project version, it's just always 0.0.0. I'm not aware of any way that the version in objects.inv is used by consuming clients, so doesn't seem like a major problem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the modules in the inventory seem off.
It seems to be adding modules to the inventory if they're imported by another module, even if it's not in the module's __all__, e.g. the inventory contains asdf.lazy_nodes.tagged because asdf.lazy_nodes imports tagged. I guess that's not a huge issue, other than polluting the inventory a bit.

Not sure yet why it's not including the root module though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://sphobjinv.readthedocs.io/en/stable/syntax.html the version is used in hover over text generation as is the case now on RTD. Here's an example with the docs on main:
Screenshot 2026-11-20 at 3 42 06 PM

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will try to find a better solution later but for now I've updated the intersphinx_compat hook to populate the inventory package version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I figured out the asdf module being missing. That's because it was being overwritten by an asdf std:label object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated intersphinx_compat so it will emit a warning if a registered object overwrites an existing object, and (for now) removed the std:label asdf entry. That is one of the few labels that is definitely referenced by several other projects though, so probably need a better solution.

@sydduckworth sydduckworth Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think I have a solution to this.
Right now intersphinx_compat is appending to the mkdocstrings-python inventory, but I think it should be doable to instead add an entirely new handler from within the hook which would then have its own inventory that wouldn't conflict. Edit: I'm wrong about this I think, but another similar solution may work.

I'll look into that once I'm back in the office after Thanksgiving.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OKAY, so I actually found a fix for this, although its a bit hacky.

mkdocstrings.Inventory is a dictionary that keys objects by name, but it appears that the dictionary key actually isn't used by mkdocstrings anywhere.
So I just updated the hook to swap the inventory out with a custom subclass that keys by domain:role:name instead. Now all the objects can coexist, and it doesn't seem to have broken anything in the docs themselves 😅


Raises a warning if the URL for a label doesn't exist in the docs.

# Docs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is polluting the doc entry names. See example:

std:doc
     api/asdf/config                          <code class="doc-symbol doc-symbol-module"></code> asdf.config: api/asdf/config.html

The code tag shouldn't be there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entry name comes from the page name, and that is what the module's page name is.
To me the std:doc items for API pages didn't seem that important since realistically I don't see why someone would be referencing those pages via doc rather than py.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does indeed seem to come literally from https://github.com/asdf-format/asdf/pull/2140/changes#diff-aed2cba4728ca2741215a681e42c91a87c715e2abb419b26da30b9bb92b312ea or the equivalent for the user API docs. Which I'm a bit puzzled by too.

Comment thread docs/developer/SUMMARY.md Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert documentation from Sphinx to mkdocs

4 participants