[DOCS] Remove index file from notebooks (#19619)

This commit is contained in:
Sebastian Golebiewski 2023-09-11 12:56:08 +02:00 committed by GitHub
parent fb59d0eb36
commit 3d872f14e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 90 deletions

View File

@ -76,7 +76,7 @@ function(build_docs)
# build with openvino notebooks
if(ENABLE_OPENVINO_NOTEBOOKS)
set(NBDOC_SCRIPT "${DOCS_SOURCE_DIR}/nbdoc/nbdoc.py")
list(APPEND commands
list(PREPEND commands
COMMAND ${PYTHON_EXECUTABLE} "${NBDOC_SCRIPT}" "${DOCS_SOURCE_DIR}/notebooks" "${RST_OUTPUT}/notebooks"
)
endif()

View File

@ -1,5 +1,3 @@
notebooks_docs = "notebooks.rst"
notebooks_path = "notebooks"
repo_directory = "notebooks"
@ -12,9 +10,6 @@ artifacts_link = "http://repository.toolbox.iotg.sclab.intel.com/projects/ov-not
blacklisted_extensions = ['.xml', '.bin']
section_names = ["Getting Started", "Convert & Optimize",
"Model Demos", "Model Training", "Live Demos"]
# Templates
binder_template = """
@ -100,19 +95,3 @@ See the |installation_link| for instructions to run this tutorial locally on Win
\n
"""
rst_template = """
OpenVINO notebooks documentation
================================
{% for section in sections %}
{{section.name}}
--------------------------------
.. toctree::
:maxdepth: 1
{% for notebook in section.notebooks %} {{notebook.path}}\n{% endfor %}
{% endfor %}
"""

View File

@ -4,9 +4,7 @@ from pathlib import Path
from utils import (
create_content,
add_content_below,
process_notebook_name,
verify_notebook_name,
split_notebooks_into_sections,
)
from consts import (
artifacts_link,
@ -14,14 +12,11 @@ from consts import (
colab_template,
binder_colab_template,
blacklisted_extensions,
notebooks_docs,
notebooks_path,
no_binder_template,
repo_directory,
repo_name,
repo_owner,
rst_template,
section_names,
)
from notebook import Notebook
from section import Section
@ -31,6 +26,7 @@ from jinja2 import Template
from urllib.request import urlretrieve
from requests import get
import os
import sys
class NbTravisDownloader:
@ -79,22 +75,6 @@ class NbTravisDownloader:
class NbProcessor:
def __init__(self, nb_path: str = notebooks_path):
self.nb_path = nb_path
notebooks = [
Notebook(
name=process_notebook_name(notebook),
path=notebook,
)
for notebook in os.listdir(self.nb_path)
if verify_notebook_name(notebook)
]
notebooks = split_notebooks_into_sections(notebooks)
self.rst_data = {
"sections": [
Section(name=section_name, notebooks=section_notebooks)
for section_name, section_notebooks in zip(section_names, notebooks)
]
}
self.binder_data = {
"owner": repo_owner,
"repo": repo_name,
@ -164,18 +144,16 @@ class NbProcessor:
if not add_content_below(button_text, f"{self.nb_path}/{notebook}"):
raise FileNotFoundError("Unable to modify file")
def render_rst(self, path: str = notebooks_docs, template: str = rst_template):
"""Rendering rst file for all notebooks
:param path: Path to notebook main rst file. Defaults to notebooks_docs.
:type path: str
:param template: Template for default rst page. Defaults to rst_template.
:type template: str
"""
with open(path, "w+") as nb_file:
nb_file.writelines(Template(template).render(self.rst_data))
def add_glob_directive(tutorials_file):
with open(tutorials_file, 'r+', encoding='cp437') as mainfile:
readfile = mainfile.read()
if ':glob:' not in readfile:
add_glob = readfile\
.replace(":hidden:\n", ":hidden:\n :glob:\n")\
.replace("notebooks_installation\n", "notebooks_installation\n notebooks/*\n")
mainfile.seek(0)
mainfile.write(add_glob)
mainfile.truncate()
def main():
parser = argparse.ArgumentParser()
@ -185,6 +163,10 @@ def main():
args = parser.parse_args()
sourcedir = args.sourcedir
outdir = args.outdir
main_tutorials_file = Path('../../docs/tutorials.md').resolve(strict=True)
add_glob_directive(main_tutorials_file)
if args.download:
outdir.mkdir(parents=True, exist_ok=True)
# Step 2. Run default pipeline for downloading
@ -196,8 +178,7 @@ def main():
buttons_list = nbp.fetch_binder_list('notebooks_with_binder_buttons.txt')
cbuttons_list = nbp.fetch_colab_list('notebooks_with_colab_buttons.txt')
nbp.add_binder(buttons_list, cbuttons_list)
nbp.render_rst(outdir.joinpath(notebooks_docs))
if __name__ == '__main__':
main()
main()

View File

@ -1,6 +1,4 @@
from jinja2 import Template
from os import path, remove
from shutil import rmtree
def create_content(template: str, notebooks_data: dict, file_name: str):
@ -45,25 +43,6 @@ def add_content_below(text: str, path: str, line=3) -> bool:
return False
def process_notebook_name(notebook_name: str) -> str:
"""Processes notebook name
:param notebook_name: Notebook name by default keeps convention:
[3 digit]-name-with-dashes-with-output.rst,
example: 001-hello-world-with-output.rst
:type notebook_name: str
:returns: Processed notebook name,
001-hello-world-with-output.rst -> 001. hello world
:rtype: str
"""
return (
notebook_name[:3]
+ "."
+ " ".join(notebook_name[4:].split(".")[0].split("-")[:-2])
)
def verify_notebook_name(notebook_name: str) -> bool:
"""Verification based on notebook name
@ -75,14 +54,4 @@ def verify_notebook_name(notebook_name: str) -> bool:
:rtype: bool
"""
return notebook_name[:3].isdigit() and notebook_name[-4:] == ".rst"
def split_notebooks_into_sections(notebooks: list) -> list:
series = [list() for _ in range(5)]
for notebook in notebooks:
try:
series[int(notebook.name[0])].append(notebook)
except IndexError:
pass
return series
return notebook_name[:3].isdigit() and notebook_name[-4:] == ".rst"

View File

@ -15,7 +15,7 @@
:hidden:
notebooks_installation
notebooks/notebooks
This collection of Python tutorials are written for running on Jupyter notebooks.
The tutorials provide an introduction to the OpenVINO™ toolkit and explain how to