Skip to content

Commit

Permalink
Update to add github plus source files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Tehrani committed May 13, 2024
1 parent a3c749f commit ec350f0
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import importlib
import inspect
import os
import sys

Expand Down Expand Up @@ -37,7 +39,8 @@
"sphinx.ext.mathjax",
"nbsphinx",
"nbsphinx_link",
"IPython.sphinxext.ipython_console_highlighting"
"IPython.sphinxext.ipython_console_highlighting",
"sphinx.ext.linkcode",
]

# List of arguments to be passed to the kernel that executes the notebooks:
Expand Down Expand Up @@ -92,8 +95,7 @@
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {"collapse_navigation": False}

html_theme_options = {"collapse_navigation": False,}

# -- Configuration for autodoc extensions ---------------------------------

Expand Down Expand Up @@ -121,3 +123,44 @@ def autodoc_skip_member(app, what, name, obj, skip, options):
def setup(app):
"""Set up sphinx."""
app.connect("autodoc-skip-member", autodoc_skip_member)


# -- Link to Github ------------------------------
# Configure viewcode extension.
code_url = f"https://github.com/theochem/grid/blob/master/src/grid"


def linkcode_resolve(domain, info):
# Non-linkable objects from the starter kit in the tutorial.
if domain != 'py':
return None
if not info['module']:
return None

mod = importlib.import_module(info["module"])
if "." in info["fullname"]:
objname, attrname = info["fullname"].split(".")
obj = getattr(mod, objname)
try:
# object is a method of a class
obj = getattr(obj, attrname)
except AttributeError:
# object is an attribute of a class
return None
else:
obj = getattr(mod, info["fullname"])
try:
file = inspect.getsourcefile(obj)
lines = inspect.getsourcelines(obj)
except TypeError:
# e.g. object is a typing.Union
return None
file = os.path.relpath(file, os.path.abspath(".."))

# Get the file name e.g. /usr/conda/py37/grid/angular.py -> angular.py
split = file.split("grid/")
file = split[-1]

start, end = lines[1], lines[1] + len(lines[0]) - 1

return f"{code_url}/{file}#L{start}-L{end}"

0 comments on commit ec350f0

Please sign in to comment.