Skip to content

fix: don't abort rST render when :scale: image can't be sized#359

Open
miketheman wants to merge 1 commit into
pypa:mainfrom
miketheman:miketheman/304-image-scale
Open

fix: don't abort rST render when :scale: image can't be sized#359
miketheman wants to merge 1 commit into
pypa:mainfrom
miketheman:miketheman/304-image-scale

Conversation

@miketheman
Copy link
Copy Markdown
Member

When a reST image directive uses :scale: without both explicit :width: and :height:, docutils' image_size() calls read_size_with_PIL() to fill in the missing dimensions.
With file_insertion_enabled=False (set for security to block .. include::-style file reads) and PIL unavailable for arbitrary URLs, that probe fails and emits a WARNING/2.
Combined with halt_level=2, the warning is upgraded to a SystemMessage and render() returns None, breaking twine check --strict for any README with a scaled badge.

Override read_size_with_PIL on ReadMeHTMLTranslator to short-circuit to None silently. The image then renders at its natural size (or with whatever dimension the user did provide) instead of aborting the entire render. No security regression: we still don't read external files; we just decline to warn about not reading them.

Closes #304

When a reST image directive uses :scale: without both explicit
:width: and :height:, docutils' image_size() calls read_size_with_PIL()
to fill in the missing dimensions.
With file_insertion_enabled=False (set for security to block
.. include::-style file reads) and PIL unavailable for arbitrary URLs,
that probe fails and emits a WARNING/2.
Combined with halt_level=2, the warning is upgraded to a SystemMessage
and render() returns None, breaking `twine check --strict` for any
README with a scaled badge.

Override read_size_with_PIL on ReadMeHTMLTranslator to short-circuit
to None silently. The image then renders at its natural size (or with
whatever dimension the user did provide) instead of aborting the
entire render. No security regression: we still don't read external
files; we just decline to warn about not reading them.

Closes pypa#304

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@miketheman miketheman requested a review from di April 25, 2026 00:42
@miketheman miketheman added the bug label Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

twine check fails when badges have a scale factor ...

1 participant