Code Monkey home page Code Monkey logo

Comments (11)

pawamoy avatar pawamoy commented on August 25, 2024 1

Should be fixed in 0.25.2 (both cases, in your main and griffe_debugging branches), let me know if you still encounter a similar issue and I'll reopen 🙂

from griffe.

digitaldogsbody avatar digitaldogsbody commented on August 25, 2024 1

Happy to confirm the fix working here. Thanks so much for your speedy work on this, it's really appreciated.

from griffe.

pawamoy avatar pawamoy commented on August 25, 2024

Errr, fixing something and breaking something else 😅
Thanks for the report, I'll investigate and fix ASAP.

from griffe.

digitaldogsbody avatar digitaldogsbody commented on August 25, 2024

Thankyou! Please let me know if there's anything I can do to assist with the process (testing etc).

I started looking into it a bit more, and in terms of the dependency path, I realised there are actually two import * statements in the chain:

  1. The main library imports everything from the helpers submodule: https://github.com/iiif-prezi/iiif-prezi3/blob/main/iiif_prezi3/__init__.py#L1
  2. The helpers module usually imports classes explicitly from its files: https://github.com/iiif-prezi/iiif-prezi3/blob/main/iiif_prezi3/helpers/__init__.py, but in this case (L7), it is using from .auto_fields import * (auto_fields.py is where the import uuid statement is located.

This could potentially be the cause of the issue? If it were a single import * causing the issue, I'd expect to see an earlier failure on one of the other helper files.

I will try updating that init in helpers to explicitly import the classes from auto_fields and report back whether or not that makes a difference.

from griffe.

digitaldogsbody avatar digitaldogsbody commented on August 25, 2024

It did indeed remove that error - but another one appeared in its place for an import of typing.Union. However there was also a secondary error that might be useful for debugging:

ERROR    -  Error building page 'code.md': Cyclic aliases detected:
              typing.Union
Traceback (most recent call last):
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs_autorefs/plugin.py", line 78, in _get_item_url
    return self._url_map[identifier]
KeyError: 'iiif_prezi3.skeleton.Union'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mike/projects/iiif-prezi3/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 329, in build
    _build_page(file.page, config, doc_files, nav, env, dirty)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/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/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs_autorefs/plugin.py", line 205, in on_post_page
    fixed_output, unmapped = fix_refs(output, url_mapper)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs_autorefs/references.py", line 191, in fix_refs
    html = AUTO_REF_RE.sub(fix_ref(url_mapper, unmapped), html)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs_autorefs/references.py", line 157, in inner
    url = url_mapper(unescape(identifier))
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs_autorefs/plugin.py", line 107, in get_item_url
    url = self._get_item_url(identifier, fallback)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocs_autorefs/plugin.py", line 83, in _get_item_url
    new_identifiers = fallback(identifier)
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocstrings/handlers/base.py", line 508, in get_anchors
    anchors = handler.get_anchors(handler.collect(identifier, fallback_config))
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/mkdocstrings_handlers/python/handler.py", line 228, in collect
    if doc_object.docstring is not None:
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/griffe/dataclasses.py", line 914, in docstring
    return self.target.docstring
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/griffe/dataclasses.py", line 1082, in target
    self.resolve_target()
  File "/home/mike/projects/iiif-prezi3/.venv/lib/python3.8/site-packages/griffe/dataclasses.py", line 1106, in resolve_target
    raise CyclicAliasError([self.target_path])
griffe.exceptions.CyclicAliasError: Cyclic aliases detected:
  typing.Union

iiif_prezi3.skeleton does import Union from the standard typing library (as well as a bunch of others), and it is still behind an from .skeleton import * in the root of the library, so I guess if you call from iiif_prezi3 import * then you are still getting a "double import * chain" situation.

from griffe.

digitaldogsbody avatar digitaldogsbody commented on August 25, 2024

I've pushed the version with the modified import for auto_fields to a branch here: https://github.com/iiif-prezi/iiif-prezi3/tree/griffe_debugging

from griffe.

pawamoy avatar pawamoy commented on August 25, 2024

Thank you for the investigation! That's really helpful.

90% of Griffe bugs come from wildcard imports indeed. They're a PITA to handle :/ I always recommend avoiding them, but I understand how convenient they might be.
I should probably try again to find some technical spec on how they are handled by Python itself, like an algorithm or something.

The way we handle indirections would probably benefit from a proper design as well. I've implemented it on top on the existing, simple data structures.

Anyway, enough ramblings. Time to write proper tests for wildcard imports.

from griffe.

digitaldogsbody avatar digitaldogsbody commented on August 25, 2024

Unfortunately due to the nature of our library, it's difficult to avoid, because we need to expose classes from the submodules as if they were part of the base module, and we have a model file that is generated by datamodel-code-generator, so it can change frequently and we always need to expose everything inside it.

We have managed to limit the use of from X import * to two statements in the init of the main library, but I will see about implementing some tooling to replace these with an explicit list that is autogenerated.

Keep me posted if there's anything else I can do :)

from griffe.

pawamoy avatar pawamoy commented on August 25, 2024

Hi @digitaldogsbody, it seems I cannot replicate the issue anymore in your repository 🤔
But I don't see any major change in the codebase in the last commit, so I wonder if you can still replicate? If yes, how?

from griffe.

digitaldogsbody avatar digitaldogsbody commented on August 25, 2024

I can replicate both the original issue (with uuid) against the code in main and the second one (with typing.Union) against the code in griffe_debugging by running mkdocs build in the root of the repo.

griffe is 0.25.1 and pip freeze | grep mkdocs reports this:

mkdocs==1.4.2
mkdocs-autorefs==0.4.1
mkdocs-material==8.5.11
mkdocs-material-extensions==1.1.1
mkdocstrings==0.19.0
mkdocstrings-python==0.8.2

Running pip install griffe==0.25.0 is enough to get mkdocs to start building again without any other changes.

from griffe.

pawamoy avatar pawamoy commented on August 25, 2024

Ah, my bad, I forgot I had patched griffe in the venv itself yesterday. Thank you for helping me remember that :) Hopefully I won't bother you again until it's resolved :)

from griffe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.