Code source de papierstat.datasets.documentation

# -*- coding: utf-8 -*-
"""
Automatatisation de certaines parties de la documentation.


:githublink:`%|py|6`
"""
import os


[docs]def list_notebooks(subfolder, name=None, contains=None): """ Retourne les notebooks qui contiennent *name* dans leur nom. :param subfolder: sous-répertoire où chercher :param name: préfixe à chercher :param contains: extrait à chercher :return: liste des notebooks (sans répertoire) :githublink:`%|py|17` """ this = os.path.dirname(__file__) nbs = [os.path.abspath( os.path.normpath( os.path.join( this, '..', '..', '..', '..', 'notebooks', subfolder))), os.path.abspath( os.path.normpath( os.path.join( this, '..', '..', '..', '_doc', 'notebooks', subfolder)))] nb_ = list(filter(os.path.exists, nbs)) if len(nb_) == 0: raise FileNotFoundError( # pragma: no cover "Unable to find notebooks in\n{0}".format('\n'.join(nbs))) nb = nb_[0] name_ = name if name is not None: names = [_ for _ in os.listdir(nb) if _.startswith(name_)] if contains is not None: names = [_ for _ in os.listdir(nb) if contains in _] if len(names) == 0: raise FileNotFoundError( # pragma: no cover "Unable to find any notebook in '{0}'.".format(nb)) return names