Skip to content
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

Markdown tables break texinfo builder because of float colspec #540

Closed
n-peugnet opened this issue Mar 29, 2022 · 4 comments · Fixed by #568
Closed

Markdown tables break texinfo builder because of float colspec #540

n-peugnet opened this issue Mar 29, 2022 · 4 comments · Fixed by #568
Labels
bug Something isn't working

Comments

@n-peugnet
Copy link
Contributor

n-peugnet commented Mar 29, 2022

Describe the bug

context
When I run make texinfo using markdown tables...

expectation
Build should succeed.

bug
But instead it fails with:

Exception occurred:
  File "/home/nicolas/GoogleDrive/Projets/Club1/sphinx-myst-table-texinfo/.venv/lib/python3.9/site-packages/sphinx/writers/texinfo.py", line 1014, in visit_colspec
    self.body.append('{%s} ' % ('x' * (n + 2)))
TypeError: can't multiply sequence by non-int of type 'float'

problem
This is a problem because it prevents from building info pages.

cause
MyST seems to generate incorrect colspecs, containing floats, when Sphinx texinfo builder seems to expect ints:

<colspec colwidth="50.0"/>
<colspec colwidth="50.0"/>

Maybe this should be fixed in Sphinx instead, by making sure n is an int here:

https://github.com/sphinx-doc/sphinx/blob/223b1a94f2cd1d2af6297fa419ab96758ddd31e2/sphinx/writers/texinfo.py#L1014

Reproduce the bug

Here is a reproducer:

virtualenv .venv
. .venv/bin/activate
pip install sphinx myst-parser
sphinx-quickstart --sep -p test -a test -v test -r test -l en --extensions myst_parser
rm source/index.rst
echo '# Hello world!

```{toctree}
---
maxdepth: 2
caption: test
---

```

| col1 | col2 |
|------|------|
| val1 | val2 |
' > source/index.md
make texinfo

List your environment

  • Debian bookworm
  • Python 3.9.12

all python programs installed via pip in a virtualenv:

alabaster==0.7.12
attrs==21.4.0
Babel==2.9.1
certifi==2021.10.8
charset-normalizer==2.0.12
docutils==0.17.1
idna==3.3
imagesize==1.3.0
importlib-metadata==4.11.3
Jinja2==3.1.1
markdown-it-py==2.0.1
MarkupSafe==2.1.1
mdit-py-plugins==0.3.0
mdurl==0.1.0
myst-parser==0.17.0
packaging==21.3
Pygments==2.11.2
pyparsing==3.0.7
pytz==2022.1
PyYAML==6.0
requests==2.27.1
snowballstemmer==2.2.0
Sphinx==4.5.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
typing_extensions==4.1.1
urllib3==1.26.9
zipp==3.7.0
@n-peugnet n-peugnet added the bug Something isn't working label Mar 29, 2022
@welcome
Copy link

welcome bot commented Mar 29, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@AdamLatos
Copy link

Same thing with text builder:

Exception occurred:
  File "(...)/site-packages.sphinx/writers/text.py", line 207, in writesep
    out.append(char * (width + 2))
TypeError: can't multiply sequence by non-int of type 'float'

@n-peugnet
Copy link
Contributor Author

This could be fixed by removing the second parameter of round() in this line:

colwidths = [round(100 / maxcols, 2)] * maxcols

@@ -909,7 +909,7 @@
 
         # column settings element
         maxcols = len(header_row.children)
-        colwidths = [round(100 / maxcols, 2)] * maxcols
+        colwidths = [round(100 / maxcols)] * maxcols
         tgroup = nodes.tgroup(cols=len(colwidths))
         table += tgroup
         for colwidth in colwidths:

But this may cause problems elsewhere.

@chrisjsewell
Copy link
Member

chrisjsewell commented Mar 29, 2022

Heya,
yeh so this is the equivalent code in docutils: https://github.com/live-clones/docutils/blob/6548b56d9ea9a3e101cd62cfcd727b6e9e8b7ab6/docutils/docutils/parsers/rst/directives/tables.py#L119

i.e. it uses the floor division operator: https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations,
so indeed we should do the same here 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants