How to access data written to "env" in "env-get-outdated" from "html-page-context"?

Skip to first unread message

Matthias Geier

Feb 2, 2021, 1:44:38 PMFeb 2
Dear list.

I'm writing a Sphinx extension where I'm collecting some information
about each source file including their dependencies.

I'm doing this in the "env-get-outdated" event handler and I'm writing
the resulting information as an attribute to "env".

Now I would like to access this information from the
"html-page-context" event handler in order to manipulate the "context"
(individually for each HTML file).

However, the data I was writing to "env" doesn't seem to be available
in "app.env" when inside the "html-page-context".

Those two "env" instances seem to be different ...?

Am I using the wrong event handler?
Which one should I use?

Or in other words:

How can I write some data to the build environment (in an event
handler where I have access to all document names and their
dependencies) and then use this information to update the HTML context
of each page?


Matthias Geier

Feb 3, 2021, 6:51:19 AMFeb 3
Dear list.

In case somebody is interested, I found the problem: I was indeed
using the wrong event handler!

I was collecting data for added and changed source files in
"env-get-outdated" and stored it as attribute of the `env` variable.

However, I was also using "env-purge-doc", which was running after
"env-get-outdated" and was deleting all my data again!
That's why it wasn't available in `app.env` in "html-page-context".

To solve this I have moved my data collection from "env-get-outdated"
to "env-updated". In order to know which source files have changed,
I'm using "source-read" to mark new/changed files.
Finally, to make this also work for parallel builds, I use
"env-merge-info" to merge all information obtained in "source-read".

Now it works as expected!

Reply all
Reply to author
0 new messages