Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

"NoneType object is not callable" when trying to link between documents #93

Closed
multimeric opened this issue Jan 16, 2018 · 12 comments
Closed

Comments

@multimeric
Copy link

multimeric commented Jan 16, 2018

I've noticed that adding a hyperlink between documents, when AutoStructify is enabled, causes the following error:

File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/states.py", line 135, in run_role
  content=content)
TypeError: 'NoneType' object is not callable

For a full example, clone this repo (https://github.com/TMiguelT/Sphinx-Bug-AutoStructify) and run

sphinx-build . $(mktemp -d)

The full error log is here:

  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/cmdline.py", line 306, in main
    app.build(opts.force_all, filenames)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/application.py", line 339, in build
    self.builder.build_update()
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 329, in build_update
    'out of date' % len(to_build))
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 342, in build
    updated_docnames = set(self.env.update(self.config, self.srcdir, self.doctreedir))
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/environment/__init__.py", line 601, in update
    self._read_serial(docnames, self.app)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/environment/__init__.py", line 621, in _read_serial
    self.read_doc(docname, app)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/sphinx/environment/__init__.py", line 758, in read_doc
    pub.publish()
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/docutils/core.py", line 218, in publish
    self.apply_transforms()
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/docutils/core.py", line 199, in apply_transforms
    self.document.transformer.apply_transforms()
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/docutils/transforms/__init__.py", line 171, in apply_transforms
    transform.apply(**kwargs)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 325, in apply
    self.traverse(self.document)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 297, in traverse
    self.traverse(child)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 297, in traverse
    self.traverse(child)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 297, in traverse
    self.traverse(child)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 287, in traverse
    newnode = self.find_replace(c)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 267, in find_replace
    newnode = self.auto_doc_ref(node)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/transform.py", line 175, in auto_doc_ref
    return self.state_machine.run_role('doc', content=content)
  File "/home/michael/Programming/GenovicAnalysis/venv/local/lib/python2.7/site-packages/recommonmark/states.py", line 135, in run_role
    content=content)
TypeError: 'NoneType' object is not callable
@multimeric
Copy link
Author

Notably, this works again when you add

    app.add_config_value('recommonmark_config', {
        'enable_auto_doc_ref': False,
    }, True)

So it must be related to the auto_doc_ref feature.

@mapio
Copy link

mapio commented Mar 9, 2018

Same here, unfortunately setting enable_auto_doc_ref of course disables the document linking (resulting in broken links).

What I've noticed instead is that using [title](doc.md#) instead of simply [title](doc.md) works as intended, that is no error is reported during make html and the generated html contains a link to doc.html# that links to the correct document.

@pfultz2
Copy link
Contributor

pfultz2 commented Mar 11, 2018

On the README, it says that enable_auto_doc_ref is deprecated. This is because now links which are not explicit URLs, are treated as cross references with the :any: role.

@mazerte
Copy link

mazerte commented Jun 29, 2018

Hi, I have the exactly same issue when I use nested list of links

* [Page 1](page1/index.md)
    * [SubPage 1](page1/subpage1.md)
    * [SubPage 2](page1/subpage2.md)
* [Page 2](page2/index.md)
    * [SubPage 1](page2/subpage1.md)

If I switch to enable_auto_doc_ref no more error but no more link.

It also works when the list is flat:

* [Page 1](page1/index.md)
* [SubPage 1](page1/subpage1.md)
* [SubPage 2](page1/subpage2.md)
* [Page 2](page2/index.md)
* [SubPage 1](page2/subpage1.md)

So I'm block can you help me ?
Thanks

@mvancanneyt
Copy link

I had the same issue.

I managed to fix it changing the flile
python3.5/dist-packages/recommonmark/transform.py
line 175, I changed
return self.state_machine.run_role('doc', content=content)
to
return self.state_machine.run_role('any', content=content)

And then all works fine.

@cas--
Copy link

cas-- commented Oct 26, 2018

The best workaround would seem to be installing latest code from the git repo:

pip install git+https://github.com/rtfd/recommonmark.git

To specify branch or commit see: https://stackoverflow.com/a/13754517/175584

Edit: I ran into new issues with master branch so ended up using patch below.


Alternatively based on @mvancanneyt change, a hacky monkey patch can be applied to recommonmark 0.4 in the sphinx config by adding this near the top of conf.py :

from recommonmark.states import DummyStateMachine
# Monkey patch to fix recommonmark 0.4 doc reference issues.
orig_run_role = DummyStateMachine.run_role
def run_role(self, name, options=None, content=None):
    if name == 'doc':
        name = 'any'
    return orig_run_role(self, name, options, content)
DummyStateMachine.run_role = run_role

