From 0908908227bff09674485d20bd1e7de0ffa46af2 Mon Sep 17 00:00:00 2001 From: tadamczx <156996781+tadamczx@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:24:51 +0200 Subject: [PATCH] [DOCS] OpenVINO Python API docs build fix (#24952) ### Details: - *item1* - *...* ### Tickets: - *ticket-id* --- docs/CMakeLists.txt | 5 +- .../templates/custom-class-template.rst | 32 +++++++++ .../templates/custom-module-template.rst | 68 +++++++++++++++++++ .../install_appropriate_openvino_version.py | 66 ++++++++++++++++++ 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-class-template.rst create mode 100644 docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-module-template.rst create mode 100644 docs/scripts/install_appropriate_openvino_version.py diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 8b57988ca14..797c95ef7d9 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -33,6 +33,7 @@ function(build_docs) set(DOXYGEN_MAPPING_SCRIPT "${SCRIPTS_DIR}/create_mapping.py") set(DOCS_MAPPING_SCRIPT "${SCRIPTS_DIR}/create_doc_mapping.py") set(BREATHE_APIDOC_SCRIPT "${SCRIPTS_DIR}/apidoc.py") + set(OV_INSTALLATION_SCRIPT "${SCRIPTS_DIR}/install_appropriate_openvino_version.py") # Doxygen/Sphinx setup set(DOXYGEN_XML_OUTPUT "${DOCS_BUILD_DIR}/xml") @@ -62,7 +63,9 @@ function(build_docs) if(${ENABLE_PYTHON_API}) list(APPEND commands COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "STARTED preprocessing OpenVINO Python API") - list(APPEND commands COMMAND ${Python3_EXECUTABLE} -m pip install openvino) + list(APPEND commands COMMAND ${Python3_EXECUTABLE} ${OV_INSTALLATION_SCRIPT} + --ov_dir=${SPHINX_SETUP_DIR} + --python=${Python3_EXECUTABLE}) list(APPEND commands COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "FINISHED preprocessing OpenVINO Python API") endif() diff --git a/docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-class-template.rst b/docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-class-template.rst new file mode 100644 index 00000000000..710766c8aae --- /dev/null +++ b/docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-class-template.rst @@ -0,0 +1,32 @@ +{{ fullname | escape | underline}} + +.. currentmodule:: {{ module }} + +.. autoclass:: {{ objname }} + :members: + :show-inheritance: + :inherited-members: + + {% block methods %} + .. automethod:: __init__ + + {% if methods %} + .. rubric:: Methods + + .. autosummary:: + {% for met in methods %} + ~{{ name }}.{{ met }} + {%- endfor %} + {% endif %} + {% endblock %} + + {% block attributes %} + {% if attributes %} + .. rubric:: Attributes + + .. autosummary:: + {% for att in attributes %} + ~{{ name }}.{{ att }} + {%- endfor %} + {% endif %} + {% endblock %} diff --git a/docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-module-template.rst b/docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-module-template.rst new file mode 100644 index 00000000000..fa60a39f44d --- /dev/null +++ b/docs/openvino_sphinx_theme/openvino_sphinx_theme/templates/custom-module-template.rst @@ -0,0 +1,68 @@ +{{ fullname | escape | underline}} + +.. automodule:: {{ fullname }} + +{% block attributes %} +{% if attributes %} + .. rubric:: Module Attributes + + .. autosummary:: + :toctree: + {% for attr in attributes %} + {{ attr }} + {% endfor %} +{% endif %} +{% endblock %} + +{% block functions %} +{% if functions %} + .. rubric:: Functions + + .. autosummary:: + :toctree: + {% for func in functions %} + {% if not func.startswith('_') %} + {{ func }} + {% endif %} + {%- endfor %} +{% endif %} +{% endblock %} + +{% block classes %} +{% if classes %} + .. rubric:: Classes + + .. autosummary:: + :toctree: + :template: custom-class-template.rst + {% for cl in classes %} + {{ cl }} + {%- endfor %} +{% endif %} +{% endblock %} + +{% block exceptions %} +{% if exceptions %} + .. rubric:: Exceptions + + .. autosummary:: + :toctree: + {% for item in exceptions %} + {{ item }} + {%- endfor %} +{% endif %} +{% endblock %} + +{% block modules %} +{% if modules %} +.. rubric:: Modules + +.. autosummary:: + :toctree: + :template: custom-module-template.rst + :recursive: +{% for mod in modules %} + {{ mod }} +{%- endfor %} +{% endif %} +{% endblock %} diff --git a/docs/scripts/install_appropriate_openvino_version.py b/docs/scripts/install_appropriate_openvino_version.py new file mode 100644 index 00000000000..d9cbb6a9ddb --- /dev/null +++ b/docs/scripts/install_appropriate_openvino_version.py @@ -0,0 +1,66 @@ +import re +import argparse +import subprocess +import requests +import pkg_resources +from packaging import version +from pathlib import Path + + +def determine_openvino_version(file_path): + pattern = r"version_name\s*=\s*['\"]([^'\"]+)['\"]" + + with open(file_path, 'r') as file: + content = file.read() + + match = re.search(pattern, content) + + if match: + return match.group(1) + else: + return None + + +def get_latest_version(major_version): + url = f"https://pypi.org/pypi/openvino/json" + response = requests.get(url) + + if response.status_code == 200: + data = response.json() + versions = data['releases'].keys() + + # Filter versions by the major version prefix + matching_versions = [v for v in versions if v.startswith(major_version)] + + # Sort the matching versions and return the latest one + if matching_versions: + matching_versions.sort(key=version.parse) + return matching_versions[-1] + + return None + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--ov_dir', type=Path, help='OpenVINO docs directory') + parser.add_argument('--python', type=Path, help='Python executable') + args = parser.parse_args() + ov_dir = args.ov_dir + python_executable = args.python + version_name = determine_openvino_version(ov_dir.joinpath("conf.py")) + + if version_name is None: + ov_version = "openvino" + elif version_name == "nightly": + ov_version = "openvino-nightly" + else: + latest_version = get_latest_version(version_name) + if latest_version: + ov_version = f"openvino=={latest_version}" + else: + ov_version = f"openvino=={version_name}" + subprocess.check_call([f'{python_executable}', '-m', 'pip', 'install', '-U', ov_version, '--no-cache-dir']) + + +if __name__ == "__main__": + main() \ No newline at end of file