8000 Fix attribute errors, address code-blocks by StaticRocket · Pull Request #107 · rstcheck/rstcheck-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix attribute errors, address code-blocks #107

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

StaticRocket
Copy link

Take a stab at addressing the attribute errors in sphinx now by eliminating the dynamic loader. A single instance of sphinx will be created at launch if sphinx is present on the system.

Also, address the warning about being unable to determine the line of a code-block by generating one from the information available in the parent node.

Let me know if there's anything else that needs addressing here. This is the first project I've played with that uses tox.

Resolves: #3

  • I added tests for the changed code.
  • I updated the documentation for the changed code.
  • I ran the full tox test suite locally, so the CI pipelines should be green.
  • I added the change to the CHANGELOG.md file.

@StaticRocket
Copy link
Author

Ah, just noticed that in fixing this I've exposed a bug in _get_code_block_directive_line . This function cannot currently handle parsing nodes from included files. It attempts to search the current source instead of the node's source.

@StaticRocket
Copy link
Author

Ah, just noticed that in fixing this I've exposed a bug in _get_code_block_directive_line . This function cannot currently handle parsing nodes from included files. It attempts to search the current source instead of the node's source.

Well, I have a fix for that, but I can't get the tests to actually pick up the error. I may need a little help (or at least someone to verify I'm not crazy).

@Cielquan
Copy link
Contributor

Hey, thanks for filing this PR.
This week my schedule is pretty tight. Maybe I can find a time slot, but next week is more likely.

This was a neat idea, but unfortunately upstream sphinx keeps multiple
references to itself and internal structures, making a web of variables
that do not leave the execution context once loaded.

This causes a litany of parsing errors that have only gotten worse as
sphinx progresses. For now, load one instance of sphinx to interact with
if sphinx is available on the system.

Signed-off-by: Randolph Sapp <rs@ti.com>
Try and generate a line number for a code-block in the event one is not
provided. Right now this only seems to occur with indented code-blocks,
which means we should be able to gleam some information from the parent
node if it exists.

Signed-off-by: Randolph Sapp <rs@ti.com>
Update the code-block example to also have a valid include file. This
should generate an index error in _get_code_block_directive_line
currently.

Signed-off-by: Randolph Sapp <rs@ti.com>
Handle code-blocks from files being included by fetching and operating
on the source of the included file as needed.

Add a function to iterate through parent nodes until we get a source
since there is a chance the code-block could be nested several layers
below other directives.

Signed-off-by: Randolph Sapp <rs@ti.com>
Copy link
Contributor
@Cielquan Cielquan left a comment

Choose a reason for hiding this comment

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

Sorry for the late reply. I simply forgot.

Please also remove the "Known issues" section in the docs/source/faq.rst file. The only issue stated there is the one fixed with this PR. Line 13-40 can be removed.

The rest LGTM.

@@ -397,21 +394,16 @@ def test_code_block_without_language_is_works_with_sphinx_pre310(
"""
ignores = types.construct_ignore_dict()
# fmt: off
Copy link
Contributor

Choose a reason for hiding this comment

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

All 6 remaining fmt comments can be removed. They were there to fixate the empty line between the now removed context manager and the variable assignement.

@StaticRocket
Copy link
Author

Hey, thanks for reviewing this, we've been running it in production for a little bit over here: https://github.com/TexasInstruments/processor-sdk-doc/

I've noticed one potential regression around code-blocks: the sphinx version of the code-block directive doesn't like the additional parameters (like :name: or :caption:). Have not tested this to see if it is actually a regression. Out of curiosity, do you remember any similar issues in the past?

I'll take a swing at it later today if it is a regression. If not I'll put it on a different PR since this one is creeping.

@Cielquan
Copy link
Contributor

From the top of my head I cannot recall any issues so far, but I am not working much with rst files since like 2 years or so and for code blocks I think I only used the :language: parameter.

@StaticRocket
Copy link
Author

Alright, it is unfortunately a regression. Seems that the code-block directive is just being aliased to the default code directive and doc-utils is being passed the sphinx specific parameters. I'll take a swing at that before addressing the above.

@StaticRocket
Copy link
Author

Ah, it's an issue with reloading docutils and not reloading sphinx at the same time. Unfortunately reloading sphinx did not work well the last time I tested that, even with a custom recursive module reload function.

@StaticRocket
Copy link
Author

Ah, well, upstream sphinx was already addressing most of the state issues they had during testing using this:

https://github.com/sphinx-doc/sphinx/blob/72ce43619c12319e71d9edc0079fc3976dfa522f/sphinx/testing/util.py#L256-L271

This PR can be dramatically simplified. Let me fix that.

@StaticRocket
Copy link
Author

New issue. There's a problem with multiprocessing and attempting to interact with global caches. Technically this was always an issue. Now it's just glaringly obvious.

@Cielquan
Copy link
Contributor
Cielquan commented Jun 1, 2025

Hi, how is the state of this PR? Things still need changes?

@StaticRocket
Copy link
Author
StaticRocket commented Jun 2, 2025

Yeah, sorry about that. Got sidetracked in some other issues. I still need to take a good look at this.

I've thought about (ab)using subprocesses to promote proper isolation between threads and sphinx instances. Even using the sphinx test helper functions, there seems to be some state either kept in it or docutils that negatively affects parsing of future documents. Messy stuff.

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

Successfully merging this pull request may close these issues.

code blocks without language error with sphinx
2 participants
0