Skip to content

Commit

Permalink
chore(docs): from viewcode to linkcode
Browse files Browse the repository at this point in the history
Link to code definition on GitHub

push
  • Loading branch information
jeertmans committed Dec 18, 2024
1 parent 24233da commit 8b60a67
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
6 changes: 3 additions & 3 deletions differt/src/differt/em/_special.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ def fresnel(
"""
# Constant factors
sqrtpi_2_4 = 0.31332853432887503 # 0.25 * jnp.sqrt(0.5 * jnp.pi)
_sqrt2 = 0.7071067811865476 # jnp.sqrt(0.5)
sqrt2 = 0.7071067811865476 # jnp.sqrt(0.5)

# Erf function evaluations
ep = erf((1 + 1j) * _sqrt2 * z)
em = erf((1 - 1j) * _sqrt2 * z)
ep = erf((1 + 1j) * sqrt2 * z)
em = erf((1 - 1j) * sqrt2 * z)

s = sqrtpi_2_4 * (1 + 1j) * (ep - 1j * em)
c = sqrtpi_2_4 * (1 - 1j) * (ep + 1j * em)
Expand Down
45 changes: 43 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import inspect
import operator
import os
import sys
from datetime import date
from pathlib import Path
from typing import Any

from docutils import nodes
Expand All @@ -25,6 +28,9 @@
copyright = f"2023-{date.today().year}, Jérome Eertmans" # noqa: A001, DTZ011
author = "Jérome Eertmans"
version = __version__
git_ref = os.environ.get("READTHEDOCS_GIT_IDENTIFIER", "main")
conf_dir = Path(__file__).absolute().parent
root_dir = conf_dir.parent.parent

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand All @@ -35,9 +41,9 @@
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.githubpages",
"sphinx.ext.linkcode",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
# Additional
"matplotlib.sphinxext.plot_directive",
"myst_nb",
Expand Down Expand Up @@ -160,16 +166,51 @@
plotly_html_show_source_link = False
plotly_html_show_formats = False

# -- Linkcode settings


def linkcode_resolve(domain: str, info: dict[str, Any]) -> str | None: # noqa: PLR0911
if domain != "py":
return None

if not info["module"]:
return None
if not info["fullname"]:
return None
if info["module"].split(".", 1)[0] not in {"differt", "differt_core"}:
return None

try:
mod = sys.modules.get(info["module"])
obj = operator.attrgetter(info["fullname"])(mod)
if isinstance(obj, property):
obj: Any = obj.fget
obj = inspect.unwrap(obj)
filename = inspect.getsourcefile(obj)
source, lineno = inspect.getsourcelines(obj)
except (AttributeError, TypeError):
return None

if filename is None:
return None

filename = os.path.relpath(filename, start=root_dir)
lines = f"#L{lineno}-L{lineno + len(source) - 1}" if lineno else ""

return f"https://github.com/jeertmans/DiffeRT/blob/{git_ref}/{filename}{lines}"


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output


html_theme = "sphinx_book_theme"
html_static_path = ["_static"]

html_theme_options = {
"show_toc_level": 2,
"repository_url": "https://github.com/jeertmans/DiffeRT",
"repository_branch": "main",
"repository_branch": git_ref,
"path_to_docs": "docs/source",
"use_edit_page_button": True,
"use_source_button": True,
Expand Down

0 comments on commit 8b60a67

Please sign in to comment.