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

feature: Disable the expand_wildcards #359

Open
FormindMPO opened this issue Feb 13, 2025 · 6 comments
Open

feature: Disable the expand_wildcards #359

FormindMPO opened this issue Feb 13, 2025 · 6 comments
Assignees
Labels
unconfirmed This bug was not reproduced yet

Comments

@FormindMPO
Copy link

Is your feature request related to a problem? Please describe.

  • I want to build a doc from a django project where i have a lot of from module import *
    -> I know that these are not in the best practises, but it helps in importing local folder with a big init.py without rewrighting whole stuff

I don't want griffe to expand_wildcards and resolve everything, i only want him to read the files and docstrings that it have, nothing more

Describe the solution you'd like

When commenting self.expand_wildcards(module, external=False) in the def _post_load(self, module: Module, obj_path: str) -> Object | Alias: method from class GriffeLoader:, i can load my project and everything works fine

Hence, would it be possible to add a parameter that states

if expand_wildcards_parameter:
        self.expand_wildcards(module, external=False)

Describe alternatives you've considered

I could repair my * import modules but this is not what i want :(

Additional context

This is my actual conf

plugins:
  - mkdocstrings: # https://mkdocstrings.github.io/usage/#html-result-for-doc2
      default_handler: python
      handlers:
        python:
          options:
            show_source: false
            allow_inspection: false 
            heading_level: 3
            show_root_full_path: true
            show_symbol_type_heading: true
            show_symbol_type_toc: true
            filters:
              - "!^(preventFromEmailBlacklisting.*)$"
            load_external_modules: false  # This disables following imports
            exclude_targets : true
@FormindMPO FormindMPO added the feature New feature or request label Feb 13, 2025
@pawamoy
Copy link
Member

pawamoy commented Feb 13, 2025

Hi @FormindMPO, thanks for the feature request 🙂

Instead of disabling wildcard expansion (which I don't think we should allow), could we maybe fix the issue you're having? Could you describe it?

@FormindMPO
Copy link
Author

FormindMPO commented Feb 13, 2025

Hey, yes sure !

So when i'm running mkdocs serve with a MD file like :::Project.recon.models.utils, i want it to read ONLY the docstrings inside, and not trying to resolve every imported module.

#!/usr/bin/python3
# utils.py
from PIL import Image
from cryptography import x509
from datetime import *
from django.conf import settings
from django.contrib import admin

def my_function(test: int) -> None:
    """ awesome documentation"""
   print("Hello World")

Here is the griffe error:

[...]
  File "/home/mpo/VOC_ForCERT/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1662, in target
    self.resolve_target()
  File "/home/mpo/VOC_ForCERT/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1729, in resolve_target
    self._resolve_target()
  File "/home/mpo/VOC_ForCERT/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1737, in _resolve_target
    raise AliasResolutionError(self) from error
_griffe.exceptions.AliasResolutionError: Could not resolve alias Project.recon.models.utils.datetime/* pointing at datetime (in Project/recon/models/utils.py:11)

@pawamoy
Copy link
Member

pawamoy commented Feb 13, 2025

Thank you! Might have been an oversight, this should definitely not error out 🙂 Let me investigate.

@pawamoy
Copy link
Member

pawamoy commented Feb 13, 2025

Can you paste the whole traceback please? Or share your repo if it's public.

@pawamoy pawamoy added unconfirmed This bug was not reproduced yet and removed feature New feature or request labels Feb 13, 2025
@FormindMPO
Copy link
Author

ERROR   -  Error reading page 'index.md': Could not resolve alias Project.recon.models.utils.datetime/* pointing at datetime (in Project/recon/models/utils.py:11)
Traceback (most recent call last):
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1735, in _resolve_target
    resolved = self.modules_collection.get_member(self.target_path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/mixins.py", line 83, in get_member
    return self.members[parts[0]]  # type: ignore[attr-defined]
           ~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'datetime'

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

Traceback (most recent call last):
  File "/home/MPO/Project/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 272, in serve_command
    serve.serve(**kwargs)
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 85, in serve
    builder(config)
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, serve_url=None if is_clean else serve_url, dirty=is_dirty)
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.render(config, files)
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocs/structure/pages.py", line 285, in render
    self.content = md.convert(self.markdown)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/markdown/core.py", line 357, in convert
    root = self.parser.parseDocument(self.lines).getroot()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 117, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 136, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/markdown/blockparser.py", line 158, in parseBlocks
    if processor.run(parent, blocks) is not False:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocstrings/extension.py", line 125, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocstrings/extension.py", line 188, in _process_block
    data: CollectorItem = handler.collect(identifier, options)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/mkdocstrings_handlers/python/handler.py", line 241, in collect
    unresolved, iterations = loader.resolve_aliases(
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/loader.py", line 234, in resolve_aliases
    self.expand_wildcards(wildcards_module, external=external)
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/loader.py", line 366, in expand_wildcards
    self.expand_wildcards(member, external=external, seen=seen)  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/loader.py", line 366, in expand_wildcards
    self.expand_wildcards(member, external=external, seen=seen)  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/loader.py", line 366, in expand_wildcards
    self.expand_wildcards(member, external=external, seen=seen)  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/loader.py", line 361, in expand_wildcards
    expanded.extend(self._expand_wildcard(member))  # type: ignore[arg-type]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/loader.py", line 707, in _expand_wildcard
    for imported_member in module.members.values()
                           ^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1170, in members
    final_target = self.final_target
                   ^^^^^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1697, in final_target
    target = target.target  # type: ignore[assignment]
             ^^^^^^^^^^^^^
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1662, in target
    self.resolve_target()
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1729, in resolve_target
    self._resolve_target()
  File "/home/MPO/Project/.venv/lib/python3.11/site-packages/_griffe/models.py", line 1737, in _resolve_target
    raise AliasResolutionError(self) from error
_griffe.exceptions.AliasResolutionError: Could not resolve alias Project.recon.models.utils.datetime/* pointing at datetime (in Project/recon/models/utils.py:11)

@pawamoy
Copy link
Member

pawamoy commented Feb 13, 2025

Sorry, I cannot reproduce this issue 😕 Can you provide a minimal reproduction example? Ideally a ZIP archive or GitHub repository with instructions on how to use it to reproduce this traceback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed This bug was not reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants