Skip to content

Commit

Permalink
Add Mypy to qiskit_sphinx_theme (#359)
Browse files Browse the repository at this point in the history
This add an integration of Mypy in the repository and following the
format of this.
  • Loading branch information
MaldoAlberto committed Jun 8, 2023
1 parent 6b589a5 commit 1a1c134
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ target-version = ["py37", "py38", "py39", "py310", "py311"]

[tool.isort]
profile = "black"

[tool.mypy]
disallow_untyped_defs = true
show_error_codes = true
no_implicit_optional = true
warn_return_any = true
warn_unused_ignores = true
exclude = ["example_docs", "docs_guide", "tests"]
check_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"furo",
"jupyter_sphinx.thebelab"
]
ignore_missing_imports = true
19 changes: 17 additions & 2 deletions qiskit_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@

"""Pytorch Sphinx theme."""

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

import sphinx.addnodes

from qiskit_sphinx_theme import directives, previous_releases, translations

if TYPE_CHECKING:
import sphinx.addnodes
import sphinx.application

__version__ = "1.12.0rc1"
__version_full__ = __version__

Expand All @@ -25,7 +34,13 @@ def _get_theme_absolute_path(folder_name: str) -> str:
return str(path.resolve())


def remove_thebe_if_not_needed(app, pagename, templatename, context, doctree):
def remove_thebe_if_not_needed(
app: sphinx.application.Sphinx,
pagename: str,
templatename: str,
context: dict,
doctree: sphinx.addnodes.document,
) -> None:
"""
Remove files that jupyter-sphinx incorrectly tries to add.
Expand Down Expand Up @@ -56,7 +71,7 @@ def remove_thebe_if_not_needed(app, pagename, templatename, context, doctree):


# See https://www.sphinx-doc.org/en/master/development/theming.html
def setup(app):
def setup(app: sphinx.application.Sphinx) -> dict[str, bool]:
# Used to generate URL references. Expected to be e.g. `ecosystem/finance`.
app.add_config_value("docs_url_prefix", default=None, rebuild="html", types=[str])

Expand Down
4 changes: 2 additions & 2 deletions qiskit_sphinx_theme/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CardItemDirective(Directive):
"tags": directives.unchanged,
}

def run(self):
def run(self) -> list[nodes.paragraph]:
header = self.options.get("header")
if header is None:
raise ValueError(f"`header` not set in {self.NAME} directive")
Expand Down Expand Up @@ -81,7 +81,7 @@ class CallToActionItemDirective(Directive):
"button_text": directives.unchanged,
}

def run(self):
def run(self) -> list[nodes.paragraph]:
description = self.options.get("description", "")
header = self.options.get("header")
if header is None:
Expand Down
5 changes: 4 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ pytest==7.*

# Dev tooling
black~=23.3
isort~=5.11
isort~=5.11
mypy~=1.3.0

types-docutils
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ deps =
commands =
black --check docs_guide/ example_docs/ qiskit_sphinx_theme/ tests/ setup.py
isort --check docs_guide/ example_docs/ qiskit_sphinx_theme/ tests/ setup.py
mypy qiskit_sphinx_theme/

0 comments on commit 1a1c134

Please sign in to comment.