Skip to content

Commit

Permalink
Use pathlib for relativizing file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Apr 4, 2024
1 parent abf4871 commit 3386c4c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import importlib
import inspect
import os
import re
from pathlib import Path


project = "Qiskit"
Expand Down Expand Up @@ -166,14 +166,17 @@
# Source code links
# ----------------------------------------------------------------------------------

REPO_ROOT = Path(__file__).resolve().parents[1]


def linkcode_resolve(domain, info):
if domain != "py":
return None

module_name = info["module"]
if "qiskit" not in module_name:
return None

try:
module = importlib.import_module(module_name)
except ModuleNotFoundError:
Expand All @@ -192,7 +195,10 @@ def linkcode_resolve(domain, info):
return None
if full_file_name is None:
return None
file_name = full_file_name.split("/qiskit/")[-1]
try:
file_name = Path(full_file_name).resolve().relative_to(REPO_ROOT / "qiskit")
except ValueError:
return None

try:
source, lineno = inspect.getsourcelines(obj)
Expand Down

0 comments on commit 3386c4c

Please sign in to comment.