2023-01-06 18:02:17 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-02-25 16:03:11 +00:00
|
|
|
import io
|
|
|
|
import os
|
2021-09-16 09:39:26 +00:00
|
|
|
import sys
|
2021-11-23 08:25:09 +00:00
|
|
|
from typing import Any, Dict, List
|
2018-12-03 18:59:09 +00:00
|
|
|
|
2020-02-25 16:03:11 +00:00
|
|
|
import docutils
|
|
|
|
import docutils.parsers.rst
|
2018-12-03 18:59:09 +00:00
|
|
|
|
|
|
|
# -- Project information -----------------------------------------------------
|
|
|
|
|
2020-02-25 16:03:11 +00:00
|
|
|
project = "Tutor"
|
2023-01-06 18:02:17 +00:00
|
|
|
copyright = "" # pylint: disable=redefined-builtin
|
|
|
|
author = "Overhang.IO"
|
2018-12-03 18:59:09 +00:00
|
|
|
|
|
|
|
# The short X.Y version
|
2020-02-25 16:03:11 +00:00
|
|
|
version = ""
|
2018-12-03 18:59:09 +00:00
|
|
|
# The full version, including alpha/beta/rc tags
|
2020-02-25 16:03:11 +00:00
|
|
|
release = ""
|
2018-12-03 18:59:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
# -- General configuration ---------------------------------------------------
|
2020-02-25 16:03:11 +00:00
|
|
|
extensions = []
|
|
|
|
templates_path = ["_templates"]
|
|
|
|
source_suffix = ".rst"
|
|
|
|
master_doc = "index"
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
language = "en"
|
2020-02-25 16:03:11 +00:00
|
|
|
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
2018-12-03 18:59:09 +00:00
|
|
|
pygments_style = None
|
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
# Autodocumentation of modules
|
|
|
|
extensions.append("sphinx.ext.autodoc")
|
|
|
|
autodoc_typehints = "description"
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
# For the life of me I can't get the docs to compile in nitpicky mode without these
|
|
|
|
# ignore statements. You are most welcome to try and remove them.
|
2023-01-06 18:02:17 +00:00
|
|
|
# To make matters worse, some ignores are only required for some versions of Python,
|
2023-04-28 08:13:46 +00:00
|
|
|
# from 3.8 to 3.10...
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
nitpick_ignore = [
|
2023-01-06 18:02:17 +00:00
|
|
|
# Sphinx does not handle ParamSpec arguments
|
|
|
|
("py:class", "T.args"),
|
|
|
|
("py:class", "T.kwargs"),
|
|
|
|
("py:class", "T2.args"),
|
|
|
|
("py:class", "T2.kwargs"),
|
|
|
|
# Sphinx doesn't know about the following classes
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
("py:class", "click.Command"),
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
("py:class", "t.Any"),
|
2023-01-06 18:02:17 +00:00
|
|
|
("py:class", "t.Callable"),
|
|
|
|
("py:class", "t.Iterator"),
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
("py:class", "t.Optional"),
|
2023-01-06 18:02:17 +00:00
|
|
|
# python 3.10
|
|
|
|
("py:class", "NoneType"),
|
|
|
|
("py:class", "click.core.Command"),
|
feat: strongly typed hooks
Now that the mypy bugs have been resolved, we are able to define more precisely
and cleanly the types of Actions and Filters.
Moreover, can now strongly type named actions and hooks (in consts.py). With
such a strong typing, we get early alerts of hooks called with incorrect
arguments, which is nothing short of awesome :)
This change breaks the hooks API by removing the `context=...` argument. The
reason for that is that we cannot insert arbitrary arguments between `P.args,
P.kwargs`: https://peps.python.org/pep-0612/#the-components-of-a-paramspec
> A function declared as def inner(a: A, b: B, *args: P.args, **kwargs:
> P.kwargs) -> R has type Callable[Concatenate[A, B, P], R]. Placing
> keyword-only parameters between the *args and **kwargs is forbidden.
Getting the documentation to build in nitpicky mode is quite difficult... We
need to add `nitpick_ignore` to the docs conf.py, otherwise sphinx complains
about many missing class references. This, despite upgrading almost all doc
requirements (except docutils).
2022-10-06 10:05:01 +00:00
|
|
|
]
|
2023-01-06 18:02:17 +00:00
|
|
|
# Resolve type aliases here
|
|
|
|
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_type_aliases
|
|
|
|
autodoc_type_aliases: dict[str, str] = {
|
|
|
|
# python 3.10
|
|
|
|
"T": "tutor.core.hooks.actions.T",
|
|
|
|
"T2": "tutor.core.hooks.filters.T2",
|
|
|
|
}
|
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
|
2021-09-16 09:39:26 +00:00
|
|
|
# -- Sphinx-Click configuration
|
|
|
|
# https://sphinx-click.readthedocs.io/
|
2021-11-23 08:25:09 +00:00
|
|
|
extensions.append("sphinx_click")
|
2021-09-16 09:39:26 +00:00
|
|
|
# This is to avoid the addition of the local username to the docs
|
|
|
|
os.environ["HOME"] = "~"
|
|
|
|
# Make sure that sphinx-click can find the tutor module
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
2018-12-03 18:59:09 +00:00
|
|
|
|
|
|
|
# -- Options for HTML output -------------------------------------------------
|
2020-02-25 16:03:11 +00:00
|
|
|
html_theme = "sphinx_rtd_theme"
|
2019-10-17 15:20:22 +00:00
|
|
|
html_theme_options = {
|
2020-02-25 16:03:11 +00:00
|
|
|
"logo_only": True,
|
2019-10-17 15:20:22 +00:00
|
|
|
"style_nav_header_background": "#EFEFEF",
|
|
|
|
}
|
|
|
|
html_context = {
|
2020-02-25 16:03:11 +00:00
|
|
|
"display_github": True,
|
|
|
|
"github_user": "overhangio",
|
|
|
|
"github_repo": "tutor",
|
|
|
|
"github_version": "master",
|
|
|
|
"conf_py_path": "/docs/",
|
2019-10-17 15:20:22 +00:00
|
|
|
}
|
2020-02-25 16:03:11 +00:00
|
|
|
html_static_path = ["img"]
|
2018-12-03 18:59:09 +00:00
|
|
|
|
2019-10-17 15:20:22 +00:00
|
|
|
# Custom settings
|
2023-12-14 14:29:30 +00:00
|
|
|
html_logo = "https://overhang.io/static/img/tutor-logo.svg"
|
2019-10-25 08:53:59 +00:00
|
|
|
html_favicon = "./img/favicon.png"
|
2019-10-17 15:20:22 +00:00
|
|
|
html_show_sourcelink = False
|
|
|
|
html_display_github = True
|
|
|
|
html_show_sphinx = False
|
|
|
|
html_github_user = "overhangio"
|
|
|
|
html_github_repo = "tutor"
|
|
|
|
# Images do not link to themselves
|
|
|
|
html_scaled_image_link = False
|
|
|
|
html_show_copyright = False
|
2018-12-03 18:59:09 +00:00
|
|
|
|
2019-04-22 11:29:53 +00:00
|
|
|
# Custom variables
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
2021-11-23 08:25:09 +00:00
|
|
|
about: Dict[str, str] = {}
|
2020-02-25 16:02:39 +00:00
|
|
|
with io.open(
|
|
|
|
os.path.join(here, "..", "tutor", "__about__.py"), "rt", encoding="utf-8"
|
|
|
|
) as f:
|
2023-01-06 18:02:17 +00:00
|
|
|
# pylint: disable=exec-used
|
2019-04-22 11:29:53 +00:00
|
|
|
exec(f.read(), about)
|
2023-01-06 18:02:17 +00:00
|
|
|
rst_prolog = f"""
|
|
|
|
.. |tutor_version| replace:: {about["__version__"]}
|
|
|
|
"""
|
2020-02-25 16:02:39 +00:00
|
|
|
|
2023-02-09 10:57:26 +00:00
|
|
|
|
2020-02-25 16:02:39 +00:00
|
|
|
# Custom directives
|
|
|
|
def youtube(
|
2021-11-23 08:25:09 +00:00
|
|
|
_name: Any,
|
|
|
|
_args: Any,
|
|
|
|
_options: Any,
|
|
|
|
content: List[str],
|
|
|
|
_lineno: Any,
|
|
|
|
_contentOffset: Any,
|
|
|
|
_blockText: Any,
|
|
|
|
_state: Any,
|
|
|
|
_stateMachine: Any,
|
|
|
|
) -> Any:
|
|
|
|
"""Restructured text extension for inserting youtube embedded videos"""
|
2020-02-25 16:02:39 +00:00
|
|
|
if not content:
|
|
|
|
return []
|
|
|
|
video_id = content[0]
|
|
|
|
return [
|
|
|
|
docutils.nodes.raw(
|
|
|
|
"",
|
2023-04-28 08:13:46 +00:00
|
|
|
f"""
|
2020-02-25 16:02:39 +00:00
|
|
|
<iframe width="560" height="315"
|
|
|
|
src="https://www.youtube-nocookie.com/embed/{video_id}"
|
|
|
|
frameborder="0"
|
|
|
|
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
|
2023-04-28 08:13:46 +00:00
|
|
|
</iframe>""",
|
2020-02-25 16:02:39 +00:00
|
|
|
format="html",
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-02-07 17:11:43 +00:00
|
|
|
# Tutor's own extension
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), "_ext"))
|
|
|
|
extensions.append("tutordocs")
|
|
|
|
|
|
|
|
|
|
|
|
setattr(youtube, "content", True)
|
|
|
|
docutils.parsers.rst.directives.register_directive("youtube", youtube) # type: ignore
|