sphinx_nbexamples/__init__.py
def recursive_processing(self, base_dir, target_dir, it):
        """Method to recursivly process the notebooks in the `base_dir`

        Parameters
        ----------
        base_dir: str
            Path to the base example directory (see the `examples_dir`
            parameter for the :class:`Gallery` class)
        target_dir: str
            Path to the output directory for the rst files (see the
            `gallery_dirs` parameter for the :class:`Gallery` class)
        it: iterable
            The iterator over the subdirectories and files in `base_dir`
            generated by the :func:`os.walk` function"""
        try:
            file_dir, dirs, files = next(it)
        except StopIteration:
            return '', []
        readme_files = {'README.md', 'README.rst', 'README.txt'}
        if readme_files.intersection(files):
            foutdir = file_dir.replace(base_dir, target_dir)
            create_dirs(foutdir)
            this_nbps = [
                NotebookProcessor(
                    infile=f,
                    outfile=os.path.join(foutdir, os.path.basename(f)),
                    disable_warnings=self.disable_warnings,
                    preprocess=(
                        (self.preprocess is True or f in self.preprocess) and
                        not (self.dont_preprocess is True or
                             f in self.dont_preprocess)),
                    clear=((self.clear is True or f in self.clear) and not
                           (self.dont_clear is True or f in self.dont_clear)),
                    code_example=self.code_examples.get(f),
                    supplementary_files=self.supplementary_files.get(f),
                    other_supplementary_files=self.osf.get(f),
                    thumbnail_figure=self.thumbnail_figures.get(f),
                    url=self.get_url(f.replace(base_dir, '')),
                    **self._nbp_kws)
                for f in map(lambda f: os.path.join(file_dir, f),
                             filter(self.pattern.match, files))]
            readme_file = next(iter(readme_files.intersection(files)))
        else:
            return '', []
        labels = OrderedDict()
        this_label = 'gallery_' + foutdir.replace(os.path.sep, '_')
        if this_label.endswith('_'):
            this_label = this_label[:-1]
        for d in dirs:
            label, nbps = self.recursive_processing(
                base_dir, target_dir, it)
            if label:
                labels[label] = nbps
        s = ".. _%s:\n\n" % this_label
        with open(os.path.join(file_dir, readme_file)) as f:
            s += f.read().rstrip() + '\n\n'

        s += "\n\n.. toctree::\n\n"
        s += ''.join('    %s\n' % os.path.splitext(os.path.basename(
            nbp.get_out_file()))[0] for nbp in this_nbps)
        for d in dirs:
            findex = os.path.join(d, 'index.rst')
            if os.path.exists(os.path.join(foutdir, findex)):
                s += '    %s\n' % os.path.splitext(findex)[0]

        s += '\n'

        for nbp in this_nbps:
            code_div = nbp.code_div
            if code_div is not None:
                s += code_div + '\n'
            else:
                s += nbp.thumbnail_div + '\n'
        s += "\n.. raw:: html\n\n    <div style='clear:both'></div>\n"
        for label, nbps in labels.items():
            s += '\n.. only:: html\n\n    .. rubric:: :ref:`%s`\n\n' % (
                label)
            for nbp in nbps:
                code_div = nbp.code_div
                if code_div is not None:
                    s += code_div + '\n'
                else:
                    s += nbp.thumbnail_div + '\n'
            s += "\n.. raw:: html\n\n    <div style='clear:both'></div>\n"

        s += '\n'

        with open(os.path.join(foutdir, 'index.rst'), 'w') as f:
            f.write(s)
        return this_label, list(chain(this_nbps, *labels.values()))
