jbms / sphinx-immaterial

Adaptation of the popular mkdocs-material material design theme to the sphinx documentation system
https://jbms.github.io/sphinx-immaterial/
Other
177 stars 28 forks source link

pydantic 2.5.0 release just broke this package #302

Closed chrisjsewell closed 7 months ago

chrisjsewell commented 7 months ago

Doh (https://github.com/pydantic/pydantic/releases/tag/v2.5.0)

Running Sphinx v7.2.6

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx/cmd/build.py", line 293, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx/application.py", line 233, in __init__
    self.setup_extension(extension)
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx/application.py", line 406, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx/registry.py", line 460, in load_extension
    metadata = setup(app)
               ^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx_immaterial/__init__.py", line 332, in setup
    app.setup_extension("sphinx_immaterial.custom_admonitions")
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx/application.py", line 406, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx/registry.py", line 447, in load_extension
    mod = import_module(extname)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/.asdf/installs/python/3.11.6/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/sphinx_immaterial/custom_admonitions.py", line 46, in <module>
    str, pydantic.functional_validators.AfterValidator(nodes.make_id)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/pydantic/__init__.py", line 363, in __getattr__
    return _getattr_migration(attr_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/pydantic/_migration.py", line 306, in wrapper
    raise AttributeError(f'module {module!r} has no attribute {name!r}')
AttributeError: module 'pydantic' has no attribute 'functional_validators'

Exception occurred:
  File "/home/docs/checkouts/readthedocs.org/user_builds/sphinx-needs/envs/1070/lib/python3.11/site-packages/pydantic/_migration.py", line 306, in wrapper
    raise AttributeError(f'module {module!r} has no attribute {name!r}')
AttributeError: module 'pydantic' has no attribute 'functional_validators'
The full traceback has been saved in /tmp/sphinx-err-aelj0aq6.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
2bndy5 commented 7 months ago

It is getting annoying to have to keep fixing our use of pydantic v2 due to all their "growing pains". This marks the third time they broke compatibility with v2.x 😡

2bndy5 commented 7 months ago

I believe the fix is to just pin to pydantic v2.5 and change the annotated type:

 CSSClassType = Annotated[
    str, pydantic.AfterValidator(nodes.make_id)
 ]
2bndy5 commented 7 months ago

This may not be considered a breaking change on their part. The namespace pydantic.functional_validators was copied from their migration guide, but their docs now seem to import AfterValidator from the root namespace pydantic. This is another reason why emphasizing docs that only lead by example is a bad idea (especially without diligent review).

As far as I can tell, the AfterValidator object was made available in the root namespace around pydantic v2.2. We are already pinned to v2.4.

2bndy5 commented 7 months ago

fixed in v0.11.9

chrisjsewell commented 7 months ago

Cheers dude!

N-Wouda commented 7 months ago

Fantastic! 🎉