Sphinx: Sphinx 2.4.0 fails on including svg files due to parsed float dimensions

Created on 9 Feb 2020  路  2Comments  路  Source: sphinx-doc/sphinx

Describe the bug
After updating to Sphinx 2.4.0 my HTML builds start failing due to imagesize.get() returning float values.

Exception occurred:
  File "/home/user/.cache/pypoetry/virtualenvs/project-TWo7gGTJ-py3.8/lib/python3.8/site-packages/sphinx/writers/html5.py", line 548, in visit_image
    atts['width'] = int(atts['width']) * scale
ValueError: invalid literal for int() with base 10: '5760.0'

To Reproduce
Steps to reproduce the behavior:

Include an SVG figure

.. figure:: ./img/some_svg.*
   :scale: 100

The error is raised at html5.py:#L548 and due to the returned float values at images.py#L45.

Expected behavior
Image dimensions are converted to int, e.g. like:

size = imagesize.get(filename)
if size[0] == -1:
    size = None
elif isinstance(size[0], float) or isinstance(size[1], float):
    size = (int(size[0]), int(size[1]))

Environment info

  • OS: [Manjaro 18.1.5 Juhraya]
  • Python version: [3.8.1]
  • Sphinx version: [2.4.0]
bug html

All 2 comments

Sorry for inconvenience. I'll fix this soon.

Fixed in #7122
It will be released within a day. Please wait a moment.

Was this page helpful?
0 / 5 - 0 ratings