Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit "source-read" events for files read via the include directive #11510

Merged
merged 29 commits into from
Aug 14, 2023

Conversation

halldorfannar
Copy link
Contributor

@halldorfannar halldorfannar commented Jul 24, 2023

Subject: Extend Sphinx to emit "source-read" events for RST files coming in via include directive.

Feature or Bugfix

  • Bugfix

Purpose

Detail

Changes are well documented - please consult the code. Added a thorough unit test to expose the issue and fix it.

Relates

Our unit test is now passing.
Why doesn't the project apply these changes automatically on the main branch?
These tests needed to change with the introduction
of the derived class `sphinx.parsers.RSTStateMachine`.
Noting that docutils 0.18 introduced the marker.
sphinx/parsers.py Outdated Show resolved Hide resolved
sphinx/parsers.py Outdated Show resolved Hide resolved
tests/test_directive_other.py Show resolved Hide resolved
CHANGES Outdated Show resolved Hide resolved
This reverts commit 4c727ce.
The subclassing will not work because docutils doesn't use Sphinx's rst
parser for processing the included
rst text.  This is a shame, and
strictly speaking an issue in Sphinx/docutils.
So we go back to monkey patching.
It works, the change is now better contained inside Sphinx Include directive.
Added a unit test to verify that
includes of includes are correctly
handled.
@halldorfannar
Copy link
Contributor Author

@picnixz Docutils HEAD is busted - doesn't work with Sphinx. I tried the 7.0.x branch and it fails the same way. That is the only failure on this PR. Do we wait for this to get fixed?

@picnixz
Copy link
Member

picnixz commented Jul 26, 2023

Ah yes, that docutils HEAD failing test. I've had one even before (#11486 (comment)) but I don't know the reason. At first, I thought it was because it's getting the dev version of docutils (and then you get docutils 0.21dev or something like that) but sometimes it works and sometimes not. Just ignore it for now.

@AA-Turner Do you have any idea why the test fails ? (and why it fails on other PRs that do not touch at all the docutils layout?)

EDIT: One possibility is that there is some race condition and outputs are wiped out before being tested or something like that.

@AA-Turner
Copy link
Member

571becb should have fixed this. I’m travelling today, will look when I return.

A

These are not part of my change but mysteriously now
cause failure in CI.
@halldorfannar halldorfannar changed the base branch from 7.0.x to 7.1.x July 31, 2023 16:44
@halldorfannar
Copy link
Contributor Author

All righty then, by targeting the new 7.1.x branch we have docutils passing. Everything else is also passing.

@halldorfannar
Copy link
Contributor Author

@AA-Turner @picnixz I believe this PR is ready.

@AA-Turner AA-Turner changed the base branch from 7.1.x to master August 3, 2023 02:11
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering but do you think it's worth to actually have this behaviour disabled by default? because if there are a lot of included files that are actually not processed by the source-read event, then the overhead might not be negligible for very large projects (I don't know if large projects use include directives a lot or not). Maybe it's good to avoid slowing down builds (you essentially perform "join/splits" twice which probably increases your build time by 10-20% if you have a lot of files). If my question is actually a non-question, LGTM.

CHANGES Show resolved Hide resolved
sphinx/directives/other.py Outdated Show resolved Hide resolved
@AA-Turner AA-Turner changed the title Issue #10678: Fix for "source-read" event not being emitted for included RST files Emit "source-read" events for files read via the include directive Aug 5, 2023
@halldorfannar
Copy link
Contributor Author

Just wondering but do you think it's worth to actually have this behaviour disabled by default? because if there are a lot of included files that are actually not processed by the source-read event, then the overhead might not be negligible for very large projects (I don't know if large projects use include directives a lot or not). Maybe it's good to avoid slowing down builds (you essentially perform "join/splits" twice which probably increases your build time by 10-20% if you have a lot of files). If my question is actually a non-question, LGTM.

Yes, I think this is worth while. We would then make it a configuration variable to have this functionality enabled. You will need to suggest what it should be named. But how would that effect the tests? I would need to see how we can enable the config variable for each test. Shouldn't be hard. The patch is also done "just-in-time" so it is easy to turn on and off.

@AA-Turner
Copy link
Member

@halldorfannar is there anything outstanding here from your perspective?

A

@AA-Turner AA-Turner merged commit 0bad447 into sphinx-doc:master Aug 14, 2023
@AA-Turner
Copy link
Member

Thanks!

A

@johannesloibl
Copy link

In my case this fix triggers an infinite recursion, because the included file contains a custom directive that uses self.state_machine.insert_lines. That leads to triggering the source-read hook on the same file again.

Worked around by also using StateMachine.insert_input(self.state_machine, ...) though, put took me a while to understand why my build deadlocked...

Maybe worth mentioning, since other directives doing similar things may break too. (like maybe longturn/freeciv21#2023)

@AA-Turner
Copy link
Member

@johannesloibl please may you open a new issue for further discussion?

A

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

source-read event does not modify include'd files source
4 participants