Skip to content

Conversation

Rouslan
Copy link
Contributor

@Rouslan Rouslan commented Jan 24, 2024

This pull request, along with the improvement made in the upcoming version 7.3 of sphinx, should fix the issue of Breathe being too slow.

The changes in this pull request are massive and I understand that the maintainers have very little time to spare, so I don't expect this will be merged right away, and I don't mind putting in more work if it's needed to get this accepted.

@Rouslan
Copy link
Contributor Author

Rouslan commented Aug 2, 2024

I finished the merge.

I understand now what the purpose for breaking up the pull request would be. It's certainly possible, but it would take a while. I would have go through all my commits, one by one, and either selectively undo certain changes, or conversely, create a new branch and selectively apply certain changes. I would need to go through all the commits multiple times and reapply the changes for the subsequent pull requests. By the time I'm done, there would probably be new changes in the original repository, and translating new changes from the old code into the new code is also not fun. Either way, the first pull request would still be the biggest because the parser's data types permeate so much of the code. There was even code in the original parser that had to be moved outside the parser because it was specific to a much later step in Breathe's operation.

I'm not enthusiastic about doing that. I would have to be convinced that smaller pull requests are worth the effort.

Also, in case the tone of this text comes off as negative: I wish to clarify that I didn't mind being asked.

@JasperCraeghs
Copy link
Contributor

JasperCraeghs commented Apr 14, 2025

The build log contains the following warning twice when I build my project documentation with this PR (I use Doxygen 1.12.0):

/home/developer/venv/lib/python3.11/site-packages/breathe/_parser.py:2274: ParseWarning: Warning on line 65: unexpected element "simplesect"
  warnings.warn(ParseWarning(f'Warning on line {self.parser.CurrentLineNumber}: {msg}'))

@michaeljones
Copy link
Collaborator

@Rouslan - to clarify, your work still depends on the C parser code in this branch? I had the vaguest idea that you'd tried that route and then didn't need the C code in the end but maybe I was wrong.

@Rouslan
Copy link
Contributor Author

Rouslan commented Apr 17, 2025

@michaeljones No, the C version is no longer generated. I didn't delete the template for the C version right away and I ended up forgetting about it until now. It can be safely removed.

@michaeljones
Copy link
Collaborator

@Rouslan - Ok, good to know. Thank you for the quick response. I'll delete the xml_parser_generator folder and anything that touches it? I guess?

@Rouslan
Copy link
Contributor Author

Rouslan commented Apr 17, 2025

@michaeljones Oh, you can't delete the whole folder, only "module_template.c.in". The Python version of the parser is also generated.

@Rouslan
Copy link
Contributor Author

Rouslan commented Apr 20, 2025

@JasperCraeghs I have updated the parser and there shouldn't be any more parse warnings (at least until a new version of Doxygen comes out). Please let me know if any show up.

@michaeljones
Copy link
Collaborator

What is the best practice for from __future__ import annotations these days? We seem to have it in a lot of files by not all? Should it be in all? Or just the top level entry point files? Or any file that uses annotations of some kind?

@michaeljones
Copy link
Collaborator

And for type checking, do we want the:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from sphinx.application import Sphinx

pattern everywhere that we use it? When does that last non-type-aware python version end-of-life? Looks like 3.9 will EOL by the end of this year.

@Rouslan
Copy link
Contributor Author

Rouslan commented May 29, 2025

I don't know what the best practice is, but I have been adding from __future__ import annotations as needed. This import changes Python's behavior so that annotations are not evaluated until they are needed. This means they can refer to classes defined later in the file, without needing to use string literals. This also means mutually recursive imports are not an issue for type checking because the names in annotations are not looked up until after all the modules are scanned.

This is also why if TYPE_CHECKING: is used. This is not for compatibility with multiple Python versions. TYPE_CHECKING is only true when Mypy or some other type checker is reading the code. Some modules are only imported because their types are used in annotations. By only importing when TYPE_CHECKING is true, the modules are only loaded when checking types, not when running code normally.

@michaeljones michaeljones merged commit a3a6870 into breathe-doc:main Jul 8, 2025
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.

6 participants