Coverage for pyquickhelper/sphinxext/__init__.py: 100%

80 statements  

« prev     ^ index     » next       coverage.py v6.4.3, created at 2022-08-13 03:05 +0200

1""" 

2@file 

3@brief Subpart related to sphinx extensions 

4 

5.. todoext:: 

6 :title: add directive for a sortable table 

7 :tag: enhancement 

8 :issue: 27 

9 

10 Based on `slickgrid <https://github.com/mleibman/SlickGrid/tree/master/examples>`_. 

11""" 

12import warnings 

13from sphinx.ext.autodoc import setup as setup_autodoc 

14from sphinx.ext.imgmath import setup as setup_imgmath 

15from sphinxcontrib.imagesvg import setup as setup_imagesvg 

16from sphinx.ext.graphviz import setup as setup_graphviz 

17from sphinx.ext.todo import setup as setup_todo 

18 

19from .blog_post import BlogPost 

20from .blog_post_list import BlogPostList 

21from .sphinx_bigger_extension import bigger_node, bigger_role 

22from .sphinx_blocref_extension import BlocRef, BlocRefList 

23from .sphinx_blog_extension import BlogPostDirective, BlogPostDirectiveAgg 

24from .sphinx_cmdref_extension import CmdRef, CmdRefList 

25from .sphinx_epkg_extension import epkg_node 

26from .sphinx_exref_extension import ExRef, ExRefList 

27from .sphinx_faqref_extension import FaqRef, FaqRefList 

28from .sphinx_githublink_extension import githublink_node, githublink_role 

29from .sphinx_gitlog_extension import gitlog_node, gitlog_role 

30from .sphinx_mathdef_extension import MathDef, MathDefList 

31from .sphinx_quote_extension import QuoteNode 

32from .sphinx_nbref_extension import NbRef, NbRefList 

33from .sphinx_postcontents_extension import PostContentsDirective, postcontents_node 

34from .sphinx_tocdelay_extension import TocDelayDirective, tocdelay_node 

35from .sphinx_youtube_extension import YoutubeDirective, youtube_node 

36from .sphinx_sharenet_extension import ShareNetDirective, sharenet_node 

37from .sphinx_downloadlink_extension import process_downloadlink_role 

38from .sphinx_video_extension import VideoDirective, video_node 

39from .sphinx_image_extension import SimpleImageDirective, simpleimage_node 

40from .sphinx_template_extension import tpl_node 

41from .sphinx_todoext_extension import TodoExt, TodoExtList 

42from .documentation_link import python_link_doc 

43 

44from ..sphinxext.sphinx_autosignature import setup as setup_signature 

45from ..sphinxext.sphinx_bigger_extension import setup as setup_bigger 

46from ..sphinxext.sphinx_blocref_extension import setup as setup_blocref 

47from ..sphinxext.sphinx_blog_extension import setup as setup_blog 

48from ..sphinxext.sphinx_collapse_extension import setup as setup_collapse 

49from ..sphinxext.sphinx_gdot_extension import setup as setup_gdot 

50from ..sphinxext.sphinx_cmdref_extension import setup as setup_cmdref 

51from ..sphinxext.sphinx_docassert_extension import setup as setup_docassert 

52from ..sphinxext.sphinx_epkg_extension import setup as setup_epkg 

53from ..sphinxext.sphinx_exref_extension import setup as setup_exref 

54from ..sphinxext.sphinx_faqref_extension import setup as setup_faqref 

55from ..sphinxext.sphinx_githublink_extension import setup as setup_githublink 

56from ..sphinxext.sphinx_gitlog_extension import setup as setup_gitlog 

57from ..sphinxext.sphinx_image_extension import setup as setup_simpleimage 

58from ..sphinxext.sphinx_mathdef_extension import setup as setup_mathdef 

59from ..sphinxext.sphinx_quote_extension import setup as setup_quote 

60from ..sphinxext.sphinx_nbref_extension import setup as setup_nbref 

61from ..sphinxext.sphinx_postcontents_extension import setup as setup_postcontents 

62from ..sphinxext.sphinx_runpython_extension import setup as setup_runpython 

63from ..sphinxext.sphinx_runpython_extension import RunPythonDirective, runpython_node 

64from ..sphinxext.sphinx_sharenet_extension import setup as setup_sharenet 

65from ..sphinxext.sphinx_downloadlink_extension import setup as setup_downloadlink 

