click_extra.sphinx.parallel moduleΒΆ

Make a parallel Sphinx read index what a serial read indexes.

A parallel read, started with --jobs, shares the documents among worker processes, then merges what each worker read into the environment of the main process. A serial read reads every document in one process, in name order. Two things then differ between the two reads.

The first is the merge of the Python domain. PythonDomain.merge_domaindata copies the entries of each worker over the ones in place. So the alias that a page re-exporting an object declares with :canonical: can replace the definition that the page of its module registered in another worker. A serial read keeps the definition, because PythonDomain.note_object never lets an alias replace one. This module puts back each definition that an alias replaced. The cross-references to such an object then lead to the page of its module, and so do the [docs] links of click_extra.sphinx.viewcode.

The second is what a worker does not see of the other documents. To find the type of a documented attribute, autodoc copies the annotations of the source of a module into the __annotations__ of that module and of its classes. These include the self.x: T of an __init__ and the names of an if TYPE_CHECKING: block, and autodoc lists each name of __annotations__ as a member. So a page lists these names only after another page has documented an attribute of the same module, which in a parallel read can happen in another worker. This module copies the annotations before autodoc lists the members of a module or a class, so that every read lists the same members.

Todo

Delete keep_definitions_over_aliases() once sphinx-doc/sphinx#14885 is fixed. Delete copy_source_annotations() once sphinx-doc/sphinx#14890 and sphinx-doc/sphinx#14891 are both fixed: from Python 3.14 on, it also keeps autodoc from dropping the fields that a TypedDict inherits. Each function goes when the floor of the sphinx extra passes the releases with its fixes, and the module goes with the last of them.

click_extra.sphinx.parallel.AUTODOC_EXTENSION = 'sphinx.ext.autodoc'ΒΆ

Module name of the extension whose member lists copy_source_annotations() keeps from following the read order.

click_extra.sphinx.parallel.forget_merged_definitions(app, env, docnames)[source]ΒΆ

Empty the record of keep_definitions_over_aliases() before a read.

Connected to env-before-read-docs, so a read restores only the definitions of its own workers, never one from an earlier build in the same process.

Return type:

None

click_extra.sphinx.parallel.keep_definitions_over_aliases(app, env, docnames, other)[source]ΒΆ

Put back each Python definition that the alias of a later worker replaced.

Connected to env-merge-info, which fires in the main process each time a parallel read has merged the entries of a worker. Records each definition the worker brings, and puts the recorded definition back over each alias the worker brings for the same name, as a serial read keeps it. A worker holds the entries of the documents it did not read too, but merges only those of docnames, so only those count. Inert in a serial read, which merges no worker.

Return type:

None

click_extra.sphinx.parallel.copy_source_annotations(app, what, name, obj, options, lines)[source]ΒΆ

Annotate a module or a class from its source before autodoc lists members.

Connected to autodoc-process-docstring, which fires for a module or a class before autodoc gathers its members. For a class, the module of each class of its MRO gets annotated, as a class also lists the annotations of its bases.

Return type:

None

click_extra.sphinx.parallel.connect_source_annotations(app)[source]ΒΆ

Connect copy_source_annotations() once every extension is set up.

Connected to builder-inited, so sphinx.ext.autodoc has registered its events whatever its place in extensions. Inert without autodoc, and with autodoc_use_type_comments off, which keeps autodoc from copying any annotation.

Return type:

None

click_extra.sphinx.parallel.setup(app)[source]ΒΆ

Register the parallel-read fixes on app.

Called from click_extra.sphinx.setup() so projects only need to list "click_extra.sphinx" in their extensions. The two merge hooks are inert in a serial read, which merges no worker. The annotation hook steadies the members of a serial read too, whose pages also follow one another.

Return type:

None