|
6 | 6 | # The contents of this file are pickled, so don't put values in the namespace
|
7 | 7 | # that aren't pickleable (module imports are okay, they're removed automatically).
|
8 | 8 |
|
9 |
| -import importlib |
10 | 9 | import os
|
11 | 10 | import sys
|
| 11 | +from importlib import import_module |
| 12 | +from importlib.util import find_spec |
12 | 13 |
|
13 | 14 | # Make our custom extensions available to Sphinx
|
14 | 15 | sys.path.append(os.path.abspath('tools/extensions'))
|
|
36 | 37 | 'sphinx.ext.extlinks',
|
37 | 38 | ]
|
38 | 39 |
|
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 = ('sphinxext.opengraph',) |
| 42 | +for optional_ext in _OPTIONAL_EXTENSIONS: |
| 43 | + try: |
| 44 | + if find_spec(optional_ext) is not None: |
| 45 | + extensions.append(optional_ext) |
| 46 | + except (ImportError, ValueError): |
| 47 | + pass |
| 48 | +del _OPTIONAL_EXTENSIONS |
47 | 49 |
|
48 | 50 | doctest_global_setup = '''
|
49 | 51 | try:
|
|
66 | 68 | # We look for the Include/patchlevel.h file in the current Python source tree
|
67 | 69 | # and replace the values accordingly.
|
68 | 70 | # See Doc/tools/extensions/patchlevel.py
|
69 |
| -version, release = importlib.import_module('patchlevel').get_version_info() |
| 71 | +version, release = import_module('patchlevel').get_version_info() |
70 | 72 |
|
71 | 73 | rst_epilog = f"""
|
72 | 74 | .. |python_version_literal| replace:: ``Python {version}``
|
|
0 commit comments