Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Sep 3, 2023
1 parent 01de71a commit 5aff9ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions sphinx_needs/api/need.py
Expand Up @@ -193,13 +193,6 @@ def run():
if needs_config.id_regex and not re.match(needs_config.id_regex, need_id):
raise NeedsInvalidException(f"Given ID '{need_id}' does not match configured regex '{needs_config.id_regex}'")

# Calculate target id, to be able to set a link back
if is_external:
target_node = None
else:
target_node = nodes.target("", "", ids=[need_id], refid=need_id, anonymous="")
external_url = None

# Handle status
# Check if status is in needs_statuses. If not raise an error.
if needs_config.statuses and status not in [stat["name"] for stat in needs_config.statuses]:
Expand Down Expand Up @@ -310,7 +303,7 @@ def run():
"doctype": doctype,
"lineno": lineno,
"target_id": need_id,
"external_url": external_url,
"external_url": external_url if is_external else None,
"content_node": None, # gets set after rst parsing
"content_id": None, # gets set after rst parsing
"type": need_type,
Expand Down Expand Up @@ -443,8 +436,10 @@ def run():
node_need.line = needs_info["lineno"]

if needs_info["hide"]:
# add node to doctree, so we can later compute the containing section(s)
# (for use with section filters)
node_need["hidden"] = True
return [target_node, node_need]
return [node_need]

node_need_content = _render_template(content, docname, lineno, state)

Expand Down Expand Up @@ -485,7 +480,13 @@ def run():
# Create a copy of the content
needs_info["content_node"] = node_need.deepcopy()

return_nodes = [target_node] + [node_need]
return_nodes = [node_need]
if not is_external:
# Calculate target id, to be able to set a link back
target_node = nodes.target("", "", ids=[need_id], refid=need_id, anonymous="")
# TODO add to document?
return_nodes = [target_node, node_need]

if pre_content:
node_need_pre_content = _render_template(pre_content, docname, lineno, state)
return_nodes = node_need_pre_content.children + return_nodes
Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/directives/need.py
Expand Up @@ -548,7 +548,7 @@ def remove_hidden_needs(app: Sphinx, doctree: nodes.document, fromdocname: str)
"""Remove hidden needs from the doctree, before it is rendered."""
if fromdocname not in SphinxNeedsData(app.env).get_or_create_docs().get("all", []):
return
for node_need in doctree.findall(Need):
for node_need in list(doctree.findall(Need)):
if node_need.get("hidden"):
node_need.parent.remove(node_need) # type: ignore

Expand Down

0 comments on commit 5aff9ca

Please sign in to comment.