Skip to content

Commit

Permalink
fix: typing hints
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 committed Oct 2, 2024
1 parent 20138c2 commit b1dc9d4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
45 changes: 23 additions & 22 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -342,27 +343,27 @@ 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.
Apply the hooks as functions before building the HTML files.
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
Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions doc/source/helpers.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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]

Expand Down Expand Up @@ -77,27 +78,27 @@ 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.
This is needed to be able to access the vars at the build stage.
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
Expand Down

0 comments on commit b1dc9d4

Please sign in to comment.