Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ dmypy.json
# These get copied from sphinx-theme-builder.
/src/qiskit_sphinx_theme/theme/qiskit-sphinx-theme/static/styles
/src/qiskit_sphinx_theme/theme/qiskit-sphinx-theme/static/scripts

.idea
1 change: 1 addition & 0 deletions docs_guide/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html


import datetime

project = "Qiskit Docs Guide"
Expand Down
45 changes: 42 additions & 3 deletions example_docs/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

import inspect
import os
import sys
from pathlib import PurePath

# This allows autodoc to find the `api_example` folder.
sys.path.insert(0, os.path.abspath(".."))

project = "Example Docs"
project = "Sphinx-ext-linkcode Testing"
project_copyright = "2020, Qiskit Development Team"
author = "Qiskit Development Team"
language = "en"
release = "9.99"
release = "1.3.2"

html_theme = "qiskit-ecosystem"

Expand All @@ -43,7 +45,7 @@
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.linkcode",
"jupyter_sphinx",
"sphinx_copybutton",
"sphinx_design",
Expand Down Expand Up @@ -100,3 +102,40 @@
# Default image for thumbnails.
"**": "_static/images/logo.png",
}


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

module = sys.modules.get(info["module"])
if module is None:
return None

obj = module
for part in info["fullname"].split("."):
obj = getattr(obj, part)
is_valid_code_object = (
inspect.isclass(obj) or inspect.ismethod(obj) or inspect.isfunction(obj)
)
if not is_valid_code_object:
return None

full_file_name = inspect.getsourcefile(obj)
if full_file_name is None:
return None
repo_root = PurePath(__file__).parent.parent.parent
file_name = PurePath(full_file_name).relative_to(repo_root)

try:
source, lineno = inspect.getsourcelines(obj)
except OSError:
linespec = ""
else:
ending_lineno = lineno + len(source) - 1
linespec = f"#L{lineno}-L{ending_lineno}"

return f"https://github.com/Qiskit/qiskit_sphinx_theme/tree/main/{file_name}/{linespec}"