-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first version based on moptipy using pycommons
- Loading branch information
1 parent
ef29906
commit 7aaeb92
Showing
69 changed files
with
273 additions
and
813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,15 @@ | ||
"""The configuration for sphinx to generate the documentation.""" | ||
import datetime | ||
import os | ||
import re | ||
import sys | ||
from typing import Final | ||
|
||
# the path of the documentation configuration | ||
doc_path = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
# get the path to the root directory of this project | ||
root_path = os.path.abspath(os.path.join(doc_path, "..", "..")) | ||
sys.path.insert(0, root_path) | ||
|
||
# set the base url | ||
html_baseurl = "https://thomasweise.github.io/moptipyapps/" | ||
|
||
# We want to include the contents of our GitHub README.md file. | ||
# So first, we need to load the README.md file. | ||
old_lines: list[str] | ||
with open(os.path.join(root_path, "README.md"), | ||
encoding="utf-8-sig") as reader: | ||
old_lines = reader.readlines() | ||
|
||
# Now, we need to fix the file contents. | ||
# We discard the top-level heading as well as the badge for the build status. | ||
# We need to move all sub-headings one step up. | ||
# Furthermore, we can turn all absolute URLs starting with | ||
# http://thomasweise.github.io/moptipyapps/xxx to local references, i.e., | ||
# ./xxx. Finally, it seems that the myst parser now again drops the numerical | ||
# prefixes of links, i.e., it tags `## 1.2. Hello` with id `hello` instead of | ||
# `12-hello`. This means that we need to fix all references following the | ||
# pattern `[xxx](#12-hello)` to `[xxx](#hello)`. We do this with a regular | ||
# expression `regex_search`. | ||
new_lines = [] | ||
in_code: bool = False # we only process non-code lines | ||
skip: bool = True | ||
# detects strings of the form [xyz](#123-bla) and gives \1=xyz and \2=bla | ||
regex_search = re.compile("(\\[.+?])\\(#\\d+-(.+?)\\)") | ||
license_link: str = \ | ||
"https://github.com/thomasWeise/moptipyapps/blob/main/LICENSE" | ||
needs_newline: bool = False | ||
can_add_anyway: bool = True | ||
for line in old_lines: | ||
if skip: # we skip everything until the introduction section | ||
if line.lstrip().startswith("## 1. Introduction"): | ||
skip = False | ||
new_lines.append(line[1:]) | ||
elif line.startswith("[![") and can_add_anyway: | ||
needs_newline = True | ||
new_lines.append(line) | ||
continue | ||
else: | ||
can_add_anyway = False | ||
continue | ||
if needs_newline: | ||
new_lines.append("") | ||
needs_newline = False | ||
continue | ||
if in_code: | ||
if line.startswith("```"): | ||
in_code = False # toggle to non-code | ||
else: | ||
if line.startswith("```"): | ||
in_code = True # toggle to code | ||
elif line.startswith("#"): | ||
line = line[1:] # move all sub-headings one step up | ||
else: # fix all internal urls | ||
# replace links of the form "#12-bla" to "#bla" | ||
line = re.sub(regex_search, "\\1(#\\2)", line) | ||
|
||
line = line.replace(license_link, "./LICENSE.html") | ||
for k in [html_baseurl, f"http{html_baseurl[5:]}"]: | ||
line = line.replace(f"]({k}", "](./")\ | ||
.replace(f' src="{k}', ' src="./')\ | ||
.replace(f' href="{k}', ' href="./') | ||
|
||
new_lines.append(line) | ||
|
||
# write the post-processed README.md file | ||
with open(os.path.join(doc_path, "README.md"), "w", | ||
encoding="utf-8") as outf: | ||
outf.writelines(new_lines) | ||
|
||
# enable myst header anchors | ||
myst_heading_anchors = 6 | ||
|
||
# project information | ||
project = "moptipyapps" | ||
author = "Thomas Weise" | ||
# noinspection PyShadowingBuiltins | ||
copyright = f"2023-{datetime.datetime.now ().year}, {author}" | ||
from pycommons.dev.doc.setup_doc import setup_doc | ||
from pycommons.io.path import Path, file_path | ||
|
||
# tell sphinx to go kaboom on errors | ||
nitpicky = True | ||
myst_all_links_external = True | ||
|
||
# The full version, including alpha/beta/rc tags. | ||
release = {} | ||
with open(os.path.abspath(os.path.sep.join([ | ||
root_path, "moptipyapps", "version.py"]))) as fp: | ||
exec(fp.read(), release) # nosec # nosemgrep # noqa: DUO105 | ||
release = release["__version__"] | ||
|
||
# The Sphinx extension modules that we use. | ||
extensions = ["myst_parser", # for processing README.md | ||
"sphinx.ext.autodoc", # to convert docstrings to documentation | ||
"sphinx.ext.doctest", # do the doc tests again | ||
"sphinx.ext.intersphinx", # to link to numpy et al. | ||
"sphinx_autodoc_typehints", # to infer types from hints | ||
"sphinx.ext.viewcode", # add rendered source code | ||
] | ||
|
||
# Location of dependency documentation for cross-referencing. | ||
intersphinx_mapping = { | ||
"matplotlib": ("https://matplotlib.org/stable/", None), | ||
"moptipy": ("https://thomasweise.github.io/moptipy/", None), | ||
"numpy": ("https://numpy.org/doc/stable/", None), | ||
"python": ("https://docs.python.org/3/", None), | ||
'scipy': ('https://docs.scipy.org/doc/scipy/', None), | ||
"urllib3": ("https://urllib3.readthedocs.io/en/stable/", None), | ||
} | ||
|
||
# inherit docstrings in autodoc | ||
autodoc_inherit_docstrings = True | ||
|
||
# add default values after comma | ||
typehints_defaults = "comma" | ||
|
||
# the sources to be processed | ||
source_suffix = [".rst", ".md"] | ||
|
||
# The theme to use for HTML and HTML Help pages. | ||
html_theme = "bizstyle" | ||
|
||
# Code syntax highlighting style: | ||
pygments_style = "default" | ||
# the path of the documentation configuration | ||
doc_path: Final[Path] = file_path(__file__).up(1) | ||
root_path: Final[Path] = doc_path.up(2) | ||
setup_doc(doc_path, root_path, 2023, dependencies=( | ||
"matplotlib", "moptipy", "numpy", "pycommons", "scipy", "sklearn", | ||
"urllib3"), | ||
full_urls={ | ||
"https://github.com/thomasWeise/moptipyapps/blob/main/LICENSE": | ||
"./LICENSE.html"}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.