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"
|
2019-10-17 15:20:22 +00:00
|
|
|
copyright = ""
|
2020-02-25 16:03:11 +00:00
|
|
|
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.
|
|
|
|
nitpick_ignore = [
|
|
|
|
("py:class", "Config"),
|
|
|
|
("py:class", "click.Command"),
|
|
|
|
("py:class", "tutor.hooks.filters.P"),
|
|
|
|
("py:class", "tutor.hooks.filters.T"),
|
|
|
|
("py:class", "tutor.hooks.actions.P"),
|
|
|
|
]
|
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
|
|
|
|
html_logo = "./img/tutor-logo.png"
|
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:
|
2019-04-22 11:29:53 +00:00
|
|
|
exec(f.read(), about)
|
|
|
|
rst_prolog = """
|
|
|
|
.. |tutor_version| replace:: {}
|
|
|
|
""".format(
|
2020-02-25 16:02:39 +00:00
|
|
|
about["__version__"],
|
2019-04-22 11:29:53 +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(
|
|
|
|
"",
|
|
|
|
"""
|
|
|
|
<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>
|
|
|
|
</iframe>""".format(
|
|
|
|
video_id=video_id
|
|
|
|
),
|
|
|
|
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
|