66from ..sphinxext.sphinx_template_extension import setup as setup_tpl 

67from ..sphinxext.sphinx_tocdelay_extension import setup as setup_tocdelay 

68from ..sphinxext.sphinx_toctree_extension import setup as setup_toctree 

69from ..sphinxext.sphinx_todoext_extension import setup as setup_todoext 

70from ..sphinxext.sphinx_video_extension import setup as setup_video 

71from ..sphinxext.sphinx_youtube_extension import setup as setup_youtube 

72from ..sphinxext.sphinximages.sphinxtrib.images import setup as setup_image 

73 

74from ..sphinxext.sphinx_doctree_builder import setup as setup_doctree 

75from ..sphinxext.sphinx_latex_builder import setup as setup_latex 

76from ..sphinxext.sphinx_md_builder import setup as setup_md 

77from ..sphinxext.sphinx_rst_builder import setup as setup_rst 

78 

79 

80def get_default_extensions(load_bokeh=False): 

81 """ 

82 Returns a list of default extensions. 

83 

84 @param load_bokeh loads :epkg:`bokeh` extensions 

85 (can be disabled as it is quite slow) 

86 @return list of :epkg:`Sphinx` extensions 

87 

88 The current list is: 

89 

90 .. runpython:: 

91 :showcode: 

92 

93 from pyquickhelper.sphinxext import get_default_extensions 

94 print("\\n".join(get_default_extensions())) 

95 """ 

96 # We delay these imports. 

97 # They change matplotlib backend if executed. 

98 with warnings.catch_warnings(): 

99 warnings.simplefilter("ignore", DeprecationWarning) 

100 from matplotlib.pyplot import get_backend, switch_backend 

101 backend = get_backend() 

102 from matplotlib.sphinxext.plot_directive import setup as setup_plot 

103 backend_ = get_backend() 

104 if backend_ != backend: # pragma: no cover 

105 import matplotlib 

106 try: 

107 with warnings.catch_warnings(record=True): 

108 warnings.simplefilter("error", UserWarning) 

109 matplotlib.use('Agg') 

110 except UserWarning: 

111 import matplotlib.pyplot as plt # pylint: disable=W0611 

112 switch_backend("Agg") 

113 

114 default_setups = [ 

115 setup_toctree, 

116 setup_blog, setup_runpython, setup_sharenet, 

117 setup_todoext, setup_bigger, setup_githublink, 

118 setup_runpython, setup_mathdef, setup_blocref, 

119 setup_faqref, setup_exref, setup_nbref, 

120 setup_docassert, setup_signature, setup_tpl, 

121 setup_cmdref, setup_epkg, setup_rst, setup_md, 

122 setup_latex, setup_doctree, 

123 setup_postcontents, setup_tocdelay, setup_youtube, 

124 # directives from sphinx 

125 setup_graphviz, setup_imgmath, setup_todo, 

126 # the rest of it 

127 setup_autodoc, setup_imagesvg, 

128 setup_plot, setup_image, setup_collapse, setup_gdot, 

129 setup_video, setup_simpleimage, setup_downloadlink, 

130 setup_quote, setup_gitlog] 

131 

132 if load_bokeh: 

133 try: 

134 import bokeh # pylint: disable=W0611 

135 from ..sphinxext.bokeh.bokeh_plot import setup as setup_bokeh 

136 default_setups.append(setup_bokeh) 

137 except ImportError: # pragma: no cover 

138 # bokeh is not installed. 

139 pass 

140 

141 return [_.__module__ for _ in default_setups] 

142 

143 

144def get_default_standard_extensions(use_mathjax=False): 

145 """ 

146 Returns a list of standard extensions. 

147 

148 @param use_mathjax use :epkg:`mathjax` or :epkg:`imgmath` 

149 @return list of standard extension. 

150 """ 

151 extensions = [ 

152 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.coverage', 

153 'sphinx.ext.extlinks', 'sphinx.ext.graphviz', 'sphinx.ext.ifconfig', 

154 'sphinx.ext.inheritance_diagram', 

155 'sphinx.ext.mathjax' if use_mathjax else 'sphinx.ext.imgmath', 

156 'sphinx.ext.napoleon', 'sphinx.ext.todo', 

157 'jupyter_sphinx.execute', 

158 'sphinxcontrib.imagesvg', 

159 'matplotlib.sphinxext.plot_directive', 

160 ] 

161 

162 return extensions