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

Infinite recursion in griffe (again) #122

Closed
roastduck opened this issue Dec 19, 2022 · 8 comments
Closed

Infinite recursion in griffe (again) #122

roastduck opened this issue Dec 19, 2022 · 8 comments
Labels
bug Something isn't working griffe: wildcard-imports Related to wildcard imports

Comments

@roastduck
Copy link

roastduck commented Dec 19, 2022

See #83. Still the same problem.

No infinite recursion with griffe==0.23.0 or griffe==0.24.0, but failed with griffe==0.25.0. Latest compatible versions of mkdocstrings[python] is resolved by pip accordingly.

Even when using griffe==0.23.0 or griffe==0.24.0, it only renders an empty API doc page. I remember the rendering was fine when I was testing against the PR branch then. There might be some differences between the PR branch and the 0.23.0 release, or the difference version of mkdocstrings causes the problem, or perhaps there was something wrong when I did the testing.

@pawamoy
Copy link
Member

pawamoy commented Dec 20, 2022

😱

Thanks for the report, will try and replicate now 🙂

@pawamoy
Copy link
Member

pawamoy commented Dec 20, 2022

Griffe 0.25.1 should fix it 🙂
Let me know if it doesn't and I'll reopen.

@pawamoy pawamoy closed this as completed Dec 20, 2022
@roastduck
Copy link
Author

Sorry for the late response. The infinite recursion erorr did disappear, but no API is rendered. The result is only an empty page. I have tried both Griffe 0.25.1 and 0.25.5, with other dependencies kept to the latest.

Please still use the repo mentioned in #83 to reproduce. The specific commit I tried is roastduck/FreeTensor@63cd89f .

Only the old "mkdocstrings==0.18.1" "pytkdocs[numpy-style]" works for me.

@pawamoy
Copy link
Member

pawamoy commented Mar 21, 2023

That's alright! Thanks for reporting :) Good to hear this is fixed. Now you're probably just missing the show_submodules: true option (globally in mkdocs.yml or locally in your Markdown page).

@roastduck
Copy link
Author

show_submoduels: true works, but it results in another error:

INFO     -  Building documentation...
INFO     -  mkdocstrings: DEPRECATION: mkdocstrings' watch feature is deprecated in favor of MkDocs' watch feature, see https://www.mkdocs.org/user-guide/configuration/#watch
INFO     -  Cleaning site directory
WARNING  -  griffe: freetensor/libop/element_wise.py:288: Parameter 'out' does not appear in the function signature
ERROR    -  Error building page 'api.md': Could not resolve freetensor.libop.softmax.core
Traceback (most recent call last):
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs_autorefs/plugin.py", line 78, in _get_item_url
    return self._url_map[identifier]
KeyError: 'freetensor.core.VarRef'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 945, in resolve_target
    resolved = self.modules_collection[self.target_path]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/mixins.py", line 28, in __getitem__
    return self.members[parts[0]][parts[1:]]  # type: ignore[attr-defined]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/mixins.py", line 28, in __getitem__
    return self.members[parts[0]][parts[1:]]  # type: ignore[attr-defined]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/mixins.py", line 28, in __getitem__
    return self.members[parts[0]][parts[1:]]  # type: ignore[attr-defined]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 821, in __getitem__
    return self.target[key]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/mixins.py", line 27, in __getitem__
    return self.members[parts[0]]  # type: ignore[attr-defined]
KeyError: 'core'

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

Traceback (most recent call last):
  File "/home/rd/.local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/rd/.local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/rd/.local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/rd/.local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rd/.local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rd/.local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 82, in serve
    builder(config)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 75, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 329, in build
    _build_page(file.page, config, doc_files, nav, env, dirty)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 234, in _build_page
    output = config.plugins.run_event('post_page', output, page=page, config=config)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs/plugins.py", line 517, in run_event
    result = method(item, **kwargs)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs_autorefs/plugin.py", line 205, in on_post_page
    fixed_output, unmapped = fix_refs(output, url_mapper)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs_autorefs/references.py", line 191, in fix_refs
    html = AUTO_REF_RE.sub(fix_ref(url_mapper, unmapped), html)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs_autorefs/references.py", line 157, in inner
    url = url_mapper(unescape(identifier))
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs_autorefs/plugin.py", line 107, in get_item_url
    url = self._get_item_url(identifier, fallback)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocs_autorefs/plugin.py", line 83, in _get_item_url
    new_identifiers = fallback(identifier)
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocstrings/handlers/base.py", line 508, in get_anchors
    anchors = handler.get_anchors(handler.collect(identifier, fallback_config))
  File "/home/rd/.local/lib/python3.9/site-packages/mkdocstrings_handlers/python/handler.py", line 200, in collect
    doc_object = self._modules_collection[identifier]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/mixins.py", line 28, in __getitem__
    return self.members[parts[0]][parts[1:]]  # type: ignore[attr-defined]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/mixins.py", line 28, in __getitem__
    return self.members[parts[0]][parts[1:]]  # type: ignore[attr-defined]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 821, in __getitem__
    return self.target[key]
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 921, in target
    self.resolve_target()
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 952, in resolve_target
    self._target.aliases[self.path] = self  # type: ignore[union-attr]  # we just set the target
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 812, in __getattr__
    attr = getattr(self.target, name)
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 921, in target
    self.resolve_target()
  File "/home/rd/.local/lib/python3.9/site-packages/griffe/dataclasses.py", line 947, in resolve_target
    raise AliasResolutionError(self.target_path) from error
griffe.exceptions.AliasResolutionError: Could not resolve freetensor.libop.softmax.core

freetensor.libop.softmax.core is indeed an alias. It is an from .. import core, which is actually freetensor.core. I have no idea why this alias cannot be resolved.

Tested with Griffe 0.25.5.

Feel free to open a new issue if you like.

@pawamoy
Copy link
Member

pawamoy commented Mar 21, 2023

One day it will work maybe 🤣

Thanks for the update, I'll investigate :)

@pawamoy pawamoy added griffe: wildcard-imports Related to wildcard imports bug Something isn't working labels Apr 1, 2023
@pawamoy
Copy link
Member

pawamoy commented Apr 1, 2023

It's again because of wildcard imports (which Griffe does not handle perfectly, for various reasons).

  • (descending) freetensor wildcard imports freetensor.libop
  • which wildcard imports freetensor.libop.softmax
  • which imports freetensor.core
  • so freetensor.libop.softmax.core is an alias to freetensor.core
  • and (ascending) freetensor.libop.core is an alias to freetensor.core.softmax.core
  • and freetensor.core is an alias to freetensor.libop.core
  • thus creating an (undetected) indirect cycle freetensor.core -> freetensor.core

I think I've been able to add a guardrail against this case. I'll push a fix soon after I verified this is working properly.

@pawamoy pawamoy reopened this Apr 1, 2023
pawamoy added a commit that referenced this issue Apr 1, 2023
@pawamoy
Copy link
Member

pawamoy commented Jun 19, 2023

Will close now, keep opening issues if you have any 🙏 ❤️

@pawamoy pawamoy closed this as completed Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working griffe: wildcard-imports Related to wildcard imports
Projects
None yet
Development

No branches or pull requests

2 participants