From b1dc9d446533dfba5032cf78020d902a3f1de1ac Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:27:17 +0200 Subject: [PATCH] fix: typing hints --- doc/source/conf.py | 45 ++++++++++++++++++++++--------------------- doc/source/helpers.py | 19 +++++++++--------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index c339e49ce..506e4534a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -9,7 +9,8 @@ from github import Github import pyvista import requests -import sphinx +from sphinx.addnodes import document as doctree +from sphinx.application import Sphinx as App from sphinx.builders.latex import LaTeXBuilder from ansys_sphinx_theme import ( @@ -27,7 +28,7 @@ EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples").resolve() # To allow using 'helper' python file as a module -sys.path.append(Path(__file__).parent) +sys.path.append(str(Path(__file__).parent)) # Project information project = "ansys_sphinx_theme" @@ -273,11 +274,11 @@ def download_and_process_files(example_links: List[str]) -> List[str]: def remove_edit_this_page_if_directive( - app: sphinx.app, + app: App, pagename: str, templatename: str, - context: sphinx.context, - doctree: sphinx.doctree, + context: dict, + doctree: doctree, page_vars: dict, ): """Remove 'edit this page' button. @@ -287,15 +288,15 @@ def remove_edit_this_page_if_directive( Parameters ---------- - app : sphinx.app + app : sphinx.application.Sphinx Sphinx app pagename : str Page name templatename : str Template name - context : sphinx.context + context : dict Page context - doctree : sphinx.doctree + doctree : sphinx.addnodes.document Page doctree page_vars : dict Page variables @@ -308,11 +309,11 @@ def remove_edit_this_page_if_directive( def remove_show_source_if_directive( - app: sphinx.app, + app: App, pagename: str, templatename: str, - context: sphinx.context, - doctree: sphinx.doctree, + context: dict, + doctree: doctree, page_vars: dict, ): """Remove the 'show_source' link. @@ -322,15 +323,15 @@ def remove_show_source_if_directive( Parameters ---------- - app : sphinx.app + app : sphinx.application.Sphinx Sphinx app pagename : str Page name templatename : str Template name - context : sphinx.context + context : dict Page context - doctree : sphinx.doctree + doctree : sphinx.addnodes.document Page doctree page_vars : dict Page variables @@ -342,11 +343,11 @@ def remove_show_source_if_directive( def pre_build_page_html( - app: sphinx.app, + app: App, pagename: str, templatename: str, - context: sphinx.context, - doctree: sphinx.doctree, + context: dict, + doctree: doctree, ): """Apply hooks before building HTML. @@ -354,15 +355,15 @@ def pre_build_page_html( Parameters ---------- - app : sphinx.app + app : sphinx.application.Sphinx Sphinx app pagename : str Page name templatename : str Template name - context : sphinx.context + context : dict Page context - doctree : sphinx.doctree + doctree : sphinx.addnodes.document Page doctree """ from helpers import get_page_vars @@ -375,12 +376,12 @@ def pre_build_page_html( remove_show_source_if_directive(app, pagename, templatename, context, doctree, page_vars) -def setup(app: sphinx): +def setup(app: App): """Add custom configuration to sphinx app. Parameters ---------- - app : sphinx.application.sphinx + app : sphinx.application.Sphinxlication.sphinx The Sphinx application. """ from helpers import SetPageVariableDirective, add_custom_variables_to_context diff --git a/doc/source/helpers.py b/doc/source/helpers.py index 7eb188304..fd04b0872 100644 --- a/doc/source/helpers.py +++ b/doc/source/helpers.py @@ -1,10 +1,11 @@ """Helper classes and functions for documentation build.""" from docutils.parsers.rst import Directive -import sphinx +from sphinx.addnodes import document as doctree +from sphinx.application import Sphinx as App -def get_page_vars(app: sphinx.app, pagename: str) -> dict: +def get_page_vars(app: App, pagename: str) -> dict: """Get page variables. Get each page variables. @@ -28,7 +29,7 @@ def get_page_vars(app: sphinx.app, pagename: str) -> dict: or not env.pages_vars or not env.pages_vars.get(pagename, None) ): - return + return {} return env.pages_vars[pagename] @@ -77,11 +78,11 @@ def run(self): def add_custom_variables_to_context( - app: sphinx.app, + app: App, pagename: str, templatename: str, - context: sphinx.context, - doctree: sphinx.doctree, + context: dict, + doctree: doctree, ) -> None: """Add customs variables to build context. @@ -89,15 +90,15 @@ def add_custom_variables_to_context( Parameters ---------- - app : Sphinx.app + app : sphinx.application.Sphinx Sphinx app. pagename : str Page name templatename : str Template page - context : Sphinx.context + context : dict Page context - doctree : Sphinx.doctree + doctree : sphinx.addnodes.document Page doctree """ env = app.builder.env