pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
597 stars 312 forks source link

failure to parse http links containing dashes #1887

Closed NicNomadic closed 3 months ago

NicNomadic commented 3 months ago

Building the following simple page fails because it contains a web link including a dash, when using pydata 0.15.3.

Extract from poetry.lock:

[[package]]
name = "pydata-sphinx-theme"
version = "0.15.3"
description = "Bootstrap-based Sphinx theme from the PyData community"
category = "main"
optional = false
python-versions = ">=3.9"

Reproducing the error:

$ cat >index.rst <<EOF
Welcome to the Documentation!
=============================

Report issues to https://gitlab.com/tezos/tezos/-/issues
EOF

$ cat >conf.py <<EOF
source_suffix = '.rst'
master_doc = 'index'
html_theme = "pydata_sphinx_theme"
EOF

$ poetry run sphinx-build -b html "." "_build"
Running Sphinx v7.3.7
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... copying static files... done
copying extra files... done
done
writing output... [100%] index
Exception occurred:
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/pydata_sphinx_theme/short_link.py", line 103, in parse_url
    url_type, element_number, *_ = parts
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected at least 2, got 1)
The full traceback has been saved in /var/folders/9y/r3w7mc6j3j79sp8qyp92rd_r0000gn/T/sphinx-err-__d87tta.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

$ cat /var/folders/9y/r3w7mc6j3j79sp8qyp92rd_r0000gn/T/sphinx-err-__d87tta.log
# Platform:         darwin; (macOS-10.16-x86_64-i386-64bit)
# Sphinx version:   7.3.7
# Python version:   3.11.6 (CPython)
# Docutils version: 0.21.2
# Jinja2 version:   3.1.4
# Pygments version: 2.18.0

# Last messages:
#   copying assets...
#   copying static files...
#   done
#   copying extra files...
#   done
#   done
#   
#   writing output... [100%]
#   index
#   

# Loaded extensions:
#   sphinx.ext.mathjax (7.3.7)
#   alabaster (0.7.16)
#   sphinxcontrib.applehelp (1.0.8)
#   sphinxcontrib.devhelp (1.0.6)
#   sphinxcontrib.htmlhelp (2.0.5)
#   sphinxcontrib.serializinghtml (1.1.10)
#   sphinxcontrib.qthelp (1.0.7)
#   pydata_sphinx_theme (unknown version)

# Traceback:
Traceback (most recent call last):
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/cmd/build.py", line 337, in build_main
    app.build(args.force_all, args.filenames)
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/application.py", line 351, in build
    self.builder.build_update()
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 293, in build_update
    self.build(to_build,
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 362, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 570, in write
    self._write_serial(sorted(docnames))
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 577, in _write_serial
    doctree = self.env.get_and_resolve_doctree(docname, self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/environment/__init__.py", line 638, in get_and_resolve_doctree
    self.apply_post_transforms(doctree, docname)
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/environment/__init__.py", line 691, in apply_post_transforms
    transformer.apply_transforms()
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/transforms/__init__.py", line 84, in apply_transforms
    super().apply_transforms()  # type: ignore[misc]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/docutils/transforms/__init__.py", line 182, in apply_transforms
    transform.apply(**kwargs)
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/sphinx/transforms/post_transforms/__init__.py", line 44, in apply
    self.run(**kwargs)
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/pydata_sphinx_theme/short_link.py", line 54, in run
    node.children[0] = nodes.Text(self.parse_url(uri))
                                  ^^^^^^^^^^^^^^^^^^^
  File "/Users/nic/Library/Caches/pypoetry/virtualenvs/tezos-LY8-gUlI-py3.11/lib/python3.11/site-packages/pydata_sphinx_theme/short_link.py", line 103, in parse_url
    url_type, element_number, *_ = parts
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected at least 2, got 1)
Carreau commented 3 months ago

This is strange as there is already a test file (tests/sites/base/page1.rst), but I can confirm I can reproduce and have a fix, but I want to see why it is not caught by the other test.

NicNomadic commented 3 months ago

I confirm that with v0.15.4 I get no more errors. Thanks a lot for the quick fix!