wpilibsuite / sphinxext-opengraph

Sphinx extension to generate unique OpenGraph metadata
https://sphinxext-opengraph.readthedocs.io
Other
68 stars 25 forks source link

0.9.1: not ready for `matplotlib` 3.8.4?🤔 #121

Open kloczek opened 3 months ago

kloczek commented 3 months ago

On building urllib3 documentation in build env with installed matplotlib 3.8.4 I found that sphinx fails in sphinxext-opengraph with:

+ /usr/bin/sphinx-build -n -T -b man docs build/sphinx/man
Running Sphinx v7.2.6

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/sphinx/registry.py", line 447, in load_extension
    mod = import_module(extname)
  File "/usr/lib64/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/sphinxext/opengraph/__init__.py", line 19, in <module>
    from .socialcards import create_social_card, DEFAULT_SOCIAL_CONFIG
  File "/usr/lib/python3.10/site-packages/sphinxext/opengraph/socialcards.py", line 5, in <module>
    from matplotlib import pyplot as plt
ImportError: cannot import name 'pyplot' from 'matplotlib' (unknown location)

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

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/sphinx/cmd/build.py", line 293, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/usr/lib/python3.10/site-packages/sphinx/application.py", line 233, in __init__
    self.setup_extension(extension)
  File "/usr/lib/python3.10/site-packages/sphinx/application.py", line 406, in setup_extension
    self.registry.load_extension(self, extname)
  File "/usr/lib/python3.10/site-packages/sphinx/registry.py", line 450, in load_extension
    raise ExtensionError(__('Could not import extension %s') % extname,
sphinx.errors.ExtensionError: Could not import extension sphinxext.opengraph (exception: cannot import name 'pyplot' from 'matplotlib' (unknown location))

Extension error:
Could not import extension sphinxext.opengraph (exception: cannot import name 'pyplot' from 'matplotlib' (unknown location))
TheTripleV commented 3 months ago

Weird. https://github.com/wpilibsuite/sphinxext-opengraph/blob/main/sphinxext/opengraph/__init__.py#L12 should check for that and prevent matplotlib from loading if its not installed.

I guess that check should be the exact same import that's called later, from matplotlib import pyplot as plt

kloczek commented 2 months ago

That is because matplotlib install dependency is optional.