mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-27 18:25:32 +08:00
Links to API in examples
This commit is contained in:
@@ -58,7 +58,11 @@ def get_data(url, gallery_dir):
|
||||
if sys.version_info[0] == 2 and isinstance(url, unicode):
|
||||
url = url.encode('utf-8')
|
||||
|
||||
cached_file = os.path.join(gallery_dir, 'searchindex')
|
||||
cwd = os.getcwd()
|
||||
if 'source' in cwd:
|
||||
cached_file = os.path.join(gallery_dir, 'searchindex')
|
||||
else:
|
||||
cached_file = os.path.join('source', gallery_dir, 'searchindex')
|
||||
search_index = shelve.open(cached_file)
|
||||
if url in search_index:
|
||||
data = search_index[url]
|
||||
@@ -318,7 +322,6 @@ class SphinxDocLinkResolver(object):
|
||||
def _embed_code_links(app, gallery_conf, gallery_dir):
|
||||
# Add resolvers for the packages for which we want to show links
|
||||
doc_resolvers = {}
|
||||
|
||||
for this_module, url in gallery_conf['reference_url'].items():
|
||||
try:
|
||||
if url is None:
|
||||
@@ -341,9 +344,10 @@ def _embed_code_links(app, gallery_conf, gallery_dir):
|
||||
"Error:\n".format(this_module))
|
||||
print(e.args)
|
||||
|
||||
working_dir = os.getcwd()
|
||||
os.chdir(app.builder.srcdir)
|
||||
html_gallery_dir = os.path.abspath(os.path.join(app.builder.outdir,
|
||||
gallery_dir))
|
||||
|
||||
# patterns for replacement
|
||||
link_pattern = '<a href="%s">%s</a>'
|
||||
orig_pattern = '<span class="n">%s</span>'
|
||||
@@ -356,7 +360,6 @@ def _embed_code_links(app, gallery_conf, gallery_dir):
|
||||
subpath = dirpath[len(html_gallery_dir) + 1:]
|
||||
pickle_fname = os.path.join(gallery_dir, subpath,
|
||||
fname[:-5] + '_codeobj.pickle')
|
||||
|
||||
if os.path.exists(pickle_fname):
|
||||
# we have a pickle file with the objects to embed links for
|
||||
with open(pickle_fname, 'rb') as fid:
|
||||
@@ -366,7 +369,6 @@ def _embed_code_links(app, gallery_conf, gallery_dir):
|
||||
# generate replacement strings with the links
|
||||
for name, cobj in example_code_obj.items():
|
||||
this_module = cobj['module'].split('.')[0]
|
||||
|
||||
if this_module not in doc_resolvers:
|
||||
continue
|
||||
|
||||
@@ -403,6 +405,7 @@ def _embed_code_links(app, gallery_conf, gallery_dir):
|
||||
line = expr.sub(substitute_link, line)
|
||||
fid.write(line.encode('utf-8'))
|
||||
print('[done]')
|
||||
os.chdir(working_dir)
|
||||
|
||||
|
||||
def embed_code_links(app, exception):
|
||||
|
||||
@@ -73,15 +73,16 @@ def generate_gallery_rst(app):
|
||||
if not isinstance(gallery_dirs, list):
|
||||
gallery_dirs = [gallery_dirs]
|
||||
|
||||
# cd to the appropriate directory regardless of sphinx configuration
|
||||
working_dir = os.getcwd()
|
||||
os.chdir(app.builder.srcdir)
|
||||
|
||||
mod_examples_dir = os.path.relpath(gallery_conf['mod_example_dir'],
|
||||
app.builder.srcdir)
|
||||
seen_backrefs = set()
|
||||
|
||||
computation_times = []
|
||||
|
||||
# cd to the appropriate directory regardless of sphinx configuration
|
||||
working_dir = os.getcwd()
|
||||
os.chdir(app.builder.srcdir)
|
||||
for examples_dir, gallery_dir in zip(examples_dirs, gallery_dirs):
|
||||
examples_dir = os.path.relpath(examples_dir,
|
||||
app.builder.srcdir)
|
||||
@@ -100,7 +101,6 @@ def generate_gallery_rst(app):
|
||||
seen_backrefs)
|
||||
|
||||
computation_times += this_computation_times
|
||||
|
||||
fhindex.write(this_fhindex)
|
||||
for directory in sorted(os.listdir(examples_dir)):
|
||||
if os.path.isdir(os.path.join(examples_dir, directory)):
|
||||
@@ -113,7 +113,6 @@ def generate_gallery_rst(app):
|
||||
computation_times += this_computation_times
|
||||
|
||||
fhindex.flush()
|
||||
|
||||
# Back to initial directory
|
||||
os.chdir(working_dir)
|
||||
|
||||
|
||||
+8
-2
@@ -31,7 +31,7 @@ extensions = ['sphinx.ext.autodoc',
|
||||
'sphinx.ext.imgmath',
|
||||
'numpydoc',
|
||||
'sphinx.ext.autosummary',
|
||||
'plot2rst',
|
||||
#'plot2rst',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.linkcode',
|
||||
'sphinx_gallery.gen_gallery'
|
||||
@@ -44,11 +44,17 @@ autosummary_generate = True
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
sphinx_gallery_conf = {
|
||||
# 'doc_module' : 'skimage',
|
||||
'doc_module' : 'skimage',
|
||||
# path to your examples scripts
|
||||
'examples_dirs' : '../examples',
|
||||
# path where to save gallery generated examples
|
||||
'gallery_dirs' : 'auto_examples',
|
||||
'mod_example_dir': 'api',
|
||||
'reference_url' : {
|
||||
'skimage': None,
|
||||
'matplotlib': 'http://matplotlib.org',
|
||||
'numpy': 'http://docs.scipy.org/doc/numpy-1.6.0',
|
||||
'scipy': 'http://docs.scipy.org/doc/scipy-0.11.0/reference',}
|
||||
}
|
||||
|
||||
# Determine if the matplotlib has a recent enough version of the
|
||||
|
||||
Reference in New Issue
Block a user