Code source de teachpyx.datasets.documentation

# coding: utf-8
import os
import re
from typing import List, Optional


[docs] def root(subfolder: str) -> str: "Returns the local folder for all notebooks." this = os.path.dirname(__file__) if subfolder == "c_data": return os.path.abspath(os.path.normpath(os.path.join(this, "..", "..", "_doc"))) return os.path.abspath( os.path.normpath(os.path.join(this, "..", "..", "_doc", "practice")) )
[docs] def list_notebooks( subfolder: str, name: Optional[str] = None, contains: Optional[str] = None ) -> List[str]: """ 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) """ nbs = [os.path.join(root(subfolder), subfolder)] nb_ = list(filter(os.path.exists, nbs)) assert len(nb_) > 0, "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 _] assert len(names) > 0, ( f"Unable to find any notebook in {nb!r} " f"(this file is {__file__}, " f"root is {root(subfolder)}, " f"sub is {subfolder!r}, name is {name!r})." ) return names