melissawm / sphinx-tags

A tiny Sphinx extension that implements blog-style tags for documentation.
https://sphinx-tags.readthedocs.io/en/latest/
MIT License
44 stars 11 forks source link

Exclude sources matching `exclude_patterns` #58

Closed JWCook closed 10 months ago

JWCook commented 1 year ago

It would be useful if source files gathered by assign_entries() excluded any files matched by exclude_patterns.

It looks like we could use sphinx.util.matching.Matcher and get_matching_files() to match those patterns the same way Sphinx does. I found an example of another extension that does this here. If that sounds reasonable to you, I'd be willing to make a PR for that.

Example

Example use case (which I found completely by accident):

When building tag pages with Jupyter Notebooks, it's possible to have tags in a notebook counted twice. This is because the doctree build directory ({build_dir}/doctrees/nbsphinx/) may, depending on output format, include a copy of any .ipynb files as-is. If the build directory is under the source directory (like docs/_build), then the glob pattern in assign_entries() will match those extra files and count their tags again.

For example, for a single notebook with a tag tag_1, the generated tag page will look like this:

My tags: tag_1
##############

.. toctree::
    :maxdepth: 1
    :caption: With this tag

    ../_build/doctrees/nbsphinx/page_1.ipynb
    ../page_1.ipynb
melissawm commented 1 year ago

Sounds good, thanks!