Skip to content
Permalink
Browse files

add parameter neg_pattern for #68

  • Loading branch information...
sdpython committed Sep 4, 2017
1 parent 797e68c commit f90ee0807b2dd527140913c5e16724ab634cdb64
@@ -23,3 +23,6 @@
# there is an issue with this attribute on Anaconda math_number_all
assert math_number_all or not math_number_all
blog_root = "http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/"

# remove notebooks following this pattern
nbneg_pattern = ".*[\\\\/]temp_.*"
@@ -784,15 +784,15 @@ def add_tag_for_slideshow(ipy, folder, encoding="utf8"):
return output


def build_notebooks_gallery(nbs, fileout, layout="classic", keep_temp=False, fLOG=noLOG):
def build_notebooks_gallery(nbs, fileout, layout="classic", neg_pattern=None, fLOG=noLOG):
"""
Creates a rst page (gallery) with links to all notebooks.
For each notebook, it creates a snippet.
@param nbs list of notebooks to consider or tuple(full path, rst),
@param fileout file to create
@param layout ``'classic'`` or ``'table'``
@param keep_temp keep every notebook including notebook in folder ``temp_*``
@param neg_pattern do not consider notebooks matching this regular expression
@param fLOG logging function
@return created file name
@@ -829,9 +829,8 @@ def build_notebooks_gallery(nbs, fileout, layout="classic", keep_temp=False, fLO
The function was renamed into *build_notebooks_gallery*
(previous name *add_notebook_page*).
Add a link on notebook coverage.
Parameters *layout*, *keep_temp* were added.
Parameters *layout*, *neg_pattern* were added.
"""
neg_pattern = None if keep_temp else ".*[\\/]temp_.*"
if not isinstance(nbs, list):
fold = nbs
nbs = explore_folder(
@@ -848,17 +847,13 @@ def build_notebooks_gallery(nbs, fileout, layout="classic", keep_temp=False, fLO
containers = {}
for tu in nbs:
if isinstance(tu, (tuple, list)):
if not keep_temp and ("/temp_" in tu[0] or "\\temp_" in tu[0]):
continue
if tu[0] is None or ("/" not in tu[0] and "\\" not in tu[0]):
rst.append((tuple(), tu[1]))
else:
way = tuple(tu[0].replace("\\", "/").split("/")[:-1])
hier.add(way)
rst.append((way, tu[1]))
else:
if not keep_temp and ("/temp_" in tu or "\\temp_" in tu):
continue
rst.append((tuple(), tu))
name = rst[-1][1]
ext = os.path.splitext(name)[-1]
@@ -267,6 +267,8 @@ def generate_help_sphinx(project_var_name, clean=False, root=".",
Parameter *parallel* was added.
The parameter *nblayout* in the configuration file specifies
the layout for the notebook gallery. ``'classic'`` or ``'table'``.
The parameter *nbneg_pattern* can be used to remove notebooks from
the gallery if they match this regular expression.
.. todoext::
:title: add subfolder when building indexes of notebooks
@@ -526,6 +528,7 @@ def lay_build_override_newconf(t3):
##########
nblayout = theconf.__dict__.get("nblayout", "classic")
nblinks = theconf.__dict__.get("nblinks", None)
nbneg_pattern = theconf.__dict__.get("nbneg_pattern", None)
if nblinks is not None and len(nblinks) > 0:
fLOG("[generate_help_sphinx] NBLINKS - BEGIN")
for i, (k, v) in enumerate(sorted(nblinks.items())):
@@ -662,7 +665,7 @@ def lay_build_override_newconf(t3):
os.path.join(root, "_doc", "sphinxdoc", "source", "notebooks"))
if os.path.exists(notebook_dir):
notebooks = explore_folder(
notebook_dir, pattern=".*[.]ipynb", neg_pattern=".*[\\/]temp_.*", fullname=True)[1]
notebook_dir, pattern=".*[.]ipynb", neg_pattern=nbneg_pattern, fullname=True)[1]
notebooks = [_ for _ in notebooks if "checkpoint" not in _]
if len(notebooks) > 0:
fLOG("*******************************************")

0 comments on commit f90ee08

Please sign in to comment.
You can’t perform that action at this time.