File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change 66# The contents of this file are pickled, so don't put values in the namespace
77# that aren't pickleable (module imports are okay, they're removed automatically).
88
9- import importlib
109import os
1110import sys
11+ from importlib import import_module
12+ from importlib .util import find_spec
1213
1314# Make our custom extensions available to Sphinx
1415sys .path .append (os .path .abspath ('tools/extensions' ))
3637 'sphinx.ext.extlinks' ,
3738]
3839
39- # Skip if downstream redistributors haven't installed it
40- try :
41- import sphinxext .opengraph # noqa: F401
42- except ImportError :
43- pass
44- else :
45- extensions .append ('sphinxext.opengraph' )
46-
40+ # Skip if downstream redistributors haven't installed them
41+ _OPTIONAL_EXTENSIONS = (
42+ 'sphinxext.opengraph' ,
43+ )
44+ for optional_ext in _OPTIONAL_EXTENSIONS :
45+ try :
46+ if find_spec (optional_ext ) is not None :
47+ extensions .append (optional_ext )
48+ except (ImportError , ValueError ):
49+ pass
50+ del _OPTIONAL_EXTENSIONS
4751
4852doctest_global_setup = '''
4953try:
6670# We look for the Include/patchlevel.h file in the current Python source tree
6771# and replace the values accordingly.
6872# See Doc/tools/extensions/patchlevel.py
69- version , release = importlib . import_module ('patchlevel' ).get_version_info ()
73+ version , release = import_module ('patchlevel' ).get_version_info ()
7074
7175rst_epilog = f"""
7276.. |python_version_literal| replace:: ``Python { version } ``
You can’t perform that action at this time.
0 commit comments