diff --git a/sphinx/conf.py b/sphinx/conf.py index 949c541..c894646 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -124,6 +124,7 @@ linkcheck_ignore = [ "https://docs.jax.dev/en/latest/notebooks/thinking_in_jax.html", "https://docs.quantinuum.com/selene", + r"https://[a-z0-9-]+\.stackexchange\.com/", ] linkcheck_rate_limit_timeout = 100 @@ -186,5 +187,28 @@ def skip_member(app, what, name, obj, skip, options): return None +def prune_sourceless_viewcode_modules(app): + """Drop viewcode entries for modules whose source could not be read. + + ``sphinx.ext.viewcode`` stores ``False`` for a module it could not read the + source of (e.g. the compiled ``builtins`` module) and never writes a page + for it, but its ``_modules`` index is built from every module it saw, so it + links to pages that do not exist. Pruning them before viewcode's own + ``html-collect-pages`` handler (hence the lower priority) keeps the index + limited to modules that actually get a page. + + The ``not entry`` test mirrors the skip condition in viewcode's own + ``collect_pages``, so exactly the modules it declines to render are removed. + Entries for real modules are ``(code, tags, used, refname)`` tuples and are + therefore always truthy. + """ + modules = getattr(app.env, "_viewcode_modules", None) + if modules: + for modname in [name for name, entry in modules.items() if not entry]: + del modules[modname] + return () + + def setup(app): app.connect("autodoc-skip-member", skip_member) + app.connect("html-collect-pages", prune_sourceless_viewcode_modules, priority=100) diff --git a/sphinx/getting_started.md b/sphinx/getting_started.md index fcbbc59..1d17b2f 100644 --- a/sphinx/getting_started.md +++ b/sphinx/getting_started.md @@ -44,7 +44,7 @@ The intermediate state of the qubits as the circuit progresses is annotated abov To implement this circuit in Guppy, we define a Python function with the [`@guppy`](https://docs.quantinuum.com/guppy/api/decorator.html) decorator. Since our circuit takes no input, the function does not have to have any parameters. Similarly, as the circuit prepares a single-qubit state, we must annotate the function with this as the corresponding return type. -We can also record the outcome of the mid-circuit measurement for later evaluation using `output`, as this will make it available to the user after we run the simulation. Note that the `measure` function returns a [dedicated `Measurement` type](https://docs.quantinuum.com/guppy/language_guide/measurement). +We can also record the outcome of the mid-circuit measurement for later evaluation using `output`, as this will make it available to the user after we run the simulation. Note that the `measure` function returns a [dedicated `Measurement` type](https://docs.quantinuum.com/guppy/language_guide/measurement.html). ```{code-cell} ipython3 from guppylang import guppy