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

Issues with custom layout

Open elnino1 opened this issue 3 years ago • 2 comments

Hi,

I'm encountering several issues related to custom layout. Hope these are only misunderstandings from me.

First some context:

I added some extra options:

needs_extra_options = {
    "safety": directives.unchanged,
    "rationale": directives.unchanged
}

And a global option, computed from a needs_function. needs_functions = [need_sha1]

needs_global_options = {
    "sha1": "[[need_sha1()]]"
}

My requirement is to hide this sha1 field from output as I want to only use it internally with needs.json processing. So I created a custom layout.

So I made several attempts:

needs_layouts = {
    "req_without_sha1": {
        "grid": "simple",
        "layout": {
            "head": ["**<<meta_id()>>**: <<meta('title')>>"],
            "meta": [
                     "**rationale**: <<meta('rationale')>>",
                     "**safety**: <<meta('safety')>>",
                     ]
        }
    }
}

Works but I don't want to see empty fields, so I changed to

needs_layouts = {
    "req_without_sha1": {
        "grid": "simple",
        "layout": {
            "head": ["**<<meta_id()>>**: <<meta('title')>>"],
            "meta": [
                     "<<meta('rationale', prefix='rationale: '))>>",
                     "<<meta('safety', prefix='safety: ')>>",
                     ]
        }
    }
}

Works better but I also want prefix in bold. That's my first issue. If I put <<meta('rationale', prefix='**rationale:** '))>> I got this in rendered document image

Thus I tried to use meta_all and exclusion as in documentation

needs_layouts = {
    "req_without_sha1": {
        "grid": "simple",
        "layout": {
            "head": ["**<<meta_id()>>**: <<meta('title')>>"],
            "meta": ["<<meta_all(prefix='\*\*', postix='\*\*', exclude=['sha1'])>>"]
        }
    }
}

And I get the following error

Extension error (sphinxcontrib.needs.directives.need):
Handler <function print_need_nodes at 0x10e5458b0> for event 'doctree-resolved' threw an exception (exception: source code string cannot contain null bytes)

I also tried without escaping the rst format but here I have

Extension error (sphinxcontrib.needs.directives.need):
Handler <function print_need_nodes at 0x10a9b78b0> for event 'doctree-resolved' threw an exception (exception: meta_all() got an unexpected keyword argument 'postix')

If you prefer I can split in several ticket, one for the meta, the other for the meta_all.

Thanks in advance

elnino1 avatar Oct 27 '21 08:10 elnino1

Thanks for the detailed bug report. :+1: Having both bugs in one ticket is okay.

Which Sphinx and sphinx-needs version are you using?

danwos avatar Oct 27 '21 08:10 danwos

Hi, I'm using these versions

Sphinx 4.2.0 sphinxcontrib-needs 0.7.1

elnino1 avatar Oct 27 '21 09:10 elnino1