-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
155 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
bezier | ||
ipython | ||
ipywidgets | ||
jinja2>=3.0.3 | ||
leidenalg | ||
memory_profiler>=0.58.0 | ||
# 0.8.7 is really slow | ||
|
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Based on: gist.github.com/MantasVaitkunas/7c16de233812adcb7028""" | ||
|
||
import os | ||
import warnings | ||
|
||
__licence__ = "BSD (3 clause)" | ||
|
||
from typing import Any, Dict, Tuple, Optional | ||
|
||
from sphinx.addnodes import document | ||
from sphinx.application import Sphinx | ||
|
||
|
||
def get_github_repo(app: Sphinx, path: str) -> Tuple[str, str]: | ||
if path.endswith(".ipynb"): | ||
return app.config.github_nb_repo, "/tutorials/" | ||
if path.endswith(".rst") and "auto_examples" in path and "index.rst" not in path: | ||
# TODO(michalk8): ugly trick to point .rst files in `auto_examples` to `.py` | ||
path = ( | ||
path.replace("auto_examples", "examples").replace(".rst", ".py") + "#FIXME/" | ||
) | ||
if not path.startswith("/"): | ||
path = "/" + path | ||
return app.config.github_repo, path | ||
return app.config.github_repo, "/docs/source/" | ||
|
||
|
||
def html_page_context( | ||
app: Sphinx, | ||
pagename: str, | ||
templatename: str, | ||
context: Dict[str, Any], | ||
doctree: Optional[document], | ||
) -> Optional[str]: | ||
if doctree is None: | ||
return | ||
if templatename != "page.html": | ||
return | ||
if not app.config.github_repo: | ||
warnings.warn("`github_repo `not specified") | ||
return | ||
|
||
if not app.config.github_nb_repo: | ||
nb_repo = f"{app.config.github_repo}_notebooks" | ||
app.config.github_nb_repo = nb_repo | ||
|
||
path = os.path.relpath(doctree.get("source"), app.builder.srcdir) | ||
repo, conf_py_path = get_github_repo(app, path) | ||
|
||
# For sphinx_rtd_theme. | ||
context["display_github"] = True | ||
context["github_user"] = "theislab" | ||
# TODO(michalk): master/dev | ||
context["github_version"] = "master" | ||
context["github_repo"] = repo | ||
context["conf_py_path"] = conf_py_path | ||
|
||
|
||
def setup(app: Sphinx) -> None: | ||
app.add_config_value("github_nb_repo", "", True) | ||
app.add_config_value("github_repo", "", True) | ||
app.connect("html-page-context", html_page_context) |
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,4 +1,4 @@ | ||
:github_url: {{ fullname }} | ||
:github_url: {{ fullname | modurl }} | ||
|
||
{% extends "!autosummary/base.rst" %} | ||
|
||
|
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,11 +1,11 @@ | ||
:github_url: {{ fullname }} | ||
:github_url: {{ fullname | modurl }} | ||
|
||
{{ fullname | escape | underline}} | ||
|
||
.. autofunction:: {{ fullname }} | ||
|
||
.. _sphx_glr_backref_{{fullname}}: | ||
|
||
.. minigallery:: {{fullname}} | ||
.. minigallery:: {{ fullname }} | ||
:add-heading: Examples | ||
:heading-level: - |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Based on: https://github.com/theislab/scvelo/blob/fb65bab8eb469e2b7f2793d9aca0cb9062d7e58a/docs/source/conf.py""" | ||
from typing import Any, Tuple, Optional | ||
|
||
import sys | ||
from inspect import getsourcelines | ||
from pathlib import Path, PurePosixPath | ||
|
||
|
||
def get_obj_module(qualname: str) -> Tuple[Any, Any]: | ||
"""Get a module/class/attribute and its original module by qualname""" | ||
modname = qualname | ||
classname, attrname = None, None | ||
while modname not in sys.modules: | ||
attrname = classname | ||
modname, classname = modname.rsplit(".", 1) | ||
|
||
# retrieve object and find original module name | ||
if classname: | ||
cls = getattr(sys.modules[modname], classname) | ||
modname = cls.__module__ | ||
obj = getattr(cls, attrname) if attrname else cls | ||
else: | ||
obj = None | ||
|
||
return obj, sys.modules[modname] | ||
|
||
|
||
def get_linenos(obj: Any) -> Tuple[Optional[int], Optional[int]]: | ||
"""Get an object’s line numbers""" | ||
try: | ||
lines, start = getsourcelines(obj) | ||
except TypeError: | ||
return None, None | ||
else: | ||
return start, start + len(lines) - 1 | ||
|
||
|
||
def modurl(qualname: str) -> str: | ||
"""Get the full GitHub URL for some object’s qualname.""" | ||
project_dir = Path(__file__).parent.parent.parent | ||
obj, module = get_obj_module(qualname) | ||
github_url = "https://github.com/theislab/cellrank/tree/master" | ||
|
||
try: | ||
path = PurePosixPath(Path(module.__file__).resolve().relative_to(project_dir)) | ||
except ValueError: | ||
return github_url | ||
|
||
start, end = get_linenos(obj) | ||
fragment = f"#L{start}-L{end}" if start and end else "" | ||
|
||
return f"{github_url}/{path}{fragment}" |