Skip to content

[BUG] Max depth reached error when hot reloading via sphinx (e.g. with esbonio) #27

@MaximilianSoerenPollak

Description

@MaximilianSoerenPollak

There currently seems to be a bug where sphinx errors due to this extension as it reaches the max depth recursion.
Error:

ERROR: sphinx-build failed
Traceback (most recent call last):
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/sphinx/events.py", line 404, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/main.py", line 19, in write
    write_needscfg_file(app, app.config)
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 307, in write_needscfg_file
    safe_value = get_safe_config(value, f"needs.{config_name}", outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 192, in get_safe_config
    safe_value = get_safe_config(item, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 183, in get_safe_config
    safe_value = get_safe_config(value, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 183, in get_safe_config
    safe_value = get_safe_config(value, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 192, in get_safe_config
    safe_value = get_safe_config(item, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 183, in get_safe_config
    safe_value = get_safe_config(value, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 183, in get_safe_config
    safe_value = get_safe_config(value, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...

This continues until:

  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 183, in get_safe_config
    safe_value = get_safe_config(value, item_path, outpath)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/builder.py", line 95, in get_safe_config
    if matches_path_pattern(path, pattern):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/needs_config_writer/utils.py", line 76, in matches_path_pattern
    return re.fullmatch(pattern_regex, config_path) is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/cache/bazel/05454f223d7eceee02200e9d517999d9/external/rules_python++python+python_3_12_x86_64-unknown-linux-gnu/lib/python3.12/re/__init__.py", line 172, in fullmatch
    return _compile(pattern, flags).fullmatch(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vscode/.vscode-server/extensions/swyddfa.esbonio-1.0.0/bundled/libs/esbonio/sphinx_agent/handlers/__init__.py", line 168, in build_sphinx_app
    self.app.build()
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/sphinx/application.py", line 426, in build
    self.builder.build_update()
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 375, in build_update
    self.build(
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 403, in build
    updated_docnames = set(self.read())
                           ^^^^^^^^^^^
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 508, in read
    self.events.emit('env-before-read-docs', self.env, docnames)
  File "/workspaces/docs-as-code/.venv_docs/lib/python3.12/site-packages/sphinx/events.py", line 415, in emit
    raise ExtensionError(
sphinx.errors.ExtensionError: Handler <function write at 0x74767523e200> for event 'env-before-read-docs' threw an exception (exception: maximum recursion depth exceeded)

Steps to reproduce:

  • Cloning repo: https://github.com/eclipse-score/docs-as-code
  • Opening in Devcontainer (so it installs Esbonio extension and server etc)
  • Make sure .venv_docs exists and is selected as python interpreter
  • In the output on the bottom select 'Esbonio' to see it's output
  • Open any RST file
    You now hope fully should see a non error sphinx build accin to this:
Running Sphinx v8.2.3
loading translations [en]... done
calculate directory_hash = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 within 9.822845458984375e-05 seconds.
Read in collections ...
Clean collections ...
Executing collections ...
myst v5.0.0: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions={'colon_fence'}, disable_syntax=[], all_links_external=False, links_external_new_tab=False, url_schemes=('http', 'https', 'mailto', 'ftp'), ref_domains=None, fence_as_directive=set(), number_code_blocks=[], title_to_header=False, heading_anchors=0, heading_slug_func=None, html_meta={}, footnote_sort=True, footnote_transition=True, words_per_minute=200, substitutions={}, linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', enable_checkboxes=False, suppress_warnings=[], highlight_code_blocks=True)
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 32 source files that are out of date
updating environment: [new config] 32 added, 0 changed, 0 removed
Path 'needs.flow_configs.score_config' matches pattern 'needs_flow_configs.score_config' (prefix='!include ', suffix=None)
Relativizing embedded string path at 'needs.flow_configs.score_config': !include /var/cache/bazel/05454f223d7eceee02200e9d517999d9/execroot/_main/bazel-out/k8-fastbuild/bin/ide_support.runfiles/_main/src/extensions/score_layout/assets/puml-theme-score.puml -> !include ../src/extensions/score_layout/assets/puml-theme-score.puml
Path 'needs.external_needs[0].json_path' matches pattern 'needs_external_needs[*].json_path' (prefix=None, suffix=None)
Relativizing path at 'needs.external_needs[0].json_path': /workspaces/docs-as-code/bazel-bin/ide_support.runfiles/score_process+/needs_json/_build/needs/needs.json -> ../bazel-bin/external/score_process+/needs_json/_build/needs/needs.json
Merged TOML configuration from '/var/cache/bazel/05454f223d7eceee02200e9d517999d9/execroot/_main/bazel-out/k8-fastbuild/bin/ide_support.runfiles/_main/src/extensions/score_sync_toml/shared.toml'
Needs configuration written to '/workspaces/docs-as-code/docs/ubproject.toml'
reading sources...
Copying static files for sphinx-data-viewer support
Copying static files for sphinx-needs datatables support
Copying static style files for sphinx-needs
WARNING: the sphinx_agent.handlers.webview extension does not declare if it is safe for parallel reading, assuming it isn't - please ask the extension author to check and make it explicit
WARNING: doing serial read
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
Schema validation completed with 0 warning(s) in 0.166 seconds. Validated 8240 needs/s.
preparing documents... done
Writing evaluated template result to /workspaces/docs-as-code/_build/_static/basic.css
Writing evaluated template result to /workspaces/docs-as-code/_build/_static/language_data.js
Writing evaluated template result to /workspaces/docs-as-code/_build/_static/documentation_options.js
copying static files... done
copying extra files... done
copying assets... done
writing output...

genindex generating indices... done
search writing additional pages... done
copying images...
dumping search index in English (code: en)... done
dumping object inventory... done
Needs successfully exported
Final clean of collections ...
build succeeded, 2 warnings.

The HTML pages are in _build.
  • Now change something in the rst file like removing some word or adding something
  • Save to force esbonio to reload
  • The error at the begining now should pop up.

This seems to be an issue with the Document update event in sphinx, somehow the extension can't handle something in there.

Happy to answer any questions or provide more info that is needed.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions