Skip to content

Commit

Permalink
update conf file again
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-kron-wis committed Dec 12, 2024
1 parent f9f1e41 commit a27e748
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
from datetime import datetime
from importlib.metadata import metadata
from pathlib import Path
import importlib.util
import inspect
import os
import re
import subprocess
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any

HERE = Path(__file__).parent
sys.path.insert(0, str(HERE / "extensions"))
Expand Down Expand Up @@ -130,3 +139,79 @@
# you can add an exception to this list.
# ("py:class", "igraph.Graph"),
]



# -- Config for linkcode -------------------------------------------


def git(*args):
"""Run git command and return output as string."""
return subprocess.check_output(["git", *args]).strip().decode()


# https://github.com/DisnakeDev/disnake/blob/7853da70b13fcd2978c39c0b7efa59b34d298186/docs/conf.py#L192
# Current git reference. Uses branch/tag name if found, otherwise uses commit hash
git_ref = None
try:
git_ref = git("name-rev", "--name-only", "--no-undefined", "HEAD")
git_ref = re.sub(r"^(remotes/[^/]+|tags)/", "", git_ref)
except Exception:
pass

# (if no name found or relative ref, use commit hash instead)
if not git_ref or re.search(r"[\^~]", git_ref):
try:
git_ref = git("rev-parse", "HEAD")
except Exception:
git_ref = "main"

# https://github.com/DisnakeDev/disnake/blob/7853da70b13fcd2978c39c0b7efa59b34d298186/docs/conf.py#L192
_scvi_tools_module_path = os.path.dirname(importlib.util.find_spec("scvi").origin) # type: ignore


def linkcode_resolve(domain, info):
"""Determine the URL corresponding to Python object."""
if domain != "py":
return None

try:
obj: Any = sys.modules[info["module"]]
for part in info["fullname"].split("."):
obj = getattr(obj, part)
obj = inspect.unwrap(obj)

if isinstance(obj, property):
obj = inspect.unwrap(obj.fget) # type: ignore

path = os.path.relpath(inspect.getsourcefile(obj), start=_scvi_tools_module_path) # type: ignore
src, lineno = inspect.getsourcelines(obj)
except Exception:
return None

path = f"{path}#L{lineno}-L{lineno + len(src) - 1}"
return f"{repository_url}/blob/{git_ref}/src/scvi/{path}"


# -- Config for hoverxref -------------------------------------------

hoverx_default_type = "tooltip"
hoverxref_domains = ["py"]
hoverxref_role_types = dict.fromkeys(
["ref", "class", "func", "meth", "attr", "exc", "data", "mod"],
"tooltip",
)
hoverxref_intersphinx = [
"python",
"numpy",
"scanpy",
"anndata",
"pytorch_lightning",
"scipy",
"pandas",
"ml_collections",
"ray",
]
# use proxied API endpoint on rtd to avoid CORS issues
if os.environ.get("READTHEDOCS"):
hoverxref_api_host = "/_"

0 comments on commit a27e748

Please sign in to comment.