@pfultz2 I was confused by this, however if you look at the PyPi release date it is 0.4 (Jan 2016) whereas the deprecation change occurred in Mar 2017. So for recommonmark 0.4 enable_auto_doc_ref is the only option. The project really needs to use tags to differentiate versions on rtfd.

cas-- added a commit to deluge-torrent/deluge that referenced this issue Nov 1, 2018
- Change the layout and contents of docs to be better organised and
  follow ideas from: https://www.divio.com/blog/documentation/
- Use markdown for non-technical documents to speed up writing.
- Added new sections and imported documents from Trac wiki.

Build fixes:

- Added a patch to fix recommonmark 0.4 and doc referencing:
    readthedocs/recommonmark#93
- Set docs build in tox to Py2.7 since there are problems with autodoc
  mocking multiple inheritance on Python 3 resulting in metaclass errors.
- Supressed warning about `modules.rst` not in the toctree by creating
  a static `modules.rst` with `:orphan:` file directive and add to git.
  Also skip creating this toc file with sphinx-apidoc in setup and tox.
- Simplified finding exported RPC and JSON API methods by adding an
  autodoc custom class directive. Removed unneeded __rpcapi.py.
cas-- added a commit to deluge-torrent/deluge that referenced this issue Nov 1, 2018
- Change the layout and contents of docs to be better organised and
  follow ideas from: https://www.divio.com/blog/documentation/
- Use markdown for non-technical documents to speed up writing.
- Added new sections and imported documents from Trac wiki.

Build fixes:

- Added a patch to fix recommonmark 0.4 and doc referencing:
    readthedocs/recommonmark#93
- Set docs build in tox to Py2.7 since there are problems with autodoc
  mocking multiple inheritance on Python 3 resulting in metaclass errors.
- Supressed warning about `modules.rst` not in the toctree by creating
  a static `modules.rst` with `:orphan:` file directive and add to git.
  Also skip creating this toc file with sphinx-apidoc in setup and tox.
- Simplified finding exported RPC and JSON API methods by adding an
  autodoc custom class directive. Removed unneeded __rpcapi.py.
@michaeldboyd
Copy link

Are there plans to incorporate this fix into the next release?

I'm currently blocked by this issue as well. When I hard code the change like @mvancanneyt it works, but the hacky monkey patch that @cas-- offered hasn't worked for me yet - I'm adding the PatchDummyStateMachine to the top of my conf.py, but it's not catching the override when I build.

Does anyone have any feedback on why it isn't working? My conf.py file is here: https://github.com/michaeldboyd/indy-sdk/blob/sphinx-docs-test/docs/conf.py

Thanks

@cas--
Copy link

cas-- commented Nov 26, 2018

My patch has to be applied after other recommonmark imports, otherwise it'll be reverted.

@michaeldboyd
Copy link

@cas-- Hmm, I've changed my conf.py so that your patch is applied after all the other imports. My sphinx build is still giving me this error below:

reading sources... [ 29%] design/005-dkms/README
Exception occurred:
  File "/home/mdb/.local/lib/python3.6/site-packages/recommonmark/states.py", line 134, in run_role
    content=content)
TypeError: 'NoneType' object is not callable

Thank you for your help, do you have any other ideas why this might not be working?

@cas--
Copy link

cas-- commented Nov 26, 2018

Ah oops, it seems my refactor of the patch didn't work (along with not getting that error anymore didn't catch that) so try my original patch:

from recommonmark.states import DummyStateMachine
# Monkey patch to fix recommonmark 0.4 doc reference issues.
orig_run_role = DummyStateMachine.run_role
def run_role(self, name, options=None, content=None):
    if name == 'doc':
        name = 'any'
    return orig_run_role(self, name, options, content)
DummyStateMachine.run_role = run_role

@michaeldboyd
Copy link

Great! That works. Thank you for the help.

@michaeldboyd
Copy link

Are there plans to incorporate a fix for this in a future release?

RichBarton-Arm added a commit to llvm/llvm-project that referenced this issue Sep 16, 2020
Apply a local fix to an issue with recommonmark's AutoStructify extension
when used with certain versions of sphinx.

See readthedocs/recommonmark#93

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D87714
zmodem pushed a commit to llvm/llvm-project that referenced this issue Sep 16, 2020
Apply a local fix to an issue with recommonmark's AutoStructify extension
when used with certain versions of sphinx.

See readthedocs/recommonmark#93

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D87714

(cherry picked from commit af56be3)
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Mar 23, 2021
Apply a local fix to an issue with recommonmark's AutoStructify extension
when used with certain versions of sphinx.

See readthedocs/recommonmark#93

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D87714
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants