Reduce your documentation build size by selectively removing toctrees from pages.
Project description
Remove toctrees from Sphinx pages
Improve your Sphinx build time by selectively removing TocTree objects from pages. This is useful if your documentation uses auto-generated API documentation, which generates a lot of stub pages.
This extension can be used to remove the sidebar links for just the pages you specify, speed up the build considerably.
Who is this for?
This package is for maintainers that use Sphinx and have really large API documentation (or for some other reason, have a ton of nested pages). If you use a Sphinx theme that contains the entire Table of Contents on every page (e.g., any theme that has "collapsable" sidebar sections), this will slow things down considerably. Use this theme to speed up your builds.
Install
Install the extension via pip
:
$ pip install sphinx-remove-toctrees
activate it by adding it to your Sphinx extensions in conf.py
:
extensions.append("sphinx_remove_toctrees")
Use
In conf.py
, there is a top-level configuration key called remove_toctrees_from
that allows you to specify the pages to remove from your sidebar.
Provide a list of glob
-like paths relative to your documentation root.
Each entry should match to pages that should be removed from the sidebar.
For example, the following configuration will remove all pages from the folder api/generated
, and the specific page subfolder/page_two.rst
:
remove_toctrees_from = ["api/generated/*", "subfolder/page_two.rst"]
This is particularly useful in combination with the autosummary
directive, which tends to generate a ton of stub-pages that slows things down.
If you have the following autosummary directive in a page at myfolder/page1.rst
:
.. autosummary: datetime.datetime
:toctree: api_gen
This will generate stub-pages in a myfolder/api_gen/
folder.
To remove each of these pages from your sidebar, you would configure this extension like so:
remove_toctrees_from = ["myfolder/api_gen/*"]
Try it with this documentation
This extension doesn't have a hosted documentation page, but there is one in the docs/
folder of this repository.
You can use that folder to preview this extension in action.
How this works
Sphinx keeps track of toctree
objects to represent the structure of your documentation.
These exist in the Sphinx environment object, at env.tocs
.
There are two places in the build where this is relevant here:
- Early in the build, Sphinx uses these
tocs
to ensure that files in your documentation are linked somewhere, and will raise warnings if it finds a file that is not in one of thetocs
. - Later in the build, Sphinx uses these
tocs
to build the HTMLtoctree
with links to pages in your documentation. If there are many elements intocs
, it will take a long time to resolve all of these links!
This extension runs after the first step, but before the second step.
It removes all the toctree
objects that you specify, so that no warnings are raised about missing files, but they are removed from the sidebar and don't slow down your build.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sphinx-remove-toctrees-0.0.2.tar.gz
.
File metadata
- Download URL: sphinx-remove-toctrees-0.0.2.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f0e67c1829996cc4059f2c42d872d5cecd1b38afcbdbf52aedc3e552a892be |
|
MD5 | 6789a4b60d32eff1f63cbcc77ec28f75 |
|
BLAKE2b-256 | 8517f8a2e6b7fec34e67e35a7d93a6f7f45dcedc5bd1eb4fa7aef181240ee7a2 |
File details
Details for the file sphinx_remove_toctrees-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: sphinx_remove_toctrees-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f17f3e9a37e39c87fff97090f2e2c4c04a2c39ced657b0b6a3316b5f72a3efef |
|
MD5 | 3ebdf4ccc299e7b7830fc7138c821694 |
|
BLAKE2b-256 | 80544b2d4606ff93bb4cf774be353e80ea1d4733eae9c695d3fd512531962fec |