1818
1919import os
2020import sys
21+ import shutil
2122from configparser import ConfigParser
22- from recommonmark .transform import AutoStructify
23- from recommonmark .parser import CommonMarkParser
24- from jinja2 import Environment , FileSystemLoader , StrictUndefined
2523
2624root = os .path .abspath (os .path .join ('..' ))
2725sys .path .insert (0 , root )
2826
2927# Load metadata from setup.cfg
30- metadata_file = os .path .join (root , 'setup.cfg' )
31- metadata = ConfigParser ()
32- metadata .read (metadata_file )
33- metadata = metadata ['metadata' ]
34-
35- with open (os .path .join (root , 'README.md' ), 'rt' ) as fh :
36- metadata ['long_description' ] = fh .read ()
37-
38- # Render index.md with metadata
39- def write_index ():
40- path = os .path .join (root , 'docs' , '_templates' )
41- env = Environment (loader = FileSystemLoader (path ),
42- undefined = StrictUndefined )
43- template = env .get_template ('index.md' )
44- s = template .render (** metadata )
45- s = s .replace ('<!--' , '' )
46- s = s .replace ('-->' , '' )
47-
48- with open (os .path .join (root , 'docs' , 'index.md' ), 'wt' ) as fh :
49- fh .truncate ()
50- fh .write (s )
51-
52- write_index ()
28+ meta_path = os .path .join (root , 'setup.cfg' )
29+ meta = ConfigParser ()
30+ meta .read (meta_path )
31+ meta = meta ['metadata' ]
32+
33+ # Clear generated documents
34+ if (not os .path .exists ('_build' ) or len (os .listdir ('_build' )) == 0 ) and os .path .exists ('generated' ):
35+ shutil .rmtree ('generated' )
5336
5437# -- Project information -----------------------------------------------------
5538
56- project = metadata ['project' ]
57- copyright = metadata ['copyright' ]
58- author = metadata ['author' ]
39+ project = meta ['project' ]
40+ copyright = meta ['copyright' ]
41+ author = meta ['author' ]
5942
6043# The short X.Y version
61- version = metadata ['version' ]
44+ version = meta ['version' ]
6245# The full version, including alpha/beta/rc tags
63- release = metadata ['version' ]
64-
65- github_doc_root = 'https://github.com/line-mind/{}/tree/master/' .format (metadata ['name' ])
46+ release = meta ['version' ]
6647
6748# -- General configuration ---------------------------------------------------
6849
@@ -74,6 +55,7 @@ def write_index():
7455# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
7556# ones.
7657extensions = [
58+ #'matplotlib.sphinxext.plot_directive',
7759 'sphinx.ext.autodoc' ,
7860 'sphinx.ext.doctest' ,
7961 'sphinx.ext.intersphinx' ,
@@ -84,7 +66,7 @@ def write_index():
8466 'numpydoc' ,
8567 #'sphinx.ext.imgmath',
8668 'sphinx.ext.viewcode' ,
87- 'sphinx.ext.githubpages ' ,
69+ #'sphinxcontrib.spelling ',
8870]
8971
9072# Add any paths that contain templates here, relative to this directory.
@@ -96,10 +78,6 @@ def write_index():
9678source_suffix = ['.rst' , '.md' ]
9779#source_suffix = '.rst'
9880
99- source_parsers = {
100- '.md' : CommonMarkParser
101- }
102-
10381# The master toctree document.
10482master_doc = 'index'
10583
@@ -125,6 +103,7 @@ def write_index():
125103# a list of builtin themes.
126104#
127105themedir = os .path .join (os .path .dirname (__file__ ), 'scipy-sphinx-theme' , '_theme' )
106+
128107if not os .path .isdir (themedir ):
129108 raise RuntimeError ('Get the scipy-sphinx-theme first, '
130109 'via git submodule init && git submodule update' )
@@ -137,14 +116,16 @@ def write_index():
137116numpydoc_show_class_members = False
138117numpydoc_show_inherited_class_members = False
139118class_members_toctree = False
119+ autosummary_generate = True
140120
141121html_theme_options = {
142122 "edit_link" : False ,
143123 "sidebar" : "left" ,
144124 "scipy_org_logo" : False ,
145125 "rootlinks" : []
146126}
147- html_sidebars = {}
127+
128+ html_sidebars = {'index' : ['searchbox.html' ]}
148129
149130html_title = "%s v%s Manual" % (project , version )
150131html_last_updated_fmt = '%b %d, %Y'
@@ -174,7 +155,7 @@ def write_index():
174155# -- Options for HTMLHelp output ---------------------------------------------
175156
176157# Output file base name for HTML help builder.
177- htmlhelp_basename = '{}_doc ' .format (metadata ['name' ])
158+ htmlhelp_basename = '{}' .format (meta ['name' ])
178159
179160
180161# -- Options for LaTeX output ------------------------------------------------
@@ -203,7 +184,7 @@ def write_index():
203184# (source start file, target name, title,
204185# author, documentclass [howto, manual, or own class]).
205186latex_documents = [
206- (master_doc , '{}.tex' .format (metadata ['name' ]), '{} Documentation' .format (metadata ['project' ]),
187+ (master_doc , '{}.tex' .format (meta ['name' ]), '{} Documentation' .format (meta ['project' ]),
207188 author , 'manual' ),
208189]
209190
@@ -213,7 +194,7 @@ def write_index():
213194# One entry per manual page. List of tuples
214195# (source start file, name, description, authors, manual section).
215196man_pages = [
216- (master_doc , metadata ['name' ], '{} Documentation' .format (metadata ['project' ]),
197+ (master_doc , meta ['name' ], '{} Documentation' .format (meta ['project' ]),
217198 [author ], 1 )
218199]
219200
@@ -224,8 +205,8 @@ def write_index():
224205# (source start file, target name, title, author,
225206# dir menu entry, description, category)
226207texinfo_documents = [
227- (master_doc , metadata ['name' ], '{} Documentation' .format (metadata ['project' ]),
228- author , metadata ['name' ], metadata ['description' ],
208+ (master_doc , meta ['name' ], '{} Documentation' .format (meta ['project' ]),
209+ author , meta ['name' ], meta ['description' ],
229210 'Miscellaneous' ),
230211]
231212
@@ -235,17 +216,14 @@ def write_index():
235216# -- Options for intersphinx extension ---------------------------------------
236217
237218# Example configuration for intersphinx: refer to the Python standard library.
238- intersphinx_mapping = {'https://docs.python.org/' : None }
219+ intersphinx_mapping = {
220+ 'python' : ('https://docs.python.org/3' , None ),
221+ 'numpy' : ('https://docs.scipy.org/doc/numpy/' , None ),
222+ 'scipy' : ('https://docs.scipy.org/doc/scipy/reference/' , None ),
223+ 'pandas' : ('https://pandas.pydata.org/pandas-docs/stable' , None ),
224+ }
239225
240226# -- Options for todo extension ----------------------------------------------
241227
242228# If true, `todo` and `todoList` produce output, else they produce nothing.
243229todo_include_todos = True
244-
245- # AutoStructify setup
246- def setup (app ):
247- app .add_config_value ('recommonmark_config' , {
248- 'url_resolver' : lambda url : github_doc_root + url ,
249- 'auto_toc_tree_section' : 'Table of Contents' ,
250- }, True )
251- app .add_transform (AutoStructify )
0 commit comments