sphinx-needs icon indicating copy to clipboard operation
sphinx-needs copied to clipboard

WARNING: unknown node type: <NeedIncoming: <inline...>> when using `add_need` API

Open adegroote opened this issue 2 years ago • 2 comments

When trying to upgrade my project to newer version of sphinx-needs, I get the error described in title. I finally succeed to create a small reproducer. The problem seems to arise when some needs generated from a directive are referenced from an other document. Note that it works in 0.7.7 (but is it by luck or by design ?).

Thanks in advance for your help.

conf.py

# -*- coding: utf-8 -*-

extensions = [
    'sphinx_needs',
    'sphinxcontrib.plantuml',
    'foo_directive.foo_directive',
]

project = u'foo'

html_use_index = False

plantuml_output_format = "svg_img"

foo_directive

from docutils.parsers.rst import Directive
from sphinx_needs.api import add_need

from sphinx.application import Sphinx


class FooDirective(Directive):
    required_arguments = 1

    def run(self):
        main_section = []
        env = self.state.document.settings.env
        docname = env.docname

        main_section += add_need(env.app, self.state, docname, self.lineno,
                                 need_type="req", title="my title", id="ID_001",
                                 content="foo\nbar\n")

        return main_section


def setup(app: Sphinx):

    app.add_directive('foo', FooDirective)

    return {
        'version': '0.1',
        'parallel_read_safe': True,
        'parallel_write_safe': True,
    }

index.rst

FOO
=====


.. spec:: bar
   :id: ID_002
   :links: ID_001

.. toctree::

    foo.rst

foo.rst

FOOO
====

.. foo:: buz

adegroote avatar Feb 03 '23 13:02 adegroote

Try calling add_doc after using the add_need function. Example snippet:

from sphinx_needs.utils import add_doc
nodes = add_need(...)
add_doc(self.env, self.env.docname)

@danwos I think that needs to be mentioned in the docs.

r-o-b-e-r-t-o avatar May 10 '23 06:05 r-o-b-e-r-t-o

@r-o-b-e-r-t-o , you are right this should be documented.

Or maybe we can add add_doc() to the add_need() function directly so that it gets done automatically.

danwos avatar May 11 '23 16:05 danwos