def recursive_processing(self, base_dir, target_dir, it):
        """Method to recursivly process the notebooks in the `base_dir`

        Parameters
        ----------
        base_dir: str
            Path to the base example directory (see the `examples_dir`
            parameter for the :class:`Gallery` class)
        target_dir: str
            Path to the output directory for the rst files (see the
            `gallery_dirs` parameter for the :class:`Gallery` class)
        it: iterable
            The iterator over the subdirectories and files in `base_dir`
            generated by the :func:`os.walk` function"""
        try:
            file_dir, dirs, files = next(it)
        except StopIteration:
            return '', []
        readme_files = {'README.md', 'README.rst', 'README.txt'}
        if readme_files.intersection(files):
            foutdir = file_dir.replace(base_dir, target_dir)
            create_dirs(foutdir)
            this_nbps = [
                NotebookProcessor(
                    infile=f,
                    outfile=os.path.join(foutdir, os.path.basename(f)),
                    disable_warnings=self.disable_warnings,
                    preprocess=(
                        (self.preprocess is True or f in self.preprocess) and
                        not (self.dont_preprocess is True or
                             f in self.dont_preprocess)),
                    clear=((self.clear is True or f in self.clear) and not
                           (self.dont_clear is True or f in self.dont_clear)),
                    code_example=self.code_examples.get(f),
                    supplementary_files=self.supplementary_files.get(f),
                    other_supplementary_files=self.osf.get(f),
                    thumbnail_figure=self.thumbnail_figures.get(f),
                    url=self.get_url(f.replace(base_dir, '')),
                    **self._nbp_kws)
                for f in map(lambda f: os.path.join(file_dir, f),
                             filter(self.pattern.match, files))]
            readme_file = next(iter(readme_files.intersection(files)))
        else:
            return '', []
        labels = OrderedDict()
        this_label = 'gallery_' + foutdir.replace(os.path.sep, '_')
        if this_label.endswith('_'):
            this_label = this_label[:-1]
        for d in dirs:
            label, nbps = self.recursive_processing(
                base_dir, target_dir, it)
            if label:
                labels[label] = nbps
        s = ".. _%s:\n\n" % this_label
        with open(os.path.join(file_dir, readme_file)) as f:
            s += f.read().rstrip() + '\n\n'

        s += "\n\n.. toctree::\n\n"
        s += ''.join('    %s\n' % os.path.splitext(os.path.basename(
            nbp.get_out_file()))[0] for nbp in this_nbps)
        for d in dirs:
            findex = os.path.join(d, 'index.rst')
            if os.path.exists(os.path.join(foutdir, findex)):
                s += '    %s\n' % os.path.splitext(findex)[0]

        s += '\n'

        for nbp in this_nbps:
            code_div = nbp.code_div
            if code_div is not None:
                s += code_div + '\n'
            else:
                s += nbp.thumbnail_div + '\n'
        s += "\n.. raw:: html\n\n    <div style='clear:both'></div>\n"
        for label, nbps in labels.items():
            s += '\n.. only:: html\n\n    .. rubric:: :ref:`%s`\n\n' % (
                label)
            for nbp in nbps:
                code_div = nbp.code_div
                if code_div is not None:
                    s += code_div + '\n'
                else:
                    s += nbp.thumbnail_div + '\n'
            s += "\n.. raw:: html\n\n    <div style='clear:both'></div>\n"

        s += '\n'

        with open(os.path.join(foutdir, 'index.rst'), 'w') as f:
            f.write(s)
        return this_label, list(chain(this_nbps, *labels.values()))
def recursive_processing ( self , base_dir , target_dir , it ) : try : file_dir , dirs , files = next ( it ) except StopIteration : return '' , [ ] readme_files = { 'README.md' , 'README.rst' , 'README.txt' } if readme_files . intersection ( files ) : foutdir = file_dir . replace ( base_dir , target_dir ) create_dirs ( foutdir ) this_nbps = [ NotebookProcessor ( infile = f , outfile = os . path . join ( foutdir , os . path . basename ( f ) ) , disable_warnings = self . disable_warnings , preprocess = ( ( self . preprocess is True or f in self . preprocess ) and not ( self . dont_preprocess is True or f in self . dont_preprocess ) ) , clear = ( ( self . clear is True or f in self . clear ) and not ( self . dont_clear is True or f in self . dont_clear ) ) , code_example = self . code_examples . get ( f ) , supplementary_files = self . supplementary_files . get ( f ) , other_supplementary_files = self . osf . get ( f ) , thumbnail_figure = self . thumbnail_figures . get ( f ) , url = self . get_url ( f . replace ( base_dir , '' ) ) , * * self . _nbp_kws ) for f in map ( lambda f : os . path . join ( file_dir , f ) , filter ( self . pattern . match , files ) ) ] readme_file = next ( iter ( readme_files . intersection ( files ) ) ) else : return '' , [ ] labels = OrderedDict ( ) this_label = 'gallery_' + foutdir . replace ( os . path . sep , '_' ) if this_label . endswith ( '_' ) : this_label = this_label [ : - 1 ] for d in dirs : label , nbps = self . recursive_processing ( base_dir , target_dir , it ) if label : labels [ label ] = nbps s = ".. _%s:\n\n" % this_label with open ( os . path . join ( file_dir , readme_file ) ) as f : s += f . read ( ) . rstrip ( ) + '\n\n' s += "\n\n.. toctree::\n\n" s += '' . join ( '    %s\n' % os . path . splitext ( os . path . basename ( nbp . get_out_file ( ) ) ) [ 0 ] for nbp in this_nbps ) for d in dirs : findex = os . path . join ( d , 'index.rst' ) if os . path . exists ( os . path . join ( foutdir , findex ) ) : s += '    %s\n' % os . path . splitext ( findex ) [ 0 ] s += '\n' for nbp in this_nbps : code_div = nbp . code_div if code_div is not None : s += code_div + '\n' else : s += nbp . thumbnail_div + '\n' s += "\n.. raw:: html\n\n    <div style='clear:both'></div>\n" for label , nbps in labels . items ( ) : s += '\n.. only:: html\n\n    .. rubric:: :ref:`%s`\n\n' % ( label ) for nbp in nbps : code_div = nbp . code_div if code_div is not None : s += code_div + '\n' else : s += nbp . thumbnail_div + '\n' s += "\n.. raw:: html\n\n    <div style='clear:both'></div>\n" s += '\n' with open ( os . path . join ( foutdir , 'index.rst' ) , 'w' ) as f : f . write ( s ) return this_label , list ( chain ( this_nbps , * labels . values ( ) ) )
Method to recursivly process the notebooks in the `base_dir`

        Parameters
        ----------
        base_dir: str
            Path to the base example directory (see the `examples_dir`
            parameter for the :class:`Gallery` class)
        target_dir: str
            Path to the output directory for the rst files (see the
            `gallery_dirs` parameter for the :class:`Gallery` class)
        it: iterable
            The iterator over the subdirectories and files in `base_dir`
            generated by the :func:`os.walk` function
Method to recursivly process the notebooks in the base_dir