[DOCS] Remove index file from notebooks (#19619)
This commit is contained in:
parent
fb59d0eb36
commit
3d872f14e4
@ -76,7 +76,7 @@ function(build_docs)
|
|||||||
# build with openvino notebooks
|
# build with openvino notebooks
|
||||||
if(ENABLE_OPENVINO_NOTEBOOKS)
|
if(ENABLE_OPENVINO_NOTEBOOKS)
|
||||||
set(NBDOC_SCRIPT "${DOCS_SOURCE_DIR}/nbdoc/nbdoc.py")
|
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"
|
COMMAND ${PYTHON_EXECUTABLE} "${NBDOC_SCRIPT}" "${DOCS_SOURCE_DIR}/notebooks" "${RST_OUTPUT}/notebooks"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
notebooks_docs = "notebooks.rst"
|
|
||||||
|
|
||||||
notebooks_path = "notebooks"
|
notebooks_path = "notebooks"
|
||||||
|
|
||||||
repo_directory = "notebooks"
|
repo_directory = "notebooks"
|
||||||
@ -12,9 +10,6 @@ artifacts_link = "http://repository.toolbox.iotg.sclab.intel.com/projects/ov-not
|
|||||||
|
|
||||||
blacklisted_extensions = ['.xml', '.bin']
|
blacklisted_extensions = ['.xml', '.bin']
|
||||||
|
|
||||||
section_names = ["Getting Started", "Convert & Optimize",
|
|
||||||
"Model Demos", "Model Training", "Live Demos"]
|
|
||||||
|
|
||||||
# Templates
|
# Templates
|
||||||
|
|
||||||
binder_template = """
|
binder_template = """
|
||||||
@ -100,19 +95,3 @@ See the |installation_link| for instructions to run this tutorial locally on Win
|
|||||||
|
|
||||||
\n
|
\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 %}
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
@ -4,9 +4,7 @@ from pathlib import Path
|
|||||||
from utils import (
|
from utils import (
|
||||||
create_content,
|
create_content,
|
||||||
add_content_below,
|
add_content_below,
|
||||||
process_notebook_name,
|
|
||||||
verify_notebook_name,
|
verify_notebook_name,
|
||||||
split_notebooks_into_sections,
|
|
||||||
)
|
)
|
||||||
from consts import (
|
from consts import (
|
||||||
artifacts_link,
|
artifacts_link,
|
||||||
@ -14,14 +12,11 @@ from consts import (
|
|||||||
colab_template,
|
colab_template,
|
||||||
binder_colab_template,
|
binder_colab_template,
|
||||||
blacklisted_extensions,
|
blacklisted_extensions,
|
||||||
notebooks_docs,
|
|
||||||
notebooks_path,
|
notebooks_path,
|
||||||
no_binder_template,
|
no_binder_template,
|
||||||
repo_directory,
|
repo_directory,
|
||||||
repo_name,
|
repo_name,
|
||||||
repo_owner,
|
repo_owner,
|
||||||
rst_template,
|
|
||||||
section_names,
|
|
||||||
)
|
)
|
||||||
from notebook import Notebook
|
from notebook import Notebook
|
||||||
from section import Section
|
from section import Section
|
||||||
@ -31,6 +26,7 @@ from jinja2 import Template
|
|||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
from requests import get
|
from requests import get
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class NbTravisDownloader:
|
class NbTravisDownloader:
|
||||||
@ -79,22 +75,6 @@ class NbTravisDownloader:
|
|||||||
class NbProcessor:
|
class NbProcessor:
|
||||||
def __init__(self, nb_path: str = notebooks_path):
|
def __init__(self, nb_path: str = notebooks_path):
|
||||||
self.nb_path = nb_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 = {
|
self.binder_data = {
|
||||||
"owner": repo_owner,
|
"owner": repo_owner,
|
||||||
"repo": repo_name,
|
"repo": repo_name,
|
||||||
@ -164,18 +144,16 @@ class NbProcessor:
|
|||||||
if not add_content_below(button_text, f"{self.nb_path}/{notebook}"):
|
if not add_content_below(button_text, f"{self.nb_path}/{notebook}"):
|
||||||
raise FileNotFoundError("Unable to modify file")
|
raise FileNotFoundError("Unable to modify file")
|
||||||
|
|
||||||
def render_rst(self, path: str = notebooks_docs, template: str = rst_template):
|
def add_glob_directive(tutorials_file):
|
||||||
"""Rendering rst file for all notebooks
|
with open(tutorials_file, 'r+', encoding='cp437') as mainfile:
|
||||||
|
readfile = mainfile.read()
|
||||||
:param path: Path to notebook main rst file. Defaults to notebooks_docs.
|
if ':glob:' not in readfile:
|
||||||
:type path: str
|
add_glob = readfile\
|
||||||
:param template: Template for default rst page. Defaults to rst_template.
|
.replace(":hidden:\n", ":hidden:\n :glob:\n")\
|
||||||
:type template: str
|
.replace("notebooks_installation\n", "notebooks_installation\n notebooks/*\n")
|
||||||
|
mainfile.seek(0)
|
||||||
"""
|
mainfile.write(add_glob)
|
||||||
with open(path, "w+") as nb_file:
|
mainfile.truncate()
|
||||||
nb_file.writelines(Template(template).render(self.rst_data))
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@ -185,6 +163,10 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
sourcedir = args.sourcedir
|
sourcedir = args.sourcedir
|
||||||
outdir = args.outdir
|
outdir = args.outdir
|
||||||
|
|
||||||
|
main_tutorials_file = Path('../../docs/tutorials.md').resolve(strict=True)
|
||||||
|
add_glob_directive(main_tutorials_file)
|
||||||
|
|
||||||
if args.download:
|
if args.download:
|
||||||
outdir.mkdir(parents=True, exist_ok=True)
|
outdir.mkdir(parents=True, exist_ok=True)
|
||||||
# Step 2. Run default pipeline for downloading
|
# Step 2. Run default pipeline for downloading
|
||||||
@ -196,7 +178,6 @@ def main():
|
|||||||
buttons_list = nbp.fetch_binder_list('notebooks_with_binder_buttons.txt')
|
buttons_list = nbp.fetch_binder_list('notebooks_with_binder_buttons.txt')
|
||||||
cbuttons_list = nbp.fetch_colab_list('notebooks_with_colab_buttons.txt')
|
cbuttons_list = nbp.fetch_colab_list('notebooks_with_colab_buttons.txt')
|
||||||
nbp.add_binder(buttons_list, cbuttons_list)
|
nbp.add_binder(buttons_list, cbuttons_list)
|
||||||
nbp.render_rst(outdir.joinpath(notebooks_docs))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
from os import path, remove
|
|
||||||
from shutil import rmtree
|
|
||||||
|
|
||||||
|
|
||||||
def create_content(template: str, notebooks_data: dict, file_name: str):
|
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
|
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:
|
def verify_notebook_name(notebook_name: str) -> bool:
|
||||||
"""Verification based on notebook name
|
"""Verification based on notebook name
|
||||||
|
|
||||||
@ -76,13 +55,3 @@ def verify_notebook_name(notebook_name: str) -> bool:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return notebook_name[:3].isdigit() and notebook_name[-4:] == ".rst"
|
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
|
|
@ -15,7 +15,7 @@
|
|||||||
:hidden:
|
:hidden:
|
||||||
|
|
||||||
notebooks_installation
|
notebooks_installation
|
||||||
notebooks/notebooks
|
|
||||||
|
|
||||||
This collection of Python tutorials are written for running on Jupyter 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
|
The tutorials provide an introduction to the OpenVINO™ toolkit and explain how to
|
||||||
|
Loading…
Reference in New Issue
Block a user