ftnext / sphinx-new-tab-link

Open external links in new tabs of the browser in Sphinx HTML documents
https://ftnext.github.io/sphinx-new-tab-link/guide.html
MIT License
9 stars 2 forks source link

IndexError: pop from empty list #10

Open noname77 opened 1 year ago

noname77 commented 1 year ago

Hey, I just tried this extension and when enabling it im getting the following error:

# Loaded extensions:
#   sphinx.ext.mathjax (4.5.0) from /home/vscode/.local/lib/python3.10/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.4) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.2) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (2.0.1) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.5) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.3) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.13) from /home/vscode/.local/lib/python3.10/site-packages/alabaster/__init__.py
#   myst_parser (0.18.1) from /home/vscode/.local/lib/python3.10/site-packages/myst_parser/__init__.py
#   breathe (4.35.0) from /home/vscode/.local/lib/python3.10/site-packages/breathe/__init__.py
#   sphinx_csharp (unknown version) from /home/vscode/.local/lib/python3.10/site-packages/sphinx_csharp/__init__.py
#   sphinxcontrib.pdfembed (unknown version) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/pdfembed.py
#   sphinxcontrib.video (unknown version) from /home/vscode/.local/lib/python3.10/site-packages/sphinxcontrib/video.py
#   sphinx.ext.extlinks (4.5.0) from /home/vscode/.local/lib/python3.10/site-packages/sphinx/ext/extlinks.py
#   sphinx_new_tab_link (unknown version) from /home/vscode/.local/lib/python3.10/site-packages/sphinx_new_tab_link/__init__.py
#   pydata_sphinx_theme (unknown version) from /home/vscode/.local/lib/python3.10/site-packages/pydata_sphinx_theme/__init__.py
Traceback (most recent call last):
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app.build(args.force_all, filenames)
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/application.py", line 330, in build
    self.builder.build_update()
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 286, in build_update
    self.build(to_build,
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 350, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 524, in write
    self._write_serial(sorted(docnames))
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 534, in _write_serial
    self.write_doc(docname, doctree)
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 619, in write_doc
    self.docwriter.write(doctree, destination)
  File "/home/vscode/.local/lib/python3.10/site-packages/docutils/writers/__init__.py", line 78, in write
    self.translate()
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/writers/html.py", line 59, in translate
    self.document.walkabout(visitor)
  File "/home/vscode/.local/lib/python3.10/site-packages/docutils/nodes.py", line 227, in walkabout
    if child.walkabout(visitor):
  File "/home/vscode/.local/lib/python3.10/site-packages/docutils/nodes.py", line 227, in walkabout
    if child.walkabout(visitor):
  File "/home/vscode/.local/lib/python3.10/site-packages/docutils/nodes.py", line 227, in walkabout
    if child.walkabout(visitor):
  File "/home/vscode/.local/lib/python3.10/site-packages/docutils/nodes.py", line 240, in walkabout
    visitor.dispatch_departure(self)
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/util/docutils.py", line 533, in dispatch_departure
    method(node)
  File "/home/vscode/.local/lib/python3.10/site-packages/sphinx/writers/html.py", line 810, in depart_table
    super().depart_table(node)
  File "/home/vscode/.local/lib/python3.10/site-packages/docutils/writers/html4css1/__init__.py", line 852, in depart_table
    self.compact_p = self.context.pop()
IndexError: pop from empty list

Could it be due to using it with myst_parser extension and the links / documents being in markdown format?

best, wiktor

ftnext commented 1 year ago

@noname77 Thank you for using this extension. Sure, I want to resolve this issue, but it's tough to reproduce with the information you wrote.

Could you please provide the following details?

  1. dependencies in your environment
    • output of pip list is helpful.
  2. extensions in conf.py
  3. reST or Markdown file
    • I want to check the markup of the table as exceptions are being thrown in the depart_table method.
  4. If you have the code publicly available, could you share the repository URL for further examination?
noname77 commented 1 year ago

Thanks for a quick response,

  1. dependencies in your environment
python -m pip list ```bash $ python -m pip list Package Version ----------------------------- ---------- accessible-pygments 0.0.4 alabaster 0.7.13 appdirs 1.4.4 attrs 23.1.0 Babel 2.12.1 beautifulsoup4 4.12.2 black 22.12.0 breathe 4.35.0 cattrs 23.1.2 certifi 2023.7.22 charset-normalizer 3.2.0 click 8.1.7 colorama 0.4.6 commonmark 0.9.1 docutils 0.17.1 esbonio 0.16.1 exceptiongroup 1.1.3 idna 3.4 imagesize 1.4.1 Jinja2 3.1.2 lsprotocol 2023.0.0a3 markdown-it-py 2.2.0 MarkupSafe 2.1.3 mdit-py-plugins 0.3.5 mdurl 0.1.2 mypy-extensions 1.0.0 myst-parser 0.18.1 packaging 23.1 pathspec 0.11.2 pbr 5.11.1 pip 23.2.1 platformdirs 3.11.0 pydantic 1.10.12 pydata-sphinx-theme 0.13.0rc6 pygls 1.0.2 Pygments 2.16.1 pyspellchecker 0.7.2 PyYAML 6.0.1 requests 2.31.0 rich 12.6.0 rstcheck 6.1.2 rstcheck-core 1.0.3 setuptools 59.6.0 shellingham 1.5.3 snowballstemmer 2.2.0 soupsieve 2.5 Sphinx 4.5.0 sphinx-csharp 0.1.13 sphinx-new-tab-link 0.2.0 sphinx-panels 0.6.0 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.1 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-pdfembed 0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 sphinxcontrib-video 0.0.1.dev3 tomli 2.0.1 typeguard 3.0.2 typer 0.7.0 types-docutils 0.19.1.9 typing_extensions 4.7.1 urllib3 2.0.4 wheel 0.37.1 ```
  1. extensions in conf.py

    extensions = [
    "myst_parser",
    "breathe",
    "sphinx_csharp",
    "sphinxcontrib.pdfembed",
    "sphinxcontrib.video",
    "sphinx.ext.extlinks"
    ]
  2. I can't share the full file, but here are some table examples that seem to be causing this error:

table examples ```md | LLLLLLLL | DDDDDDDDDDD | |------------------------|-------------------------------------------------------------------------| | `CCCC` | Lorem ipsum, lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum. | | `AAAAAAAA` | Lorem ipsum, lorem ipsum lorem ipsum lore. | | `BBBBBBB` | Lorem ipsum, lorem ipsum lorem ipsum lor. | | `BBBBBBB/CCCCCCCCC` | Lorem ipsum, lorem ipsum lo. | | `BBBBBBBSSSSSSSSS` | Lorem ipsum, lorem ipsum lo. | | `DDDDDD` | Lorem ipsum, lorem ipsum lorem ipsum . | | `DDDDDD/CCCCCCCCCCC` | Lorem ipsum, lorem ipsum l. | | `DDDDDD/CCCCCCCCCCCCC` | Lorem ipsum, lorem ipsum lore. | | `DDDDDD/FFFFFFFF` | Lorem ipsum, lorem ip. | | `DDDDDD/PPPPPPPPPPP` | Lorem ipsum, lorem ipsum lorem ipsum lorem i. | | `DDDDDD/SSSSSSSS` | Lorem ipsum, lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum. | | `LLLLLLL` | Lorem ipsum, lorem ipsum lorem. | | `NNNNNNHHHHHHHH` | Lorem ipsum, lorem ipsum lorem ipsum lorem i. | | `PPPPPPPPPPP` | Lorem ipsum, lorem ipsu. | | `UUUUU` | Lorem ipsum, lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lo. | ``` ````md ```{eval-rst} +-----------------------------+-----------------------+-----------------------+ | **MMMMM NNNNNN** | **SSSSSSSS RRRRRRRR** | **FFFFFFFF RRRRRRRR** | +-----------------------------+-----------------------+-----------------------+ | AA0000 (AAA0-A / BBBBB) | 0.0 | 0.0.0 | + + +-----------------------+ | | | 0.0.0 | + + +-----------------------+ | | | 0.0.0 | +-----------------------------+-----------------------+-----------------------+ | BBBBBBBBBCCCCCCCC | 0.0.00 | 0.0.0 | + (BBBBB CCCCC) +-----------------------+-----------------------+ | | 0.0.00 | 0.0.0 | + + +-----------------------+ | | | 0.0.0 | + + +-----------------------+ | | | 0.0.0 | + + +-----------------------+ | | | 0.0.0 | +-----------------------------+-----------------------+-----------------------+ ``` ```` ```md | EEEEEE | PPPP | FFFF NNNN | FFFF FFFFFF | NNNNN | |----------------------|---------------------|----------------------------------------|------------------------------------------------------------------------------------------|-------| | AAAA | LLLL | BBBBBBBBBBB_\.BBB | Lorem ipsum lorem ipsum lorem ipsum lorem ips | | | AAAAAAAAA BBBBBBBB | FFFFFFFF | AAAAAAAAAAAAAAAAA.BBB | Lorem ipsum lorem ipsu: \,\,\ | | | CCCC DDDDDDD | FFFFFFFF | SSSSSSSSSSS.BBB | Lorem ipsum lorem ipsu: \,\,\,\ | | | EEEEEEEE FFFFFF | FFFFFFFF | \~\~\.BBB | Lorem ipsum lorem ipsum lorem ip | | | OOOOOO SSSSSSSS | SSSSSSSSSSS | SSSSSSS_\_\.BBB | Lorem ipsum lorem ipsuml | | | OOOOOOO SSSSSSSS | OOOOOOO | SSSSSSS_\_\.BBB | Lorem ipsum lorem ipsuml | | | PPPPPPPP SSSSSSSSSSS | PPPPPPPCCCCCCCCCCCC | CCCCCCCCCCCCCCC.BBB | Loremips lorem ipsum l: \;\;\ | | | FFFFFFF FFFFF | - (AAA BBBB) | BBBBBBBBBBBBBBBB.BBBB | AAAA BBBB | | ``` ````md ```{list-table} :align: center :class: table-some-class * - ```{figure} ../../../../static/fig1.png :alt: Fig. 1 ``` - ```{figure} ../../../../static/fig2.png :alt: Fig. 2 ``` ``` ```` ````md ```{eval-rst} +------------+----------------------------------------------------------------+ | **BBBB** | **FFFFFFFF / VVVVV** | +------------+----------------------------------------------------------------+ | **00-00** | lorem ipsumlorem **'AAAAA'**, lorem ipsum lorem ipsumlor | | | lorem i (a.b. 00) | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsum lorem ipsum lorem ipsum lorem i (a.b. 0.0.0) | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem ipsumm | | | (a.b. 0.0) | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsumlorem ipsum lore (00 00 lorem ipsumlorem ips) | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsumlorem 'loremips' lorem ipsum lorem ipsum lorem | | | ipsum lor | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsumlorem ipsumlorem ipsumlorem ip (lorem ips) | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsumlorem ipsumlorem ipsumlorem ipsumlorem | | | (lorem ips) | +------------+----------------------------------------------------------------+ | **00-00** | 0 lorem ipsum lorem (lorem ipsum l) | +------------+----------------------------------------------------------------+ | **00-00** | Lorem ipsum lorem ipsum lorem ipsum lorem ipsum lo | +------------+----------------------------------------------------------------+ ``` ```` ````md ```{eval-rst} +---------------------+-------------------------------------------------------+ | **AAAA** | **FFFFFFFF / VVVVV** | +---------------------+-------------------------------------------------------+ | **0-0** | AAAAAA (bbbbb ccccc - 0x00 0x00 0x00 0x00) | +---------------------+-------------------------------------------------------+ | **0-0** | Lorem ipsum lorem ipsu | +---------------------+-------------------------------------------------------+ | **\*** | +-----------+--------------------------------------+ | | | | **AAAA** | **FFFFFFFF / VVVVV** | | | | +-----------+--------------------------------------+ | | | | **0** | Lorem ipsum lorem ipsum l | | | | +-----------+--------------------------------------+ | | | | **0** | Lorem ipsum lorem (0-0) | | | | +-----------+--------------------------------------+ | +---------------------+-------------------------------------------------------+ ``` ````

After I removed all tables in the project, the error is gone and your extension works as expected :)

  1. unfortunately not

