зеркало из https://github.com/microsoft/LightGBM.git
[python] add type hints in docs/conf.py (#4526)
* [python] add type hints in docs/conf.py * more specific hint for sphinx app * Apply suggestions from code review Co-authored-by: Nikita Titov <nekit94-08@mail.ru> Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
This commit is contained in:
Родитель
dbccc1e73f
Коммит
67f2cb3162
18
docs/conf.py
18
docs/conf.py
|
@ -24,12 +24,14 @@ from pathlib import Path
|
|||
from re import compile
|
||||
from shutil import copytree
|
||||
from subprocess import PIPE, Popen
|
||||
from typing import Any, List
|
||||
from unittest.mock import Mock
|
||||
|
||||
import sphinx
|
||||
from docutils.nodes import reference
|
||||
from docutils.parsers.rst import Directive
|
||||
from docutils.transforms import Transform
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.errors import VersionRequirementError
|
||||
|
||||
CURR_PATH = Path(__file__).absolute().parent
|
||||
|
@ -51,7 +53,7 @@ class InternalRefTransform(Transform):
|
|||
default_priority = 210
|
||||
"""Numerical priority of this transform, 0 through 999."""
|
||||
|
||||
def apply(self, **kwargs):
|
||||
def apply(self, **kwargs: Any) -> None:
|
||||
"""Apply the transform to the document tree."""
|
||||
for section in self.document.traverse(reference):
|
||||
if section.get("refuri") is not None:
|
||||
|
@ -63,7 +65,7 @@ class IgnoredDirective(Directive):
|
|||
|
||||
has_content = True
|
||||
|
||||
def run(self):
|
||||
def run(self) -> List:
|
||||
"""Do nothing."""
|
||||
return []
|
||||
|
||||
|
@ -197,12 +199,12 @@ htmlhelp_basename = 'LightGBMdoc'
|
|||
latex_logo = str(CURR_PATH / 'logo' / 'LightGBM_logo_black_text_small.png')
|
||||
|
||||
|
||||
def generate_doxygen_xml(app):
|
||||
def generate_doxygen_xml(app: Sphinx) -> None:
|
||||
"""Generate XML documentation for C API by Doxygen.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
app : object
|
||||
app : sphinx.application.Sphinx
|
||||
The application object representing the Sphinx process.
|
||||
"""
|
||||
doxygen_args = [
|
||||
|
@ -242,12 +244,12 @@ def generate_doxygen_xml(app):
|
|||
raise Exception(f"An error has occurred while executing Doxygen\n{e}")
|
||||
|
||||
|
||||
def generate_r_docs(app):
|
||||
def generate_r_docs(app: Sphinx) -> None:
|
||||
"""Generate documentation for R-package.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
app : object
|
||||
app : sphinx.application.Sphinx
|
||||
The application object representing the Sphinx process.
|
||||
"""
|
||||
commands = f"""
|
||||
|
@ -304,12 +306,12 @@ def generate_r_docs(app):
|
|||
raise Exception(f"An error has occurred while generating documentation for R-package\n{e}")
|
||||
|
||||
|
||||
def setup(app):
|
||||
def setup(app: Sphinx) -> None:
|
||||
"""Add new elements at Sphinx initialization time.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
app : object
|
||||
app : sphinx.application.Sphinx
|
||||
The application object representing the Sphinx process.
|
||||
"""
|
||||
first_run = not (CURR_PATH / '_FIRST_RUN.flag').exists()
|
||||
|
|
Загрузка…
Ссылка в новой задаче