Commit Graph
68 Commits
Author SHA1 Message Date
Chris SewellandAdam Turner 179e24252b Add the `sphinx.ext.apidoc` extension (#13333)
A common use-case is that users simply want to point Sphinx
towards a Python module, and have it generate documentation
automatically.

This is not possible currently, without a "pre-build" step
of running the ``sphinx-autogen`` CLI.

This PR adds ``sphinx.ext.apidoc`` as a first-party extension,
to incorporate the source file generation into the Sphinx build.

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2025-02-18 00:30:30 +00:00
Chris SewellandAdam Turner 134bd7f1fb Add `collapsible` option to admonition directives (#12507)
This PR adds the `collapsible` and option to the core admonition type directives, which are propagated to the nodes, e.g.

```restructuredtext
.. admonition:: title
   :collapsible:

   content

.. note:: content
   :collapsible: closed
```

For the HTML5 writer, this replaces the outer `div` with a `details` tag, and the title `p`  with a `summary` tag (with an `open` attribute if set), e.g.

```html
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>hallo</p>
</div>
```

changes to

```html
<details class="admonition note" open="open">
<summary class="admonition-title">Note</summary>
<p>hallo</p>
</details>
```

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2025-01-29 18:06:57 +01:00
Chris Sewell c23697aaa7 Use method colour key in the Builder API graph (#12998) 2024-10-11 22:51:32 +01:00
Chris Sewell 05cc39d9b2 [rst] Improve unreferenced footnote warnings (#12730)
The previous `UnreferencedFootnotesDetector` transform was untested and missed warnings for a number of cases.

This commit adds a test, to cover a reasonable range of scenarios,
then changes how the detection works to pass this test.

The transform now runs just after the docutils `Footnote` resolution transform
(changing its priority from 200 to 622)
then simply check for any footnotes without "back-references".
2024-08-05 10:28:13 +02:00
Chris SewellandAdam Turner dabacdf5f8 Turn `show_warning_types` on by default (#12597)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-07-20 21:07:06 +01:00
Chris SewellandAdam Turner d8fa98e46a Add a `write-started` event (#12567)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-07-15 04:59:06 +01:00
Chris Sewell cbf0b8e419 [docs] fix changelog include (#12564)
Use `include-read` instead of `source-read` for special content transform. 
In-particular, this fixes an issue that `docs/changes.rst` would not re-build, when `CHANGES.rst` was changed.
2024-07-14 06:35:35 +02:00
Chris Sewell 41b363dbff [rst] Add level option to rubric directive (#12506)
This commit adds a `level` option to the `rubric` directive, which propagates a `level` attribute to the `rubric` node,
and allows renderers to select a specific heading level.

Logic for this attribute has been added to the HTML5 and LaTeX builder.
2024-07-14 05:52:58 +02:00
Chris SewellandBénédikt Tran 78c8b4d323 Add optional description argument to app.add_config_value (#12549)
Sphinx (+ extensions) has a lot of available configuration variables for users,
allowing for the co-location of a short description on the configuration value,
can be utilised by external tools to provide better sphinx authoring support.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-12 19:40:36 +02:00
Chris Sewell 316451de81 Add docutils type, to warnings originating from docutils (#12550)
As per other warning types, this helps users to better understand the root of the problem.
2024-07-12 19:02:44 +02:00
Chris Sewell 8387f4a491 [html] propagate rel attribute from reference nodes (#12489)
See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel,
this allows third-party extensions to set this attribute on the node and have it propagate to the output HTML
2024-07-03 12:53:16 +02:00
Chris Sewell 953c0097ef [docs] add icons to admonition titles (#12486)
and also replace ad-hoc "more" icon in quickstart, with using `seealso` admonition
2024-06-27 23:06:52 +02:00
Chris Sewell d130c2e710 [docs] Improve tutorials (#12473)
This commit make it clearer, from the filenames and titles,
what the extension tutorials are intended to teach.
2024-06-27 22:30:03 +02:00
Chris Sewell 0b5fd6289d [docs] Improve contents title style (#12485) 2024-06-27 21:31:15 +02:00
Chris Sewell ad6f659eb2 [docs] Add Previous/Next links after content (#12466) 2024-06-27 14:58:50 +02:00
Chris Sewell 53119133f2 [docs] Keep top-bar visible (#12464)
This commit ensures the top-bar is always visible, rather than being hidden on scrolling or navigating to a target.
2024-06-23 00:19:43 +02:00
Chris Sewell a1bb165685 [docs] Add Github repo icon-link to topbar (#12462)
Add a link to sphinx-doc/sphinx, via an icon on the right of the top-bar
2024-06-22 20:48:18 +02:00
Chris Sewell bcf32428c8 [docs] Improve sidebar (#12461)
- Remove "Site navigation" header
  - this is already contextually clear (especially since separators were added in #12439)
- Hide "On this page" if `display_toc is False`
- Format "On this page" header similar to top-level site-nav sections
2024-06-22 15:32:06 +02:00
Chris Sewell c5bd2d42c5 [docs] improve RTD version selector (#12460)
ensure the border-radius is applied correctly
2024-06-22 14:50:38 +02:00
Chris Sewell 93e4eea307 [docs] Style ReadTheDocs version selector (#12457)
Style the ReadTheDocs version selector
(see https://docs.readthedocs.io/en/stable/flyout-menu.html)
inline with the rest of the theme.
2024-06-21 20:46:19 +02:00
Chris Sewell 8f97fd276a [docs] Improve landing page (#12453)
This commit is intended to improve new user's first-interaction with the Sphinx site:

- Make page header icon/text smaller and not capitalized
- Give min-width to left sidebar (it was getting too small at certain window sizes)
- Replace features list on landing page with admonition boxes, with adaptive layout
- Add landing page "used by" section
- Slightly restructure the Extension section, into Tutorials and How-tos
- Add code to `conf.py` to write HTML write redirect pages for moved documents
- Improve support page, by adding link to Stackoverflow, GH discussion and ReadtheDocs,
  and remove defunct link to libera chat and matplotlib tutorial
2024-06-21 20:12:57 +02:00
Chris Sewell bc1a5c5c88 [autogen] Add --remove-old option (#12456)
A common "gotcha" of re-running `sphinx-autogen`, is that if there are changes it will not remove old files, leading to build errors for files not in a `toctree`

This commit introduces a `--remove-old` option to remove these files.

Note, a key detail here is that we don't want to simply clear the directory before running `sphinx-autogen`,
since this would lead to all files having a new `mtime`,
and then `sphinx-build` would rebuild all of them even if they have not changed.
So we must first collect the list of all correct files, then remove any not in the list.
2024-06-21 19:29:46 +02:00
Chris Sewell 11abfb90ba [docs] Update changelog (#12454)
Some additions to the changelog,
that were not added in the relevant PRs.
2024-06-21 15:48:59 +02:00
Chris Sewell d7e1bfeb4b [apidoc] Add --remove-old option (#12448)
A common "gotcha" of re-running `sphinx-apidoc`, is that if the modules API changes it will not remove old files, leading to build errors for files not in a `toctree`

This commit introduces a `--remove-old` option to remove these files.

Note, a key detail here is that we don't want to simply clear the directory before running `sphinx-apidoc`,
since this would lead to all files having a new `mtime`,
and then `sphinx-build` would rebuild all of them even if they have not changed.
So we must first collect the list of all correct files, then remove any not in the list.

The commit also improves some typing of the code and replace `os.path` by `pathlib.Path` in most instances
2024-06-20 13:12:37 +02:00
Chris SewellandBénédikt Tran 0e3f5b4ab2 [DOCS] Improve events (#12446)
Split the events callback API into a separate document, add a flow graph of the events within the build process, add parameters to the events,
and link the `EnvironmentCollector` docs to the relevant events.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-06-20 10:40:22 +02:00
Chris Sewell ee92847a0a [format] Add ruff formating for apidoc/autosummary (#12447) 2024-06-20 09:37:49 +02:00
Chris Sewell 13b16c9b04 DOCS: hide todo admonitions on RTD (#12442)
`todo` admonitions should not be present in the user-facing documentation (built on ReadTheDocs)
2024-06-19 15:15:31 +02:00
Chris Sewell 37ff33dff7 [builder] type Builder core methods with @final and improve docs (#12436)
This commit:

- annotates the `Builder`'s "core" methods, with [`final`](https://docs.python.org/3/library/typing.html#typing.final)
- adds a UML graph to the Builder API docs
- Adds more methods to the Builder API docs

to make it clearer for extension developers, what is expected from a new builder subclass.
2024-06-19 14:51:20 +02:00
Chris Sewell 1e297bb8c5 🔧 Narrow typing for Builder.build method (#12357) 2024-06-17 12:44:04 +02:00
Chris Sewell 9c834ff8c5 Remove doctree cache from pickled BuildEnvironment (#12431)
This commit removes `_write_doc_doctree_cache` from the pickled `BuildEnvironment`,
greatly reducing the on-disk and parallel forking memory consumption,
and ensuring outdated doctrees are not used for re-builds.
2024-06-17 12:36:20 +02:00
Chris Sewell b97d14a8b0 Improve tox docs config (#12434)
For example, allow for `CLEAN=true BUILDER=man tox -e docs -- -j4`, 
to use the `man` builder on a clean build, with 4 processes
2024-06-17 11:52:52 +02:00
Chris Sewell f0dc8239cd [app] Allow extensions to detect freshenv builds (#12358)
Some extensions cache data outside of the `BuildEnvironment` (usually for memory/performance reasons).
For these extensions, it would be helpful to detect when `sphinx-build -E` has been called, which in essence suggests the user wishes to remove cached data before building.

This commit adds the `Sphinx.fresh_env_used` public property, exposing `Sphinx._fresh_env_used` in an immutable manner.
2024-06-03 12:01:10 +02:00
Chris Sewell 548f0f928a 👌 Allow access to the parser during the read phase (#12361)
This commit allows access to the `Parser` instance during the read phase, using the read-only property `BuildEnvironment.parser`.

This aims to allow for parser agnostic logic within roles and directives,
as opposed to hard-coding for implementation details of the default docutils `RSTParser`.
2024-05-21 14:46:43 +02:00
Chris Sewell 43276dcbac 🔧 add tox environment for mypy (#12376) 2024-05-15 07:18:31 +02:00
Chris Sewell 71d50a8658 🔧 Update ruff v0.4.4 (#12375) 2024-05-15 07:00:55 +02:00
Chris Sewell 92b30c26e0 DOCS: Add changelog for #12319 (#12374) 2024-05-15 06:38:14 +02:00
Chris Sewell 3496de62b7 🧪 Fix python 3.13 tests (#12373) 2024-05-15 06:28:40 +02:00
Chris SewellandAdam Turner 3dcd21af95 Split `sphinx.ext.intersphinx._resolve`
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-04-25 15:30:55 +01:00
Chris SewellandAdam Turner 49726c28f4 Split `sphinx.ext.intersphinx._load`
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-04-25 15:30:55 +01:00
Chris SewellandAdam Turner b9a3f7e3df Split `sphinx.ext.intersphinx._cli`
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-04-25 15:30:55 +01:00
Chris SewellandAdam Turner 3a1f2f377c Split `sphinx.ext.intersphinx._shared`
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-04-25 15:30:55 +01:00
Chris SewellandAdam Turner 56b793d1c2 Define `__all__`
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-04-25 15:30:55 +01:00
Chris SewellandAdam Turner 3e8b8ab2d9 Move `sphinx.ext.intersphinx` into a package
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-04-25 15:30:55 +01:00
Chris Sewell 430866e029 👌 Add warning log for config values that cannot be cached (#12203)
As a user and/or extension developer, it can be a source of confusion when,
on performing a `sphinx-build` for a cached project, 
an unchanged configuration variable is always marked as changed (triggering a full rebuild).

This is often due to the variable being an unpicklable value,
which is silently omitted from the cache (i.e. the `environment.pickle`).

This commit introduces a specific warning for when a configuration variable is omitted from the cache,
allowing users to understand the root of the problem.
2024-03-27 12:59:24 +01:00
Chris Sewell 448cb9931d 🔧 CI: fix Python 3.13 tests (#12210) 2024-03-27 12:45:24 +01:00
Chris Sewell 04bd0df100 👌 Improve external role warnings (and revert object fallback) (#12193)
The key issue this commit seeks to address, is that existing tools / documentation often lead users to mistakenly use object types and not role names, a classic example being `function` not `func`

Previously, the warning message for using e.g. `` external:function`target` `` (with `py` as the default domain), would be:

```
WARNING: role for external cross-reference not found: function
```

This gives no information to the user on how to fix the issue, even though there is actually quite an easy fix

This commit adds logic to create more specific / helpful warning messages, e.g.

```
WARNING: role for external cross-reference not found in domains 'py', 'std': 'function' (perhaps you meant one of: 'py:func', 'py:obj')
```

This goes through the same original logic but, if the role is not found, it will look if the role name is actually an available object type on the domain(s), and then suggest its related roles.

This commit also reverts #12133, which provided a (silent) fallback to auto convert an object type to a role name.
2024-03-25 14:39:51 +01:00
Chris Sewell 66fa790b3a [tests] Add basic build test for all builtin themes (#12168)
Add `tests/test_theming/test_theming.py::test_theme_builds`, which is a parametrized test against all builtin sphinx HTML themes, that tests:

1. that the themes builds without warnings for a basic project, and
2. that all `.html` files it produces are valid XML (see https://html.spec.whatwg.org/)

https://pypi.org/project/defusedxml/ was added to the test dependencies, in order to safely parse the XML

This required one fix for `sphinx/themes/basic/search.html`, and one for `sphinx/themes/bizstyle/layout.html`

Also, `tests/test_theming` was removed from the `ruff format` exclude list
2024-03-22 12:57:34 +01:00
Chris SewellandBénédikt Tran d59b158371 👌 Make ExtensionMetadata type public and use it in internal extensions (#12153)
This type alias has now been fully documented for public consumption.

This will be beneficial to the sphinx ecosystem,
to aide/encourage extension developers to provide the correct metadata.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-03-21 16:19:26 +01:00
ace9d97500 👌 Improve signature and type annotations for SphinxLoggerAdapter.warning (#12154)
This commit overrides the  `SphinxLoggerAdapter.warning` method,
to provide documentation and type annotations specific to logging sphinx warnings.
This should aide sphinx core/extension developers in creating good warnings.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: danieleades <33452915+danieleades@users.noreply.github.com>
2024-03-21 15:41:22 +01:00
Chris Sewell b45fee696f 🔧 Sync make doclinter with CI check (#12156)
Unignore files in `make doclinter` command, fix the resulting issues, and use this command in the CI job
2024-03-21 13:12:06 +01:00
Chris SewellandBénédikt Tran d908886c03 📚 add tip about running karma js tests on mac (#12140)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-03-20 21:55:34 +01:00
Chris Sewell 2d6f73ed68 🔧 Ruff format select sphinx modules with minimal diffs (#12146)
This comit removes select sphinx top-level modules from the `ruff format` exclude list.
They were selected based on the fact that they have the least diffs when formatted,
are not believe to introduce changes that would adversely affect any existing PRs.
2024-03-20 21:28:10 +01:00
Chris Sewell 392358d4de 🔧 Ruff format python files within utils folder (#12142)
Remove from `exclude` list
2024-03-19 19:32:28 +01:00
Chris Sewell 3bedde26a9 🔧 Ruff format python files within docs folder (#12139)
Remove `docs` files from the `exclude` list, and also add the `preview = false` format config, which is shown to reduce diffs to the current code base
2024-03-19 15:23:57 +01:00
Chris SewellandBénédikt Tran 565d4104d5 👌 Handle external references pointing to object types (#12133)
This commit fixes the issue of `objects.inv` denoting object names, whilst the `external` role only allows for role names. 

As an example, take the `objects.inv` for the sphinx documentation, which contains:

```
py:function
    compile                  : usage/domains/python.html#compile
```

A user might understandably expect that they could reference this using `` :external:py:function:`compile` ``, but actually this would previously error with:

```
WARNING: role for external cross-reference not found: py:function
```

this is because, `function` is the object type, yet `external` expects the related role name `func`.

It should not be necessary for the user to know about this distinction,
so in this commit, we add logic, to first look if the name relates to a role name (as previous, to not be back-breaking) but, if not, then also look if the name relates to an object that has a known role and, if so, use that.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-03-19 13:42:50 +01:00
d8cf71cbde 🔧 Setup ruff format (initially excluding all files) (#12136)
Co-authored-by: danieleades <33452915+danieleades@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-03-19 10:27:41 +01:00
Chris SewellandBénédikt Tran b0f096f440 ✨ Add show_warning_types configuration variable (#12131)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-03-19 10:22:28 +01:00
Chris Sewell 3f3d3d8517 🔧 Add flake8 to make style-check (#12137) 2024-03-19 10:07:41 +01:00
Chris Sewell aaecc9376d 🔧 Remove unused regexes (#12132)
These appear to have been copied to class variables at some point, but then not removed as global variables
2024-03-19 09:36:22 +01:00
Chris SewellandBénédikt Tran a27f156e31 🔧 Add check rule to Makefile (#12135)
To run all linting/type-checking, just for dev ease

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-03-19 09:34:34 +01:00
Chris Sewell 9019144590 remove type: ignore 2021-04-23 22:40:07 +02:00
Chris Sewell c47f8aa6d1 🐛 FIX: Config.__getitem__ typing 2021-04-23 22:40:07 +02:00
Chris Sewell 088d059196 minor typing fix 2021-01-20 04:43:39 +00:00
Chris Sewell 46177f6af3 Correct numbers 2020-08-21 01:58:28 +01:00
Chris Sewell 5c744d8342 📚 DOCS: Improve build process overview 2020-08-20 22:37:37 +01:00
Chris Sewell 08d7b4de2e modify deprecated method 2019-03-08 14:10:14 +00:00
Chris Sewell a88078ec73 Merge remote-tracking branch 'upstream/2.0' into propogate_citeref_classes 2019-03-08 14:05:20 +00:00
Chris Sewell b74dbeb87a propogate cite_reference node classes to pending_xref node 2019-03-08 00:26:51 +00:00