let me know if I can provide some further debug info

thanks, wiktor

ftnext commented 1 year ago

Thank you for the detail information.

After I removed all tables in the project, the error is gone and your extension works as expected :)

Sounds great!

I tried using the same versions of the libraries, but IndexError is not reproduced. Please let me know if you notice anything about the following procedure.

It seems like there's no link in the example table. Could it be an issue with sphinx-new-tab-link?


Environment

pip install docutils==0.17.1 Sphinx==4.5.0 sphinx-new-tab-link==0.2.0 myst-parser==0.18.1 breathe==4.35.0 \
git+https://github.com/rogerbarton/sphinx-csharp.git \
git+https://github.com/SuperKogito/sphinxcontrib-pdfembed.git \
sphinxcontrib-video==0.0.1.dev3
Environment detail ``` % python -V Python 3.11.4 % pip list Package Version ----------------------------- ---------- alabaster 0.7.13 Babel 2.13.0 breathe 4.35.0 certifi 2023.7.22 charset-normalizer 3.3.0 docutils 0.17.1 idna 3.4 imagesize 1.4.1 Jinja2 3.1.2 markdown-it-py 2.2.0 MarkupSafe 2.1.3 mdit-py-plugins 0.3.5 mdurl 0.1.2 myst-parser 0.18.1 packaging 23.2 pbr 5.11.1 pip 23.3 Pygments 2.16.1 PyYAML 6.0.1 requests 2.31.0 setuptools 68.2.2 snowballstemmer 2.2.0 Sphinx 4.5.0 sphinx-csharp 0.1.13 sphinx-new-tab-link 0.2.0 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.1 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-pdfembed 0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 sphinxcontrib-video 0.0.1.dev3 typing_extensions 4.8.0 urllib3 2.0.7 ```

Quickstart

% sphinx-quickstart --sep \
    -p issue10 \
    -a nikkie \
    -l en \
    -r ''
.
├── build/
├── source/
│   ├── _static/
│   ├── _templates/
│   ├── conf.py
│   └── index.rst
├── Makefile
└── make.bat

Use sphinx-new-tab-link

source/conf.py

extensions = [
    "myst_parser",
    "breathe",
    "sphinx_csharp",
    "sphinxcontrib.pdfembed",
    "sphinxcontrib.video",
    "sphinx.ext.extlinks",
    "sphinx_new_tab_link",  # Added
]

source/index.rst

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   issue.md

source/issue.md -> https://gist.githubusercontent.com/ftnext/a6d9ef18b76d736144af29f3ff35320c/raw/2dfe495b2894101caeedc7c973af85fcecf205f8/issue.md

Run make html, it passes (strangely)

build/html/issue.html -> https://gist.github.com/ftnext/41410306c92b1ec2def0c3b3a2d74df7