Skip to content

FIX: Gracefully handle empty files for imgmath depth extraction - #14468

Open
timhoffm wants to merge 3 commits into
sphinx-doc:masterfrom
timhoffm:fix-imgmath
Open

FIX: Gracefully handle empty files for imgmath depth extraction#14468
timhoffm wants to merge 3 commits into
sphinx-doc:masterfrom
timhoffm:fix-imgmath

Conversation

@timhoffm

@timhoffm timhoffm commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Closes #14466.

While empty files are unexpected and likely an error, read_svg_depth() is not the place to flag empty files. It is designed to handle files without depth comment, and that should also be true for the edge case of an empty file.

timhoffm and others added 2 commits June 4, 2026 09:54
Closes sphinx-doc#14466.

While empty files are likely an error `read_svg_depth()` is not the place to flag empty files. It is designed to handle files without depth comment, and that should also be true for the edge case of an empty file.

@jdillard jdillard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. The only concern I see (and it is a small one), is that the whole SVG is loaded into memory with list(f). To keep the small line buffer you could do something like:

with open(filename, encoding='utf-8') as f:
    line = None
    for line in f:
        pass
if line is not None:
    if matched := depthsvgcomment_re.match(line):
        return int(matched.group(1))
return None

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.

Sporadic Sphinx parallel build error - unbound local variable "line"

2 participants