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

TOML tables in code-blocks break dynamic functions #1199

Closed
ubmarco opened this issue Jun 20, 2024 · 0 comments · Fixed by #1263
Closed

TOML tables in code-blocks break dynamic functions #1199

ubmarco opened this issue Jun 20, 2024 · 0 comments · Fixed by #1263
Labels

Comments

@ubmarco
Copy link
Member

ubmarco commented Jun 20, 2024

This snippet

.. story:: foo
   :id: ST_FOO
   :status: open

   .. code-block:: toml

      [[project]]
      display_name = "sphinx-needs"

leads to

Traceback (most recent call last):
  File "/home/marco/ub/ubdocs/dist/export/python/virtualenvs/python-default/3.10.14/lib/python3.10/site-packages/sphinx_needs/functions/functions.py", line 396, in _analyze_func_string
    func_name = func_call.func.id
AttributeError: 'Name' object has no attribute 'func'
...
  File "/home/marco/ub/ubdocs/dist/export/python/virtualenvs/python-default/3.10.14/lib/python3.10/site-packages/sphinx_needs/functions/functions.py", line 75, in execute_func
    func_name, func_args, func_kwargs = _analyze_func_string(func_string, need)
  File "/home/marco/ub/ubdocs/dist/export/python/virtualenvs/python-default/3.10.14/lib/python3.10/site-packages/sphinx_needs/functions/functions.py", line 398, in _analyze_func_string
    raise SphinxError(
sphinx.errors.SphinxError: Given dynamic function string is not a valid python call. Got: project

Issue is that sphinx-needs sees [[project]] as a dynamic function call which does not exist.
This however is valid TOML https://toml.io/en/v1.0.0#array-of-tables.

2 solutions come to my mind:

  1. global config that deactivates dynamic functions for a certain set of needs
  2. escape mechanism for the [[ ]] syntax
  3. customize start and end tag for the dynamic function delimiters

I'd prefer option 3 as it's simple and safe. Escaping seems tricky as sphinx-needs has to deal with all sorts of other languages that might appear in nested directives.

@ubmarco ubmarco changed the title TOML tables in code-block breaks dynamic functions TOML tables in code-blocks break dynamic functions Jun 20, 2024
@ubmarco ubmarco added the bug label Jun 20, 2024
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.

1 participant