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

versionlabels dict is empty #981

Closed
2bndy5 opened this issue Jan 10, 2021 · 2 comments · Fixed by #982
Closed

versionlabels dict is empty #981

2bndy5 opened this issue Jan 10, 2021 · 2 comments · Fixed by #982
Labels

Comments

@2bndy5
Copy link
Contributor

2bndy5 commented Jan 10, 2021

I'm trying to build docs (with rst2pdf) using sphinx, and I'm getting an error related to the versionadded and versionchanged directives.

Description of problem

rST code in question

   .. versionadded:: 0.0.5
   .. versionchanged:: 0.0.5
      removed ``only_new`` parameter in favor of using `available()`

Entire output

[ERROR] pdfbuilder.py:159 Failed to build doc
Traceback (most recent call last):
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\rst2pdf\pdfbuilder.py", line 156, in write
    docwriter.write(doctree, destination)
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\docutils\writers\__init__.py", line 78, in write
    self.translate()
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\rst2pdf\pdfbuilder.py", line 587, in translate
    self.document.walkabout(visitor)
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\docutils\nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\docutils\nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\docutils\nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  [Previous line repeated 8 more times]
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\docutils\nodes.py", line 206, in walkabout
    visitor.dispatch_visit(self)
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\docutils\nodes.py", line 1995, in dispatch_visit
    return method(node)
  File "c:\users\%USER_NAME%\appdata\local\programs\python\python38-32\lib\site-packages\rst2pdf\pdfbuilder.py", line 738, in visit_versionmodified
    text = versionlabels[node['type']] % node['version']
KeyError: 'versionadded'
FAILED

Attempted debugging

When I added some debugging print statements to visit_versionmodified() I found that the versionlabels dict is empty. 😕 I can confirm that the directive and their args are gathered correctly.

    def visit_versionmodified(self, node):
        print(node['type'], node['version'])  # verify directive and arg is correct
        print(versionlabels)  # verify that no keys named `versionadded` or `versionchanged` exist
        text = versionlabels[node['type']] % node['version']
        if len(node):
            text += ': '
        else:
            text += '.'
        replacement = nodes.paragraph()
        replacement += nodes.Text(text)
        replacement.extend(node.children)
        node.parent.replace(node, replacement)

the print statements output:

versionadded 0.0.5
{}

and for the versionchanged directive:

versionchanged 0.0.5
{}

EDIT

This problem might be instigated by a Sphinx change because I found this declaration in Sphinx's __init__.py:

# Moved to sphinx.directives.other (will be overriden later)
versionlabels = {}  # type: Dict[str, str]

after some more digging, I found the dict with expected values in Sphinx.domain.changeset.py

versionlabels = {
    'versionadded':   _('New in version %s'),
    'versionchanged': _('Changed in version %s'),
    'deprecated':     _('Deprecated since version %s'),
}

So, I assume this issue is likely affecting the deprecated directive also.

Versions

  • Python 3.8.2 (3.8.5 on WSL ubuntu)
  • rst2pdf 0.98
  • reportlab 3.5.59
  • Sphinx 3.0.3 (3.4.3 on WSL ubuntu)

this output is consistent using Windows 10 and WSL ubuntu (with version listed above)

@2bndy5
Copy link
Contributor Author

2bndy5 commented Jan 10, 2021

I think I solved this. Changing (this line)

from sphinx.locals import versionlabels

to

from sphinx.domains.changeset import versionlabels

doesn't produce the error anymore. Except the output in the pdf is now

New in version 0.0.5: New in version 0.0.5.

and for versionchanged

Changed in version 0.0.5: Changed in version 0.0.5: removed only_new parameter in favor of using available()

@2bndy5
Copy link
Contributor Author

2bndy5 commented Jan 10, 2021

ok, I fixed the duplicate text entry by removing the prepending

replacement += node.Text(text)

from visit_versionmodified(). The output produced is now

New in version 0.0.5.

and for versionchanged directive

Changed in version 0.0.5: removed only_new parameter in favor of using available().

which is what I expect from comparing this to the html output.

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 a pull request may close this issue.

2 participants